We are building a online store that the in stock quantity is updated after every sale. We use 3rd party financial transaction site, such as authorizent, to handle the credit card payment. We don't handle the credit card payment on our site.
Our site take the address and orders information, check the "in stock availablity", and pass the order to authorizenet, authorizenet will take the credit card information and process the financial transaction and pass the results back to our site. Our site will update the in stock quantity after we get the results from authorizenet.
But there is a possible time gap.
Say client A, add the item#1 (in stock quantity is 1) to the cart, and Client B at the same time, add the item #1 to his cart too.
Client A's order is passed to authorizenet, and at this moment Client A is filling out his credit card information at the authorizenet. (So our site, the in stock quantity is still 1), then client B's order is ready to be passed to authorizenet. Our site checks the in stock quantity, still available, we pass the client B's order to authorizent.
Both orders passed to authorizenet, authorizenet take their credit cards payment and both payments is "AUTHORIZED". But the problem is we one have 1 item #1.
When authorizent pass back the transaction results to our sitem, and our site updates our in-stock quantity. At this moment we can find that Item #1 is double sold.
The solutions is: then the merchant have to refund the second client B and informed him.
Are there better solutions?
Will authorizenet or other financial transaction sites can also check with our site for the availability at the last step when they process the credit card transaction? For example after Client A or Client B fill out the credit card information at the authorizenet and submit, then authorizenet will have to check with us again to see if the quantity is still available at this moment, if yes, they will process, if no, they will not process.
Other solutions are
1) If Client A's order is passed to authorizenet, I will lock the item #1 off, so the client B's order cannot be passed to authorizenet. But lock it for how long? when to release it? All are questions.
Any people have the similiar projects and how do you solve the problem?