【问题标题】:Why is my PayPal IPN script failing?为什么我的 PayPal IPN 脚本失败?
【发布时间】:2011-09-07 07:08:18
【问题描述】:

我正在开发一个使用 PayPal 作为支付网关的轻量级电子商务解决方案。但是,我的 IPN 回调不断返回 INVALID 响应。我什至尝试使用 PayPal 提供的示例 PHP 脚本:

// read the post from PayPal system and add 'cmd'
$req = 'cmd=_notify-validate';

foreach ($_POST as $key => $value) {
  $value = urlencode(stripslashes($value));
  $req .= "&$key=$value";
}

// post back to PayPal system to validate
$header .= "POST /cgi-bin/webscr HTTP/1.0\r\n";
$header .= "Content-Type: application/x-www-form-urlencoded\r\n";
$header .= "Content-Length: " . strlen($req) . "\r\n\r\n";
$fp = fsockopen ('ssl://www.paypal.com', 443, $errno, $errstr, 30);

// 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'];

if (!$fp) {
  // HTTP ERROR
}
else {
  fputs ($fp, $header . $req);
  while (!feof($fp)) {
    $res = fgets ($fp, 1024);
    if (strcmp ($res, "VERIFIED") == 0) {
      // check the payment_status is Completed
      // check that txn_id has not been previously processed
      // check that receiver_email is your Primary PayPal email
      // check that payment_amount/payment_currency are correct
      // process payment
    }
    else if (strcmp ($res, "INVALID") == 0) {
      // log for manual investigation
    }
  }
  fclose ($fp);
}

但正如我所说,我不断收到INVALID 的回复。这实际上是我使用将响应写入日志文件的 PHP 类得到的响应:

[2011-06-02 19:18:49] - FAIL: IPN Validation Failed.
IPN POST data from PayPal:
test_ipn=1,
payment_type=instant,
payment_date=11:07:43 Jun 02, 2011 PDT,
payment_status=Completed,
payer_status=verified,
first_name=John,
last_name=Smith,
payer_email=buyer@paypalsandbox.com,
payer_id=TESTBUYERID01,
business=seller@paypalsandbox.com,
receiver_email=seller@paypalsandbox.com,
receiver_id=TESTSELLERID1,
residence_country=US,
item_name1=something,
item_number1=AK-1234,
quantity1=1,
tax=2.02,
mc_currency=USD,
mc_fee=0.44,
mc_gross=15.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=4362187,
notify_version=2.4,
custom=xyz123,
invoice=abc1234,
charset=windows-1252,
verify_sign=AjbdIvvDAW2fh1O9jAbEym4myX.WAV7-jCEiEWMqoSkewvM6L3Co6oUQ

这是来自官方的PayPal IPN 测试工具。所以 PayPal 的示例代码和测试工具之间的某些东西导致我的脚本失败。有人有什么想法吗?

【问题讨论】:

    标签: php paypal paypal-ipn paypal-sandbox


    【解决方案1】:

    你的 html/php 页面的编码是什么? (charset=windows-1252) ?

    【讨论】:

    • 没有。我相信它是 UTF-8...<meta charset="UTF-8" /> (HTML 5)。
    • 那么为什么你使用 charset windows-1252 ;) 我昨天也遇到了同样的问题
    • 在您的贝宝账户上配置!沙盒也是!
    • 如何更改此设置?它位于我的 PayPal 帐户中的哪个部分?
    • 我的贝宝是法语的,所以很抱歉翻译 Preferencs=>更多选项 => 偏好销售 => 编码语言 => 更多选项paypalobjects.com/en_US/ebook/…
    猜你喜欢
    • 2011-01-09
    • 2019-02-02
    • 2016-08-17
    • 2012-06-24
    • 2016-10-15
    • 2018-12-28
    • 2018-05-21
    • 2013-06-30
    • 1970-01-01
    相关资源
    最近更新 更多