duanchuonong5370 2011-10-01 21:17
浏览 66

Paypal 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:

  1. 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.
  2. 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.
  3. (a) User completes payment.

    (b) User does not complete payment by either returning to website or going somewhere else / closing browser.

  4. (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.
  5. Paypal sends IPN
    • 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!

  • 写回答

2条回答 默认 最新

  • douweilei2307 2011-10-01 23:10
    关注

    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.

    评论

报告相同问题?

悬赏问题

  • ¥500 52810做蓝牙接受端
  • ¥15 基于PLC的三轴机械手程序
  • ¥15 多址通信方式的抗噪声性能和系统容量对比
  • ¥15 winform的chart曲线生成时有凸起
  • ¥15 msix packaging tool打包问题
  • ¥15 finalshell节点的搭建代码和那个端口代码教程
  • ¥15 Centos / PETSc / PETGEM
  • ¥15 centos7.9 IPv6端口telnet和端口监控问题
  • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作
  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录