A Stripe integration can pass every test-mode check and still go wrong with real customers. The reason is simple: in production Stripe may send the same event more than once, in any order, and it keeps retrying when your endpoint is slow or down. This short shows a basic handler and a hardened one getting the same traffic:
If you only change four things in your handler this week, make it these:
Verify first, using the raw body. Check the Stripe-Signature header against the exact bytes Stripe sent. Parsing the JSON and re-serialising it breaks the signature.
Remember every event you've handled. Insert event.id into a table with a unique key before doing any work. If the insert fails because the id already exists, it's a repeat delivery: return 200 and stop.
Answer fast, work later. Save the event and return 200 within a second or two, then let a background job update the database and send emails.…