Paypal IPN不断从Sandbox返回无效

时间:2016-06-20 08:01:02

标签: php paypal paypal-ipn

我知道这个问题已被问到很多,但我已经找到了我能找到的所有答案,但没有人帮助过;许多人已经岁了,所以我不确定这是否是问题的一部分。

我通过Sandbox发送IPN来测试PayPal IPN监听器。它声明已发送IPN并验证了握手,但返回给侦听器的状态始终无效。我尝试了几个不同的例子,但都没有用。我已经剥离了我的代码,只需记录输入文本,输出文本,来自paypal的验证状态以及http状态代码:

<?php

define("LOG_FILE", "./ipn.log");
define("DEBUG", 0);
define("USE_SANDBOX", 1); //for testing

//get raw input
$stream_input = file_get_contents('php://input');
error_log(date('[Y-m-d H:i e] '). $stream_input. PHP_EOL, 3, LOG_FILE); //log result for comparison to return string

//choose correct URL
if(USE_SANDBOX == 1) {
    $paypal_url = "https://www.sandbox.paypal.com/cgi-bin/webscr";
} else {
    $paypal_url = "https://www.paypal.com/cgi-bin/webscr";
}

// add cmd for return request
$return_string = 'cmd=_notify-validate&' . $stream_input;
error_log(date('[Y-m-d H:i e] '). $return_string. PHP_EOL, 3, LOG_FILE); //log result for comparison

//cURL setup
$ch = curl_init($paypal_url);
if ($ch == FALSE) {
    return FALSE;
}
curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $return_string);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($ch, CURLOPT_FORBID_REUSE, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Connection: Close'));
$verification_status = curl_exec($ch);
$http_status   = curl_getinfo($ch, CURLINFO_HTTP_CODE);

//log result
error_log(date('[Y-m-d H:i e] '). $verification_status . PHP_EOL, 3, LOG_FILE);
error_log(date('[Y-m-d H:i e] '). $http_status . PHP_EOL, 3, LOG_FILE);

//log cURL errors
if (curl_errno($ch) != 0) // cURL error
    {
    if(DEBUG == true) { 
        error_log(date('[Y-m-d H:i e] '). "Can't connect to PayPal to validate IPN message: " . curl_error($ch) . PHP_EOL, 3, LOG_FILE);
    }
    curl_close($ch);
    exit;
} else {
        // Log the entire HTTP response if debug is switched on.
        if(DEBUG == true) {
            error_log(date('[Y-m-d H:i e] '). "HTTP request of validation request:". curl_getinfo($ch, CURLINFO_HEADER_OUT) ." for IPN payload: $return_array" . PHP_EOL, 3, LOG_FILE);
            error_log(date('[Y-m-d H:i e] '). "HTTP response of validation request: $verification_status" . PHP_EOL, 3, LOG_FILE);
        }
        curl_close($ch);
}
?>

这是我在日志中得到的输出:

[2016-06-20 03:52 America/New_York] payment_type=instant&payment_date=Mon%20Jun%2020%202016%2017%3A50%3A12%20GMT+1000%20%28AUS%20Eastern%20Standard%20Time%29&payment_status=Canceled_Reversal&address_status=confirmed&payer_status=verified&first_name=John&last_name=Smith&payer_email=buyer@paypalsandbox.com&payer_id=TESTBUYERID01&address_name=John%20Smith&address_country=United%20States&address_country_code=US&address_zip=95131&address_state=CA&address_city=San%20Jose&address_street=123%20any%20street&business=seller@paypalsandbox.com&receiver_email=seller@paypalsandbox.com&receiver_id=seller@paypalsandbox.com&residence_country=US&item_name=something&item_number=AK-1234&quantity=1&shipping=3.04&tax=2.02&mc_currency=USD&mc_fee=0.44&mc_gross=12.34&mc_gross_1=12.34&txn_type=web_accept&txn_id=146655022&notify_version=2.1&parent_txn_id=SOMEPRIORTXNID003&reason_code=other&custom=xyz123&invoice=abc1234&test_ipn=1&verify_sign=AFcWxV21C7fd0v3bYYYRCpSSRl31AXwY9QNq9ZSeZMzEi6Nyk68hdvbc
[2016-06-20 03:52 America/New_York] cmd=_notify-validate&payment_type=instant&payment_date=Mon%20Jun%2020%202016%2017%3A50%3A12%20GMT+1000%20%28AUS%20Eastern%20Standard%20Time%29&payment_status=Canceled_Reversal&address_status=confirmed&payer_status=verified&first_name=John&last_name=Smith&payer_email=buyer@paypalsandbox.com&payer_id=TESTBUYERID01&address_name=John%20Smith&address_country=United%20States&address_country_code=US&address_zip=95131&address_state=CA&address_city=San%20Jose&address_street=123%20any%20street&business=seller@paypalsandbox.com&receiver_email=seller@paypalsandbox.com&receiver_id=seller@paypalsandbox.com&residence_country=US&item_name=something&item_number=AK-1234&quantity=1&shipping=3.04&tax=2.02&mc_currency=USD&mc_fee=0.44&mc_gross=12.34&mc_gross_1=12.34&txn_type=web_accept&txn_id=146655022&notify_version=2.1&parent_txn_id=SOMEPRIORTXNID003&reason_code=other&custom=xyz123&invoice=abc1234&test_ipn=1&verify_sign=AFcWxV21C7fd0v3bYYYRCpSSRl31AXwY9QNq9ZSeZMzEi6Nyk68hdvbc
[2016-06-20 03:52 America/New_York] INVALID
[2016-06-20 03:52 America/New_York] 200

我已经相互测试了输入和输出字符串,除了“cmd = _notify-validate&amp;&#39;”之外,它们是相同的。在输出字符串的开头。我尝试使用urlencode将输出作为数组发送回来,就像大多数示例那样,但是也没有运气。

拜托,我错过了什么?

1 个答案:

答案 0 :(得分:1)

我遇到了完全相同的问题。它似乎是IPN模拟器和任何日期字段中的错误。编码似乎全部搞砸了,这意味着当您尝试将数据发回以验证它时,PayPal认为该消息不一样。

清除所有日期字段,然后应该有效。