PayPal IPN通知接收同一付款的多个通知

时间:2013-04-15 11:40:42

标签: php codeigniter paypal-ipn

我想知道为什么我收到一次付款的多个IPN通知,以及我如何阻止这一点。我想只保留一个通知。

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

//$ch = curl_init('https://www.paypal.com/cgi-bin/webscr');
$ch = curl_init('https://www.sandbox.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'));

// In wamp like environments that do not come bundled with root authority certificates,
// please download 'cacert.pem' from "http://curl.haxx.se/docs/caextract.html" and set the directory path 
// of the certificate as shown below.
// curl_setopt($ch, CURLOPT_CAINFO, dirname(__FILE__) . '/cacert.pem');
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) {

    // my stuff goes here

} else if (strcmp ($res, "INVALID") == 0) {
    // log for manual investigation
}

2 个答案:

答案 0 :(得分:3)

我想到了两个可能性:

  1. PayPal重试通知,如果您的处理脚本返回HTTP错误。
  2. 对于某些转化,PayPal会发送多个通知。喜欢检查。或者当交易被取消/退款/撤销时。您需要检查付款状态字段。

答案 1 :(得分:0)

它看起来像是一个很老的帖子,但我在2019年发现了同样的问题 您只需添加

即可解决此问题
    header("HTTP/1.1 200 OK");

在代码的第一行中添加http标头200。