Paypal IPN 库存控制
我一直在开发一家在线零售店。
它是用 php 编写的,并使用 paypal 和 IPN 来处理付款。
我自己写了购物车。当用户想要结帐时,他们单击结帐按钮,该按钮周围包含标准购物车上传功能,然后用户将被带到 PayPal 完成付款。然后 Paypal 向我发送 IPN 以通知我付款。
我的问题是,我应该在什么时候存储订单以及什么时候应该减少库存水平?
我现在的标准流程如下:
用户将商品添加到购物车。
- 如果商品现已售完或添加的数量超出可用数量,购物车会更新以反映这一情况。
- 但是,添加到购物车的库存不会减少库存水平。
用户点击结帐。
- 购物车被加载到数据库中的订单记录中,并且库存水平会减少。
- 用户将被引导至 PayPal 以完成付款。
(a) 用户完成付款。
(b) 用户未通过返回网站或前往其他地方/关闭浏览器来完成付款。
(可选)用户点击返回网站。
- 用户会看到“谢谢,订单完成”完整页面。
- 不会处理与订单表相关的任何内容,因为 PayPal 无论如何都会发送 IPN。
- Paypal发送IPN
- 使用交易状态更新订单
- 使用交易状态更新订单
正如您所看到的,此过程存在一些问题。如果客户在未完成付款的情况下离开贝宝页面,我将收到一个“悬空”订单,并且由于库存水平也减少了,因此其他客户将无法获得该库存!解决这个问题的方法是经常手动“清理”数据库。
替代品?
选项 I) 在收到“已完成的交易”IPN 之前,不要将订单存储在数据库中,然后使用会话中存储的购物车信息来创建订单并减少库存水平。但是,会话可能会过期,并且 Paypal 付款可能需要几天时间,具体取决于付款方式。
选项 II) 按现在的状态存储订单,但在收到完成的交易 IPN 之前不要减少库存水平。这仍然存在悬空订单的问题,但至少在清理时不需要再次添加库存,我只需删除订单即可。然而,另一个问题是,如果多个人在相似的时间订购,那么他们的订单总数就会超过库存。当系统收到完整的 IPNS,然后将库存水平减少到负数时,这可能会非常混乱!
我在互联网上到处寻找某种帮助,但没有任何地方提到!每个人都直接跳到如何处理 IPN。我只是不明白其他人怎么可能没有这个问题?!
请帮忙!
I have been developing an online retail shop.
It is written in php and uses paypal and IPN to handle payments.
I have written my own shopping cart. When the user wants to checkout they click on the checkout button which has the standard cart upload function wrapped around the button and the user is taken to paypal to complete payment. Paypal then sends me an IPN to notify me of the payment.
My question is, at what point should I store the order and when should the stock levels be reduced?
The standard process flow is that I have right now is as follows:
User adds item to cart.
- If item is now sold out or the quantity added is more than available, the cart is updated to reflect this.
- However, stock added to the cart does not reduce stock levels.
User clicks checkout.
- The cart is loaded into an order record in the db AND the stock levels are reduced.
- User is taken to paypal to complete payment.
(a) User completes payment.
(b) User does not complete payment by either returning to website or going somewhere else / closing browser.
(Optional) User clicks return to website.
- User sees a 'thank you, order complete' complete page.
- Nothing is processed relating to the order table since paypal will send IPN anyway.
- Paypal sends IPN
- Update order with the transaction status
- Update order with the transaction status
As you may see, there are some issues with this process. If the customer leaves the paypal page without completing payment I will have a 'dangling' order and since stock levels are also reduced this stock will not be available to other customers! A solution to this is to manually 'clean' the database every so often.
Alternatives?
option I) Do not store the order in the database until a 'completed transaction' IPN is received, then use the cart info stored in the session to create an order and reduce stock levels. However, sessions can expire and paypal payments might take days depending on payment.
option II) Store the order as is now but do not reduce stock levels until completed transaction IPN is received. This still has the issue of dangling orders but at least no stock will have to be re added again when cleaning up, I'll just have to remove the orders. Another problem with this though is that if multiple people order at similar times and thus collectively their orders contain quantities that exceed stock. This could be quite chaotic when the system receives completed IPNS and then reduces stock levels to negative quantities!
I have looked everywhere on the internet for some sort of help, but it is not mentioned anywhere! Everyone just skips to how IPN should be handled. I just don't understand how other people could not have had this problem?!
Please help!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您所面临的问题与航空公司预订系统多年来存在的问题相同。使用相同的解决方案,即
1.用户单击结帐时(同时被重定向到 Paypal)
2a。一旦您收到 IPN,即知道计费已成功
2b。有一个每隔几分钟运行一次的 cron 作业来跟踪临时订单。如果临时订单的时间超过您允许的时间(例如 20 分钟),则:
You're dealing with the same problem that airline reservation systems have for ages. Use the same solution ie
1.Upon user clicking checkout (while being redirected to Paypal)
2a. Once you receive an IPN ie know the billing has been successful
2b. Have a cron job that runs every few minutes to track temporary orders. If temporary orders are from a time greater than what you allow eg 20 mins then:
作为商家和开发商,我更喜欢使用 IPN 调整库存,即使该 IPN 处于待处理状态(例如电子支票)。两名顾客同时使用最后剩余库存进行结账的可能性通常很低。如果您确实有足够高的数量和较低的库存水平(为什么会这样?)那么您可能需要在购物车中执行某些操作,以在会话超时期间锁定商品。
如果订单被取消或退回,请确保您的订单处理代码将库存退回到库存中。
As both a merchant and a developer, I prefer to adjust inventory stock with the IPN, even if that IPN is pending (eg. an eCheck). The chance of 2 customers going through checkout at the same time with your last remaining stock is typically low. If you do have high enough volume and low stock levels (why would you?) then you may want to do something in the cart to place locks on the items for the duration of the session timeout.
Make sure your order processing code returns the inventory to stock if the order is canceled or returned.