尝试实施Paypal即时付款通知https://developer.paypal.com/docs/ipn/#use-ipn-in-your-checkout-flow
情况如下:
1)访客想要访问数据库(访问者输入一些内容以检查输入的数据是否存在于数据库中)
2)我收集访问者输入的数据,将其记录在mysql中,创建一些令牌,也记录在mysql中
3)将令牌添加到数据中,然后发送给Paypal。
4)付款成功后,我允许访问者访问数据库并显示访问者输入数据的结果。因此需要知道访客输入/订购了什么。
我向Paypal发送这样的数据:
$data['return'] = 'https://www.my-website.info/payment-successful.php?response='. $token_to_send_to_paypal;//here we can put URL when payment is Successful.
$data['cancel_return'] = 'https://www.my-website.info/payment-cancelled.php';//here we can put cancel URL when payment is not completed.
$data['notify_url'] = 'https://www.my-website.info/payment-notify.php';//PayPal call this file for ipn
$data['item_number'] = $token_to_send_to_paypal;
然后
$query_string = http_build_query($data);//http_build_query — Generate URL-encoded query string
然后重定向到贝宝IPN
header( 'location:'. $paypal_url. '?'. $query_string );
从Paypal成功付款后,我得到了一些数据。我看到我回来了item_number=the same as token i created sent to paypal
。
以上是目前我如何才能使游客的订单与付款相匹配的唯一方法。但是可能的问题是访问者也知道令牌。
有什么主意/更好的方法如何使访客的订单与付款相匹配?我的意思是如何将我的令牌发送到Paypal并在Paypal响应中取回令牌?
答案 0 :(得分:1)
但是可能的(?)问题是访问者也知道令牌。
为什么这是个问题?这不是问题。访客无法创建可验证的IPN。
真正的答案是,您应该切换到更好的结帐方式,并且根本不使用IPN,因为这很重要,因为那样您就不需要它了。这是一个更好的结帐方式:https://developer.paypal.com/demo/checkout/#/pattern/server
有了更好的签出功能,以下是您将从服务器调用的捕获API:https://developer.paypal.com/docs/checkout/reference/server-integration/capture-transaction/
然后就不需要IPN。