Search code examples
ruby-on-railsonline-store

How do you synchronize stock and payment on an online store?


I am working on an online store i developp from scratch using Ruby On rails.

I have a design question about stock and orders.

When do you update stock when a user select a product

  • If you lower the stock when the product is put in the cart, you must be able to restock if the user close his browser. Problem, rails does not handle session expiration for this use case

  • If i lower stock before sending the customer to my payment solution (like paypal, google checkout or amazon), i still am not notified if the user close his browser.

-If i lower stock once the payment is valid, i may have two different customers buying the same product when only one is left, and the shop now must deliver two product when he has only one left.

Do you know how online store handle this problem ?

Where can i find design documents of open source online store ?


Solution

  • Well normally you keep inventory separated such that you have one value for what is in the warehouse and one value for submitted but not shipped orders.

    When an item is placed in a shopping cart all you can do is inform the user when the effective inventory changes, i.e. when another user has submitted an order. There are no guarantees until the cart has been checked out.