Mermaid · drawn by [email protected]

Handling a payment webhook

The AI wrote eleven lines of Mermaid and Mermaid’s own library drew them in the browser. Payment providers resend webhooks, so the handler checks the event id before acting on anything twice.

Mermaid source 11 lines
flowchart TD
  hook([Webhook arrives]) --> sig{Signature valid?}
  sig -- no --> reject[Reply 401, log it]
  sig -- yes --> seen{Seen this event id?}
  seen -- yes --> dup[Reply 200, skip duplicate]
  seen -- no --> kind{Event type}
  kind -- payment.succeeded --> paid[Mark order paid]
  kind -- payment.failed --> retry[Email the customer]
  kind -- anything else --> ignore[Reply 200, ignore]
  classDef focal fill:#f9ece7,stroke:#bf4520,color:#2d3142
  class seen focal