I am trying to get the result value from a stripe.redirectToCheckout(). It is said to return a Promise https://stripe.com/docs/js/checkout/redirect_to_checkout. Here is the code that I thought would work but it doesn't
stripe.redirectToCheckout({
lineItems: [
{
price: stripePrice,
quantity: token,
},
],
mode: "payment",
successUrl: someurl
cancelUrl: someurl
}).then(result => {
if (result.error) {
alert(result.error.message);
}
})
CodePudding user response:
Both client-only Checkout and redirectToCheckout
are no longer recommended.
Instead you can use Payment Links (if you need a client-only solution) or you can create Checkout Sessions on your server and send people to the url
on the Checkout Session object.
Regarding your original question, though, redirectToCheckout
will only return a promise if the redirect fails. If the redirect succeeds the JavaScript running on your page will stop running because the browser will have navigated to another page (the Stripe Checkout page), so there's no chance for anything to be returned.
CodePudding user response:
You can't get data out of this function as you are redirected and your script ceases to exist
Stripe wile redirect you back after user checkout and then you have to read the data.