Hi I am writing a REST web application and confused on how to handle the payment via Stripe.
I am unclear on when to create order, below is 2 approaches I have thought:
First approach
- User enters order details and clicks place order.
- Order gets created in database with a boolean flag is_active and orderId is sent to UI.
- user gets redirected to stripe payment page.
- user enters card details and we get stripe token for charging card
- token with orderId sent to backend.
- token is used in backend to send request to Stripe to charge user, if charge success then mark order as active otherwise report failure to user.
Second approach
- User enters details and clicks place order.
- user gets redirected to stripe payment page.
- user enters card details and we get stripe token for charging card
- token with orderdetails sent to backend.
- token is used in backend to send request to Stripe to charge user, if charge success then create order otherwise report failure to user.
which of the above two approach should I use or is there any other way through which I should be handling the payments?