Paypal:即使是成功创建的定期付款,也会收到无效的IPN响应

时间:2013-02-04 12:26:55

标签: paypal

我的paypalipn.php文件看起来像,

<?php

$raw_post_data = file_get_contents('php://input');
$raw_post_array = explode('&', $raw_post_data);
$myPost = array();
foreach ($raw_post_array as $keyval) {
  $keyval = explode ('=', $keyval);
  if (count($keyval) == 2)
     $myPost[$keyval[0]] = urldecode($keyval[1]);
}
// read the post from PayPal system and add 'cmd'
$req = 'cmd=_notify-validate';
if(function_exists('get_magic_quotes_gpc')) {
   $get_magic_quotes_exists = true;
} 
foreach ($myPost as $key => $value) {        
   if($get_magic_quotes_exists == true && get_magic_quotes_gpc() == 1) { 
        $value = urlencode(stripslashes($value)); 
   } else {
        $value = urlencode($value);
   }
   $req .= "&$key=$value";
}


// STEP 2: Post IPN data back to paypal to validate

$ch = curl_init('https://www.paypal.com/cgi-bin/webscr');
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, $req);
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_HTTPHEADER, array('Connection: Close'));


if( !($res = curl_exec($ch)) ) {
    // error_log("Got " . curl_error($ch) . " when processing IPN data");
    curl_close($ch);
    exit;
}
curl_close($ch);


// STEP 3: Inspect IPN validation result and act accordingly

if (strcmp ($res, "VERIFIED") == 0) {


    // assign posted variables to local variables
    $item_name = $_POST['item_name'];
    $item_number = $_POST['item_number'];
    $payment_status = $_POST['payment_status'];
    $payment_amount = $_POST['mc_gross'];
    $payment_currency = $_POST['mc_currency'];
    $txn_id = $_POST['txn_id'];
    $receiver_email = $_POST['receiver_email'];
    $payer_email = $_POST['payer_email'];
} else if (strcmp ($res, "INVALID") == 0) {

}
?>

我已将Paypal实施到我的应用程序中。我可以成功获得定期付款的个人资料ID,但我从即时付款通知中得到的回复无效。只有那个原因是我得到的,而且我也没有得到任何关于它的错误消息。所以我一直在寻找你的帮助......

1 个答案:

答案 0 :(得分:1)

您使用的是Sandbox吗?实时网站不会验证沙盒中的IPN,反之亦然。如果IPN来自Sandbox,您需要将其发送回Sandbox进行验证。

尝试更改此代码:

$ch = curl_init('https://www.paypal.com/cgi-bin/webscr');

对此:

if($myPost['test_ipn'] == "1") {
    $ch = curl_init('https://www.sandbox.paypal.com/cgi-bin/webscr');
} else {
    $ch = curl_init('https://www.paypal.com/cgi-bin/webscr');
}