#hen_api

1 messages ยท Page 1 of 1 (latest)

worthy cobaltBOT
#

๐Ÿ‘‹ 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.

high phoenix
#

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

proud scroll
#

Interesting, can you show me your redirect code?

#

And do you have a public test site that I can see this behavior on?

high phoenix
#
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);
  }
}
proud scroll
high phoenix
#

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 :)

proud scroll
#

Glad I can help, that definitely was an interesting one!