I am developing an Ecommerce website and I have one doubt in my mind. Suppose user added a product in his cart and clicked on checkout and he is transfered to a payment gateway which arises some conditions
What if user 1 clicked on checkout and never came back from a gateway like he has closed the browser or a tab and i have deducted the quantity when he clicked on checkout button so that user 2 can see the actuall quantity available.
if i don't deduct the quantity when checkout button is clicked and user 2 has also checked out just after the user 1 and product is having limited quantity which have been bought by user 1.
How to handle this situation? I am using php and mysql.
I recommend you to deduct the quantity only when the checkout is finished.
The user who finish the checkout last will receive an error explaining that the product isn't available anymore.
Another approach used by e-commerces is JIT(Just-in-time), so the product is "always available" and this problem will not happens.