#abvfx
1 messages · Page 1 of 1 (latest)
Hello! Can you put that code in this thread please?
`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);
}`
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.
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.
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.
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?
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?
Well, I'm hoping to include something like a unique code in the stripe email reciept summary.
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.
I was thinking of adding the unique code to the description attribute on PaymentIntent (the description is added to the email, correct?). Is there a way to add the unique code to the Charge object? https://stripe.com/docs/receipts?payment-ui=checkout#customizing-receipts
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.
If I disable the automatic email notifications from Stripe, can I then utilize a webhook to instruct Stripe to send the email?
Hm, I suppose you could do that by unsetting and then resetting receipt_email on the Payment Intent: https://stripe.com/docs/api/payment_intents/update#update_payment_intent-receipt_email
Also note that these emails aren't sent in test mode.
You can set it to an empty string and then back to the email address.
In the webhook function, what would invoke the email to be sent?
Just adding the customer email would send?
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.
Ah, I see.