通过数据库插入处理 PayPal IPN
我希望使用 PayPal Pro 托管解决方案来处理我的网站的付款,我想要实现的是,在 PayPal 确认我已收到其输入的付款之前,用户提交的数据不会插入我的数据库中。
根据我所读到的内容,我知道 IPN 是实现这一目标的最佳方式。
所以目前,用户正在使用表单输入他们的数据,然后我向他们预览,如果他们批准他们的输入,我将插入到数据库中(使用 PHP/MySQL)。目前的表单数据正在 SESSION 变量中传递并且工作正常。文件过程是:
- 用户输入数据
- 用户将在已知页面上看到他们输入的数据,如果他们批准...
- 他们单击一个按钮来处理插入到数据库中的操作。
但是我想做的是,如果他们在预览页面上批准了他们的条目,当他们单击批准时,而不是在那里更新数据库,然后将他们发送到 PayPal 进行付款,并且只用他们的条目更新数据库如果付款被批准,如下所示:
- 用户输入数据
- 用户将在已知页面上看到他们输入的数据,如果他们批准...
- 他们单击一个按钮,将他们带到付款页面
- 如果收到付款,他们的数据将被添加到数据库。
有没有人对这种方法有任何经验,为我指出正确的方向,或者给我一些如何去做的指导?
我已经查看了 PayPal 文档,但因为我对此不熟悉,所以我需要以非常简单的方式进行解释。
我最初的想法只是将表单存储为 SESSION 变量,但我会通过将人们重定向到付款页面来丢失它。我的另一个想法是创建一个与我已有的数据库相同的数据库作为数据的临时保存阶段,然后如果 IPN 获得批准,则将数据移动到最终的托管数据库,但这似乎有点过度设计问题。
我希望有人能提供帮助。
谢谢 担
I am hoping to use the PayPal Pro Hosted Solution to handle payments for my website, and what i would like to achieve is that user submitted data is NOT inserted into my database until PayPal confirms i have received payment for their entry.
From what I've read, i understand the IPN is the best way to achieve this.
So at the moment, users are entering their data with a form, which i am then previewing to them, and if they approve their entry, i am inserting into a database (using PHP/MySQL). The form data at the moment is being passed along in SESSION variables and working fine. The file process is:
- User enters data
- User is presented with their entered data on a knew page and if they approve...
- They click a button which handles the insert into the database.
However what i would like to do is, if they approve their entry on the preview page, when they click approve, instead of the database being updated there and then, send them to PayPal to make the payment and only update the database with their entry if the payment is approved, like this:
- User enters data
- User is presented with their entered data on a knew page and if they approve...
- They click a button which takes them to the payment page
- If payment is received, their data is added to the database.
Does anyone have any experience of this type of approach point me in the right direction or give me some guidance on how to go about this please?
I have looked over the PayPal documentation but because I'm new to this, i need things explained in a pretty simple manner.
My original idea was just to store the form is SESSION variables but i will lose this by redirecting people to the payment page. Another thought i had was to create an identical database to what i already have as a temporary holding stage for data, then if the IPN comes back approved, move the data to the final hosting database, but this seems like over engineering the problem a bit.
I hope someone can help.
Thanks
Dan
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
在这种情况下,使用 PayPal IPN 似乎是最好的解决方案。
在我看来,使用临时表似乎是最好的解决方案。它将遵循 KISS 规则。
请考虑使用以下场景:
这似乎是最简单的解决方案。
Using PayPal IPN seems to be the best solution in this case.
In my opinion, using temporary table seems to be the best solution. It'll be following KISS rule.
Please consider using following scenario:
It seems to be the simplest solution.
关于 IPN 需要认识到的一个问题是,它是来自 PayPal 的“异步”响应 - 它不在用户的浏览器会话中,因此如果您完全依赖 IPN,则会话变量将不起作用(除非您收到 IPN 响应并且然后将其与用户的会话相匹配)。 PayPal 还提供 PDT(付款数据传输),这是一种“会话中”响应,可以将用户返回到您的网站。
我不会完全依赖 IPN 进行付款通知(请参阅以下 SO 主题中的答案)可以仅依靠 Paypal IPN 来记录购买吗?。
我们的系统使用 IPN 和 PDT 的组合,“购物车”数据存储在数据库中(作为您的“临时”记录),直到 PDT 或 IPN 通知已完成付款 - 以先到者为准,完成交易(您的“永久”数据库插入)并删除“临时”记录(因此后续 IPN 或 PDT 不会触发重复事务)。
One matter to recognize regarding IPN is that it is an 'Asynchronous' response from PayPal - it is not in the user's browser session, so session variables will not work if you are relying exclusively on IPN (other than if you receive the IPN response and then match it to the user's session). PayPal also offers PDT (Payment Data Transfer) which is an 'in-session' response which could return the user to your site.
I would not rely exclusively on IPN for payment notifications (see my answer in the following SO topic) Can one rely on Paypal IPN solely to record purchases?.
Our system uses a combination of both IPN and PDT, with the 'cart' data stored in a DB (as your 'temporary' record) until notification of the completed payment by either PDT or IPN - whichever arrives first which completes the transaction (your 'permanent' database insertion) and deletes the 'temporary' record (so a subsequent IPN or PDT does not trigger a duplicate transaction).
未必。只要当前浏览器(会话)打开,会话通常就可以持续存在。如果您正确设置了会话 cookie,这与“只要查看当前页面”不同。如果你做得正确的话,你可以让课程持续几天、几个月、几年......
不,这并不是矫枉过正。
它处理交易未完成的情况。发生这种情况的原因有多种,例如,您的用户去吃午饭并忘记在会话超时(默认为 20 分钟左右)之前完成该过程,或者 Paypal 端出现问题(不太可能,但您可以必须假设它可能发生)或存在一般网络问题(ISP 在事务处理过程中中断),或您的移动用户超出网络覆盖范围。任何事情都可能干扰交易,您需要有一个后备位置。否则,这会让您(因为您不知道是什么以及在什么时候中断了交易)以及必须重新开始的用户感到烦恼。
拥有临时数据库允许您监视未完成的事务,并在必要时提示用户在给定时间段内未完成操作时完成操作。
Not necessarily. Sessions can generally persist for as long as the current browser (session) is open. This is not the same as "as long as the current page is viewed" provided you set the session cookie correctly. You can if you do it right have the sessions persist for days, months, years...
No this is not overkill.
It deals with the situation where a transaction is not completed. This could occur for a number of reasons, for example your user goes to lunch and forgets to complete the process before the session times out (the default is 20 or so minutes) or where there is a problem with the Paypal end (unlikely but you have to presume it can occur) or where there is a general network issue (isp goes down mid transaction), or where your mobile users goes out of network coverage. Anything can disturb a transaction and you need to have a fall-back position. Otherwise it becomes annoying for you (because you don't know anything about what interrupted the transaction and at what point) and for your user who has to start over again.
Having a temporary database allows you to monitor incomplete transactions and if necessary prompting the user to complete if they do not do so within a given period of time.