#abvfx

1 messages · Page 1 of 1 (latest)

crisp crestBOT
astral crag
#

Hello! Can you put that code in this thread please?

uncut egret
#

`async function handleRequest(request, env, ctx) {
const stripe = Stripe(env.STRIPE_API_KEY, {
httpClient: Stripe.createFetchHttpClient()
});
const session = await stripe.checkout.sessions.create({
line_items: [
{
price: 'price',
quantity: 1,
},
],
payment_intent_data: {
description: ' | Digital Code',
},
mode: 'payment',

    success_url: `${DOMAIN}/success.html`,
    cancel_url: `${DOMAIN}/cancel.html`,
});

return Response.redirect(session.url, 303);

}`

astral crag
#

Thanks!

#

With Checkout it's important to use webhooks to perform fulfillment, otherwise people can pay you without your knowledge and they won't get what they paid for.

#

You can suppliment this with a custom success page that retrieves the Checkout Session and displays information based on that, or even performs fulfillment, but not everyone who pays successfully will land on your success page.

#

In other words, your fulfillment code should always be triggered using webhooks, and can also optionally be triggered by people landing on your success page after looking up the Checkout Session.

uncut egret
#

Ok, can a webhook change the stripe receipt email?

#

I need to add a unique access code that is generated after a successful payment. The code should be part of the stripe receipt.

astral crag
#

No, you can't alter Stripe receipts.

#

If you need custom receipts you should disable the Stripe receipts and send your own receipts triggered by webhooks.

uncut egret
#

Ok, one more thing. If I wanted to run a function after a successful payment (that does not fulfill the order), could the call go somewhere in the code above?

astral crag
#

No. The customer is redirected to the Stripe Checkout page, at which point your code is no longer running.

#

When they complete payment in Checkout we generate events that you can listen for with webhooks, and use those to trigger code. We also redirect them to the success_url you specify, where you can do whatever you want, but they may pay successfully and then immediately close the tab or lose their connection before your success page loads, so you can't rely on that.

#

What do you want the function to do?

uncut egret
#

Well, I'm hoping to include something like a unique code in the stripe email reciept summary.

astral crag
#

That's not possible with Checkout.

#

If you want to generate/set the code only after successful payment that's not possible with Stripe's receipts at all.

#

You need to do custom receipts on your end for that.

uncut egret
astral crag
#

No. The receipt is generated sent at the time the payment is made. There is no window of opportunity for you to alter the receipt after the payment but before it's sent.

uncut egret
#

If I disable the automatic email notifications from Stripe, can I then utilize a webhook to instruct Stripe to send the email?

astral crag
#

Also note that these emails aren't sent in test mode.

uncut egret
#

Yes, thanks.

#

I'll have to see if the unsetting receipt_email works.

astral crag
#

You can set it to an empty string and then back to the email address.

uncut egret
#

In the webhook function, what would invoke the email to be sent?

#

Just adding the customer email would send?

astral crag
#

The second API request to Stripe, when you set receipt_email back to the email address.

#

So you get the webhook, you make an API request to unset the receipt_email, then you make a second request to set it again, and that triggers the email.

uncut egret
#

Ah, I see.