#Valma
1 messages · Page 1 of 1 (latest)
Hi, I was wondering if it was possible to save the url of the created session in a variable instead of redirecting to it ?
const stripe = Stripe("Public Key")
const button = document.getElementsByClassName("order-button")[0]
button.addEventListener("click", (e) => {
e.preventDefault();
fetch("../server/checkout.php", {
method: "POST",
headers: {
"Content-Type" : "application/json"
},
body: JSON.stringify({})
}).then(res => res.json())
.then(payload => {
stripe.redirectToCheckout({sessionId: payload.id})
})
})
Yes you can. What are you trying to do?
As you see here for exemple, when I press the checkout button I get redirected to the session created but I instead want to get the url to then redirect manually
Did you understand ?
Basically I just need to get the url without getting redirected
Sure. Replace this:
stripe.redirectToCheckout({sessionId: payload.id})
By something like:
checkoutURL = payload.url;
And then handle the redirect later.