7
votes

I have a question to ask about payment strategy with Stripe Checkout API. consider following scenario

  1. A vendor published 10 products(apples) for 5$ each in a marketplace
  2. A customer wants to buy 8 of them, and he fill the details and click checkout button ( stripe checkout page comes)
  3. But customer waits idle for 1 hr without completing the payment ( just looking at the UI)
  4. Mean while someone else buy all 10 apples
  5. first customer doesn't know about that because he is already in final payment page.
  6. And he pays 40 $ for 8 apples
  7. Transaction is fault because no apples left to deliver.

I am trying to integrate Stripe payment gateway to my marketplace platform and I could not find a solution for this kind of scenario.

Is there any feature in Stripe to handle this ? Like session timeout period ? Or What is the standard way to handle this ?

Appreciate your help.

1

1 Answers

3
votes

I don't know if this is still relevant!

But I had the same problem before. What I did is I start managing the sessions from the application side. So I have a stripe sessions table and I have a timeout, and status of the session. Also, I have a purchase table with a status that could be pending if the user didn't pay yet. So I can update the items counts in the real store.

This is the scenario I have implemented. It might help you or anyone who is thinking of this problem. Maybe there is a more perfect scenario but this works for me :v:

  1. User presses on pay

  2. The application makes a POST request to your application create session endpoint, with all needed information

  3. In the backend, check if this user has an active session with the same information, if yes just redirect him to that active session id. If no just create another stripe session, record its info in your database and redirect the user to the new session id

  4. Then add a purchase record with the amount/quantity the user is attempting to get (with status = pending) and the session id you have. Then update the items page and subtract this quantity...

  5. Create a webhook with that session id. So you can know if it is done or not (you have to have an endpoint that accepts session ids)

  6. You check your active sessions periodically (cronjob) if a session is too old (like one hour) you just delete it and delete the pending purchase then update the items count in your store back to the actual count.

  7. And when stripe calls your webhook with the required events, you can now set the session status and purchase status to done (Don't forget to check the call signature for more security)

I hope this will help you.