#anoosh_checkout-error
1 messages Β· Page 1 of 1 (latest)
π Welcome to your new thread!
β±οΈ We automatically close idle threads, which makes them read-only. Make sure you stick around to chat in realtime!
π This thread will always be available, even after it's closed. You can find it again using Discord's search, or you can save this link: https://discord.com/channels/841573134531821608/1212070460934852708
π Have more to share? You can add more detail below, including code, screenshots, videos, etc.
β²οΈ We'll be here soon! Typically we respond in a few minutes, but sometimes we might take a bit longer if the server is busy or if you have a particularly tricky question. Thank you for your patience!
Hey there, thank you in advance for trying to help me π
AS I said in the ticket, everything works like a charm in local development, but in a live-test context I'm having trouble reaching the Checkout Page.
Let me know whch further infos would be useful and I'll provide them π
Hi π can you share a code snippet of how you're creating those Checkout Sessions, as well as the ID of a Checkout Session where you saw this behavior (that should have a cs_test_ prefix) if you have one available?
Hi Toby, here's my createSession method :
export const createSession = async (data) => {
const { sessions, title, price, userId } = data;
const user = await prisma.users.findUnique({
where: {
id: userId,
},
});
if (!user) throw new Error("Utilisateur non trouvΓ©");
const userName = `${user.first_name} ${user.last_name}`;
const priceInCents = price * 100;
const session = await stripe.checkout.sessions.create({
payment_method_types: ['card'],
line_items: [{
price_data: {
currency: 'eur',
product_data: {
name: 'Pack de sessions pour le groupe : ' + title,
},
unit_amount: priceInCents,
},
quantity: 1
}],
mode: 'payment',
success_url: `${process.env.FRONTEND_URL}/groupes/paiement/paiement-accepte`,
cancel_url: `${process.env.FRONTEND_URL}/groupes/paiement/paiement-refuse`,
});
// LOG TRANSACTION
await prisma.transactions.create({
data: {
userId: userId,
userName: userName,
groupName: title,
sessions: JSON.stringify(sessions),
price: price,
paymentStatus: 'Pending', // UPDATE WITH WEBHOOK LATER
paymentDate: new Date(),
},
});
return { sessionId: session.id };
};
And here's a Checkout Session ID :
cs_test_a1bSd2TTCTgl6fu7nzUVrl3qxDlPMOQl6ZuLDGm8urD6xvQXWc7qgbMdQa
Thank you, taking a look!
Hm, it doesn't look like the Checkout Session was completed, nor does it appear to be expired.
I'm also not seeing an error when accessing the URL for that session.
Are you navigating directly to the URL provided after creating the Checkout Session? Or are you trying to reach it another way?
Client side I use a service to send the request to my API, and I'm using this snippet to redirect users to the Checkout Page :
if (response.ok) {
const result = await stripe!.redirectToCheckout({
sessionId: session.sessionId,
});
Hm, the only thing coming to mind is if you're initializing stripe.js with a publishable key from another account (though I do also see we've flagged that method as being deprecated).
Would it work for your flow to have your backend respond with a redirect directly to the Checkout Session's URL, rather than letting the frontend do the redirect?
I'll try that and let you know in a few minutes, thank you π
Sounds good
anoosh_checkout-error
So I couldn't redirect properly via my backend, but after a few tries I could get to the Checkout page by changing the redirection method from :
if (response.ok) {
const result = await stripe!.redirectToCheckout({
sessionId: session.sessionId,
});
to :
if (response.ok) {
window.location.href = data.url;
}
Thank you for your help toby, pointing out at the redirection helped me a lot !