The "main" page has a form with a checkout button. The data from the form is saved inside states on this page using useState. I want to add the data from the form into firestore if the payment is successful. The problem is that stripe.redirectToCheckout() redirects to an specified URL on succesful payment and does not bring any data to the new URL.
Ways that I've thought about solving this problem:
Adding the data to cloud firestore before redirecting to the checkout page and removing the data if the payment status is "canceled" and keeping it if it's "success" using cloud functions. The problem is that if the user does not even start the payment process, the data will be left in firestore. So I would have to implement some kind of periodic check to see if the user has started a payment at all.
Somehow pass the data from the main page to the success_url with something like useContext. The problem is that success_url is not returned so I'm not sure how to go about that.
All help is greatly appreciated!
CodePudding user response:
You can have the checkout session ID included in the success_url
by using the {CHECKOUT_SESSION_ID}
placeholder (docs)
successUrl: "http://yoursite.com/order/success?session_id={CHECKOUT_SESSION_ID}"
Then on your success page your can read that session_id
parameter from the URL and retrieve the session from the API to get any data you want to store.