PayPal IPN“失败”

发布于 2024-09-02 05:09:46 字数 965 浏览 8 评论 0原文

我试图弄清楚如何使用 PayPal 的 IPN,但遇到了困难。

我希望买家在购买后转到成功页面,并且我希望该页面显示其交易的详细信息。我选择 IPN 而不是 PDT,因为我还想用他们的数据做一些其他幕后的事情。

不管怎样,这是我正在使用的代码——我正在沙盒模式下测试——但它每次都返回“FAIL”。

$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 ('www.sandbox.paypal.com', 80, $errno, $errstr, 30);

if (!$fp) {
// HTTP ERROR
} else {
fputs ($fp, $header . $req);
while (!feof($fp)) {
$res = fgets ($fp, 1024);
if (strcmp ($res, "VERIFIED") == 0) {

// PAYMENT VALIDATED & VERIFIED!

echo "Validated!";

}

else if (strcmp ($res, "INVALID") == 0) {

// PAYMENT INVALID & INVESTIGATE MANUALY!

echo "Invalid!";

}
}
fclose ($fp);
}

I'm trying to figure out how to use PayPal's IPN and I've run into a wall.

I want a buyer to be forwarded to a success page after making a purchase, and I want that page to show the details of their transaction. I choose IPN instead of the PDT because I also want to do some other behind the scenes stuff with their data.

Anyway, here's the code I'm using -- I'm testing in sandbox mode -- but it returns "FAIL" every time.

$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 ('www.sandbox.paypal.com', 80, $errno, $errstr, 30);

if (!$fp) {
// HTTP ERROR
} else {
fputs ($fp, $header . $req);
while (!feof($fp)) {
$res = fgets ($fp, 1024);
if (strcmp ($res, "VERIFIED") == 0) {

// PAYMENT VALIDATED & VERIFIED!

echo "Validated!";

}

else if (strcmp ($res, "INVALID") == 0) {

// PAYMENT INVALID & INVESTIGATE MANUALY!

echo "Invalid!";

}
}
fclose ($fp);
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

草莓味的萝莉 2024-09-09 05:09:46

我在测试环境中遇到了同样的问题,因为我的 item_name 有特殊字符,
然后我将 item_name 更改为仅英文单词和数字。效果很好。

但在实际环境中我仍然发现这个问题,我阅读了 https://www.x.com /docs/DOC-1551,但我还是不知道为什么

i got the same problem in the test enviroment because my item_name has especial character,
then i change item_name to only english word and number. it works fine.

but in real enviroment i still find this problem,i read the https://www.x.com/docs/DOC-1551, but i still don't know why

狼亦尘 2024-09-09 05:09:46

我没有意识到我设置的沙盒帐户未经验证。我重新制作了预先配置的沙箱帐户,然后它开始完美工作。

I didn't realize that the sandbox account I set up was Unverified. I re-made the pre-configured sandbox account and then it started to work perfectly.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文