我的网站上有一个简单的 PayPal 购买按钮。用户转到 paypal,当他完成购买时,他会自动重定向到我的网站(目前在沙箱上,重定向之前有一个屏幕,显示“如果 10 秒后您没有被重定向......”)。另外,我在我的服务器上设置了带有 url 的 notification_url 来处理成功的付款。
我有两个问题:
我的网站使用用户登录。所以点击购买按钮的人是已经登录的用户。我的问题是,当我在 notification_url 上处理 paypal IPN 时,确定哪个用户进行了购买的最佳方法是什么?我考虑过根据按钮表单上的用户 ID 设置唯一标识符,但我找不到如何执行此操作的文档。
当用户完成购买后,他应该能够访问某些内容。假设用户登陆 http://www.example.com/account购买后,我想检查数据库,看看他是否真的成功完成了购买。所以我的问题是,我可以确定在用户登陆/account 之前会执行 notification_url 回调吗?
我真的不想让成功购买但仍然无法访问的客户感到愤怒。确保这种情况永远不会发生的最佳方法是什么?
谢谢。
最佳答案
如果你看IPN and PDT variables page对于 Paypal,您会看到可以使用名为“自定义”的字段。其说明:
custom: Custom value as passed by you, the merchant. These are pass-through variables that are never presented to your customer. Length: 255 characters
表单示例:
<input type="hidden" name="custom" value="<?php echo $user_id; ?>"/>
在您的 IPN 响应脚本中:
$user_id = $_POST['custom'];
关于php - 将用户标识符传递给 PayPal 的 notification_url,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12693314/