The webhook that charges twice
A two-engineer SaaS team adds Stripe webhook handling the night before launch. The founder writes it, tests the happy path, and merges.
if (event.type === "invoice.paid") {
await db.credit.create({
data: { accountId, amount: invoice.amount_paid },
});
}Stripe can deliver the same event more than once. This handler adds credit on every delivery, so a retried webhook doubles the customer's balance. Store event.id and skip events you've already processed.
Result: A duplicate-credit bug that would have surfaced as a billing dispute is fixed before launch, in a two-line change.