Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dealing with two people buying a unique item in an online shop at the same time

I'm creating a simple online shop with PHP integrated with PayPal that sells unique items. What I'm wondering is how other shops deal with multiple people attempting to go through the payment process with the same item.

This is my current draft strategy:

  • Items have three status types: available, on hold & sold.
  • As a user moves to the PayPal payment page it checks the status of all the items in the cart to ensure they're available. It also sets the item's status to "on hold" until they either come back after payment is confirmed or it times out (10 minutes? Not sure what this should be).

Is this standard practice or is there a more practical way I should be going about this?

Thanks in advance!

like image 621
John Jones Avatar asked Feb 18 '10 12:02

John Jones


2 Answers

Have a look at Dell's UK outlet. When someone adds a system to their shopping basket it is held and not available to other customers. If it isn't purchased, the item is removed from the basket after 15mins of inactivity and is then available to other customers.

like image 168
macleojw Avatar answered Oct 23 '22 21:10

macleojw


I would say the first part of your strategy is correct - as you move to the payment page, flag all the products as 'on hold'

When the user has finished the payment, you will get a postback from Paypal which lets you know if the authorisation was successful or not (and possibly also allows you to check the CSC/CVV2 result), and at that point you have the option of either accepting the payment, or rejecting it.

On receipt of the postback you should also check whether the items are still on hold. If they have timed out you can reject the payment and display a message 'sorry - timeout exceeded' or somesuch.

This method also allows you to work out an ideal timeout period if you keep track of how often customers run into the timeout, so you can extend the timeout from (eg) 5 to 10 minutes if too many are timing out, or shorten it if none are timing out.

like image 1
PaulG Avatar answered Oct 23 '22 21:10

PaulG