Search code examples
paypale-commercecartinventory

When to subtract inventory during a paypal transaction


This question is more conceptual than technical and I can't seem to find a good solution. I am developing a high-traffic eCommerce site using chained payments and the Adaptive Payments API.

At what point during the sale and subsequent paypal transaction should my site subtract inventory in order to prevent over ordering?

Many of the open source e-commerce sites I've come across appear to subtract inventory only once the IPN is received and confirmed; however, on a high-traffic site this could produce over ordering of a product if seperate buyers purchase the same item within a close time frame. On the other hand, if the inventory is reduced before payment is received, how long should it wait to void the unpaid order and re-stock the inventory? What would be the best solution?

Thank you in advance for any advice on this subject.


Solution

  • We are using the following process;

    1. Each item has an entry in the "inventory" DB table. We don't have a single "quantity" field per product because it doens't ensure 1:1 consistency. (We've modeled it similar to http://kylebanker.com/blog/2010/04/30/mongodb-and-ecommerce/, but implemented it in MySQL)
    2. We set a 10 minute "hold" on items once they are placed in the cart (this means 10 mins of inactivity, not 10 mins total from when they add the item)
    3. When a customer goes to the checkout we up that to 20mins (to give them time to enter all their details. You'd be surprised how long it takes some people)
    4. When a customer goes to paypal we up that to 3 hours. This is definitely not ideal because it means very low stock items may appear "unavailable" for a long time. However this is Paypal's time limit on the payKey and will guarantee that the payment has either been made, or cannot ever be made with that key.
    5. Then once you receive the IPN you permanently set the stock item as "unavailable"

    As I mentioned, the 3hr session timeout isn't ideal so we are considering using Embedded Payment Flow Using Adaptive Payments which will allow us to use javascript to keep track of the session time, and force a page refresh if they have taken long than say 30mins.

    I would love to hear if a better solution exists from someone at Paypal though. Ideally it would be better if we could implement an "Express Checkout" style pay call once the user returned to the site, rather than relying on IPN to complete the order.