简单的 Paypal IPN 示例?

2021-12-29 00:00:00 php paypal paypal-ipn

我想要一个带有提交按钮的文本输入表单,该表单可以转到贝宝,付款后表单的内容应该进入 mysql 数据库..

I would like to have a text input form with a submit button that goes to paypal, upon payment the contents of the form should go in a mysql database..

这听起来微不足道,但我在使用 paypal 的 IPN 时遇到了困难.

This sounds trivial, but I'm having such a hard time with paypal's IPN.

谁能指出我正确的方向?

Can anyone point in me in the right direction?

谢谢!

推荐答案

PayPal 在其网站上提供了一些示例代码.然而,您将面临的更大问题是用户可能需要实时响应.这通常是通过处理当用户单击链接返回到您的站点时提交到您的站点的 PDT 数据来完成的.稍后,PayPal 会将类似数据发布到您的 IPN 网址.您需要避免两次处理数据.

PayPal has some sample code on their website. However the bigger problem you'll face is that the user will probably want a real-time response. This is usually done by processing the PDT data that is submitted to your site when the user clicks the link to return to your site. At some point later PayPal will post to your IPN url similar data. You need to avoid processing the data twice.

此外,有问题的数据只是 PayPal 的有关交易的数据.它不包含任意数据.您可能应该在将客户的订单发送到贝宝之前记录他们的订单,或者寻找传递变量.例如,在创建计费协议时,有一个名为 custom 的变量,它会在您创建时传回给您.您可以在该变量中存储订单 ID 或任何您想要的内容.请小心验证其内容,以确保其对于交易详细信息仍然正确.

Also the data in question is only PayPal's data about the transaction. It does not contain arbitrary data. You should probably record the customer's order before sending them to paypal, or else look for a pass-through variable. For example, when creating a billing agreement, there is a variable called custom which is passed back to you as you created it. You can store an order id or whatever you want in that variable. Be careful to validate its contents to make sure it's still correct for the transaction details.

相关文章