#lennard_checkout-success-page

1 messages ยท Page 1 of 1 (latest)

karmic bluffBOT
#

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

๐Ÿ“ Have more to share? Add more details, code, screenshots, videos, etc. below.

scarlet breachBOT
shell lagoon
#

Oops, appears the code isn't right...

#

Here's the code:

#
import Stripe from 'stripe';
const stripe = new Stripe('xxx');

export async function POST() {
    const session = await stripe.checkout.sessions.create({
        line_items: [
          {
            // Provide the exact Price ID (for example, pr_1234) of the product you want to sell
            price: 'price_1OxZ1fHpFc1RmriHJn6XwkMJ',
            quantity: 1,
          },
        ],
        mode: 'payment',
        success_url: `http://localhost:3000/api/stripe/sucess?session_id={CHECKOUT_SESSION_ID}`,
        cancel_url: `http://localhost:3000/api/stripe/?success=true`,
        automatic_tax: {enabled: true},
    });

    console.log("๐Ÿš€ ~ POST ~ session.url:", session.url)

    return Response.json({
        url: session.url
    });
}
tame mountain
#

Sorry what about the URL or webhook are you saking about here?

shell lagoon
#

Is it secure for me to just use the sucess_url like above and parse the checkout session there, server side, and render a HTML sucess page? Or am I advised to use a webhook?

#

Because to me it looks like I do not need the webhook and can do all in sucesss, just wanted to check that to make sure I don't do anything wrong.

tame mountain
#

It depends on what you want to do with your Success page

shell lagoon
tame mountain
#

In that case you can use the success_url like you have shown here

#

Just be aware that, if your customer uses asynchronous payment methods, you may not know the outcome of the payment at the time they visit the success URL

shell lagoon
#

What would be examples of that? Are these common?

tame mountain
#

Any asynchonrous payment method. For instance ACH with a US bank account can take 3 days to complete

shell lagoon
#

Oh okay, I will go with the webhook then instead. Thanks for clarifying!

tame mountain
#

Sure thing! Happy to help ๐Ÿ™‚

shell lagoon
#

Hope you have a great day

tame mountain
#

You too ๐Ÿ‘‹

shell lagoon
#

Ty!