#hen_api
1 messages ยท Page 1 of 1 (latest)
๐ Welcome to your new thread!
โฒ๏ธ 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.
โฑ๏ธ We close idle threads, which makes them read-only. Once a thread is closed it won't be reopened, but you can always start a new thread if you have another question.
๐ 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/1266134627341566054
๐ Have more to share? Add more details, code, screenshots, videos, etc. below.
application flow:
user selects number of tickets on front-end -> post request to application api endpoint -> api endpoint creates session object with desired products and prices -> redirects the client to the payment url returned from the stripe api -> user then pays on checkout.stripe.com -> user is redirected to succes page
Interesting, can you show me your redirect code?
And do you have a public test site that I can see this behavior on?
const stripe = new Stripe(env.STRIPE_SECRET, { apiVersion: "2022-11-15" });
export async function POST(req: NextRequest) {
const formData = await req.formData();
const numberOfTickets = Number(formData.get("amount"));
const checkNumber = z.number().gt(0);
const validateAmount = checkNumber.safeParse(numberOfTickets);
if (!validateAmount.success) {
return NextResponse.json(
{ message: "Invalid number of tickets submitted" },
{ status: 500 }
);
}
// Create Checkout Sessions from body params.
const session = await stripe.checkout.sessions.create({
line_items: [
{
price: "price-id",
quantity: validateAmount.data,
},
],
mode: "payment",
success_url: `${req.nextUrl.origin}/tickets/?success=true`,
cancel_url: `${req.nextUrl.origin}/tickets/?canceled=true`,
automatic_tax: { enabled: true },
});
if (session.url) {
redirect(session.url);
}
}
https://www.victorplant.live/tickets, and click the first ticket
Ah I think I may have found it, your server is responding with a 307 redirect but a 303 would be better here https://stackoverflow.com/questions/2604530/a-good-way-to-redirect-with-a-post-request
okay amzing, that seems to have worked fine. absolutely no idea why this has stopped working in the last month ๐ญ
thank you so mcuh for your help :)
Glad I can help, that definitely was an interesting one!