如何测试 Paypal IPN 通知 [英] How to test Paypal IPN notification

查看:68
本文介绍了如何测试 Paypal IPN 通知的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试让这个 PayPal IPN 脚本工作,但似乎我没有得到 paypal 的响应.我不知道是什么问题,是在形式上还是在脚本中:

I'm trying to get this PayPal IPN script work but it seems that i don't get the response from paypal . I don't know what's the problem, is in the form or in the script:

<form action="https://www.sandbox.paypal.com/cgi-bin/webscr" method="post" target="_top">
    <input name="return" type="hidden" value="http://localhost/home/menu/index.php" />
    <input name="cancel_return" type="hidden" value="http://localhost/home/menu/index.php" />
    <input name="notify_url" type="hidden" value="http://localhost/home/menu/php/inni.php" /> 

这是inni.php的脚本:

and this is the script inni.php:

$req = 'cmd=_notify-validate';
foreach ($_POST as $key => $value) {
    $value = urlencode(stripslashes($value));
    $req .= "&$key=$value";
}
$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.sandbox.paypal.com', 443, $errno, $errstr, 30);
$item_name = $_POST['item_name'];
if (!$fp) {

} else {
fputs ($fp, $header . $req);
while (!feof($fp)) {
    $res = fgets ($fp, 1024);
    if (strcmp ($res, "VERIFIED") == 0) {
        // vérifier que payment_status a la valeur Completed
        if ( $payment_status == "Completed") {
                         if ( $email_account == $receiver_email) {
//insert in db
          }
        }
        else {
                // Statut de paiement: Echec
        }
        exit();
   }
    else if (strcmp ($res, "INVALID") == 0) {
        // Transaction invalide
    }
}
fclose ($fp);
}   

推荐答案

您需要将 PayPal IPN 请求转发到您的本地计算机才能使其工作.有几个项目可以解决这个问题,包括免费的和商业的.

You need to forward PayPal IPN requests to your local computer for it to work. There are several projects dealing with this, both free and commercial.

免费和开源变体是:https://github.com/antoniomika/sish

一种商业变体:https://ngrok.com/

Ngrok 的实现速度要快一些,因为您不需要配置服务器.

Ngrok is somewhat faster to implement since you don't need to configure the server.

使用 Ngrok 将 http 请求转发到 localhost

To forward http requests to localhost with Ngrok

./ngrok http -host-header=localhost 80

然后在浏览器中打开

http://localhost:4040/inspect/http

从状态页面复制您的 ngrok 网址

Copy your ngrok url from the status page

https://d1c7361aebf0.ngrok.io

假设您的 IPN 通知网址是

Assuming your IPN notification url is

https://www.example.com/api/paypal-ipn

将其更新为并开始测试即时付款通知

Update it to and start testing instant payment notifications

https://d1c7361aebf0.ngrok.io/api/paypal-ipn

注意:确保禁用所有与域名相关的重定向以使其正常工作.

Note: Make sure you disable all domain name related redirects for it to work.

这篇关于如何测试 Paypal IPN 通知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆