Menu

1 / 2

Stripe fulfilment from two paths: three idempotency keys and a test for a hanging email provider

DEV Community: postgres·Emmanuel·3 days ago
#4b7xagh9
#devtopostgresql#devto#dev#event#email
Reading 0:00
15s threshold

After a Stripe Checkout payment, two things try to give the buyer their purchase: Stripe's webhook, and the browser, which Stripe redirects back to your site. They race. Either can arrive first, either can arrive twice, and either can fail halfway. I didn't want the buyer to wait for the webhook alone.

This is how our shop handles it: one function, called by both, with three separate "only once" guards. It's an exam practice site, so "the purchase" is access to practice exams, but the pattern holds for anything you deliver after payment.

The two callers

The webhook verifies the signature, then hands the event to a handler. If anything throws, it answers 500 and Stripe retries:

try { const outcome = await handleStripeEvent ( db , event , { email : getEmailSender ( ) , baseUrl : appUrl ( ) } ) ; return Response . json ( { received : true , outcome } ) ; } catch ( err ) { console .…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.