Search code examples
reactjsstripe-paymentsproduct-quantity

Stripe: manage a product's quantity


I'm trying to set up a basic Stripe store to sell some t-shirts I silkscreened. I'm using this React setup. Each shirt has a limited quantity, about 12 of each size. I want to make it so when a size is sold out, the "add to cart" button disables.

Is there a way to track quantity with Stripe in this way? I can't seem to find any docs.


Solution

  • You client side app need to be aware of each client that buys a shirt.

    There are several ways to achieve this.

      1. The most ugly one is each x seconds you check all displayed t shirts on the screen quantities. aka: setInterval(checkAvailability, x)
      1. When the user presses the button (still enabled) you make a call to your api to check if the related t-shirt is still available, if not, display an error message and disable the button (this is what I recommend in your case, because it's the cheapest and the simplest and can be improved in many ways).
      1. Connect your client side app to your api using socket or server side events and each time a t-shirt is bought, you notify your client side app.