#Valma

1 messages · Page 1 of 1 (latest)

charred hillBOT
junior mango
#

Hi there!

#

How can I help?

zealous salmon
#

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})
    })
})
junior mango
#

Yes you can. What are you trying to do?

zealous salmon
#

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

junior mango
#

Sure. Replace this:
stripe.redirectToCheckout({sessionId: payload.id})
By something like:
checkoutURL = payload.url;
And then handle the redirect later.

zealous salmon
#

Alright let me try it

#

Alright its working thanks