This question already has an answer here:
I would like to implement a robust way to handle ecommerce payment for items with limited quantity, like for example exclusive paintings. Payment would ideally be accepted via PayPal and credit cards. Ideally, it would work on a 'first-come-first-serve' basis, and wouldn't just lock items out if you add them to cart like some online fashion stores do.
However, the main problem is that once you redirect the user to the payment solution, you do not have control over the user.
Even if I was to implement some form of locking on items, i.e a user adds it to cart and it is temporarily locked for other users for say 30 minutes - I think this problem would still prevail given the below workflow:
- User A adds item A with limited quantity (1) to cart. Item is removed from website for 30 minutes
- User A goes to payment on PayPal.
- For some reason, UserA does not pay immediately on PayPal but keeps session alive for say 1 hour
- After 30 minutes, website will restore item A back in stock
- User B adds to cart
- User B proceeds to payment
- User B pays for item
- User A, with the continuously refreshed session, pays for item as well.
This would result in double-purchase for the same item.
Is it possible to solve this problem 100%? I highly doubt this would happen in real-life, but would like to handle all possible cases.