PayPal IPN Sandbox无法返回

时间:2016-03-29 13:20:29

标签: php paypal paypal-ipn paypal-sandbox

我希望通过codeigniter中的php页面实现PayPals IPN。当我用沙箱测试我的代码时,我收不到Paypal的回复。尽管我的程序收到了原始消息,并且ipn模拟器声明“已发送IPN并且握手已经过验证”。任何人都可以指出以下代码中的错误:

if(array_key_exists('test_ipn', $_POST) && 1 == (int) $_POST['test_ipn'])
        $url = 'https://www.sandbox.paypal.com/cgi-bin/webscr';
    else
        $url = 'https://www.paypal.com/cgi-bin/webscr';

    // Set up request to PayPal
    $request = curl_init();
    curl_setopt_array($request, array
    (
        CURLOPT_URL => $url,
        CURLOPT_POST => TRUE,
        CURLOPT_POSTFIELDS => http_build_query(array_merge(array('cmd' => '_notify-validate'),$_POST)),
        CURLOPT_RETURNTRANSFER => TRUE,
        CURLOPT_HEADER => FALSE,
    ));

    // Execute request and get response and status code
    $response = curl_exec($request);
    $status   = curl_getinfo($request, CURLINFO_HTTP_CODE);

    // Close connection
    curl_close($request);

    $myfile = fopen("/var/www/vhosts/example.com/subdomains/apidev/httpdocs/application/controllers/test.txt", "w") or die("Unable to open file!");
    fwrite($myfile, json_encode($_POST)."\n\n");
    fwrite($myfile, $url."\n\n");
    //$response = file_get_contents($url);
    fwrite($myfile, "Response: ".$response."\n");
    fclose($myfile);
}

该文件的内容是:

{"payment_type":"instant","payment_date":"Tue Mar 29 2016 08:35:27 GMT-0400 (EDT)","payment_status":"Completed","address_status":"confirmed","payer_status":"verified","first_name":"John","last_name":"Smith","payer_email":"buyer@paypalsandbox.com","payer_id":"TESTBUYERID01","address_name":"John Smith","address_country":"United States","address_country_code":"US","address_zip":"95131","address_state":"CA","address_city":"San Jose","address_street":"123 any street","business":"seller@paypalsandbox.com","receiver_email":"seller@paypalsandbox.com","receiver_id":"seller@paypalsandbox.com","residence_country":"US","item_name1":"something","item_number1":"AK-1234","tax":"2.02","mc_currency":"USD","mc_fee":"0.44","mc_gross":"12.34","mc_gross_1":"12.34","mc_handling":"2.06","mc_handling1":"1.67","mc_shipping":"3.02","mc_shipping1":"1.02","txn_type":"cart","txn_id":"366657134","notify_version":"2.1","custom":"xyz123","invoice":"abc1234","test_ipn":"1","verify_sign":"AFcWxV21C7fd0v3bYYYRCpSSRl31Ad3zyAU11sBY.hh-lw41XA9TQLb4"}

https://sandbox.paypal.com/cgi-bin/webscr

Response: 

0 个答案:

没有答案