techdiagrams.net
← All templates

Payment gateway integration done right

Authorize → capture → settle as an explicit state machine, with idempotent PSP calls, signed webhooks, daily reconciliation and chargebacks as compensating transactions.

Open in editor — free, no login Download JSON
THE BOOKS — MUST AGREE WITH THE PSP'S BOOKScharge · Idempotency-Keyrecord transition firstauthorize / capturesigned eventsapply: captured / failedpost on settlepull daily reportcomparedispute.createdreverse postingOrder Servicewants: charge £49Payment Orchestratorstate machine ownerPayment Stateone row per attemptPSPexternal — Stripe/AdyenWebhook Receiververify signature · dedupeInternal Ledgerdouble-entry postingsSettlement FilesPSP daily reportsReconciliationledger vs PSP · dailyChargeback Handlerdispute → compensationrule of PSP integrations: the HTTP response is an opinion,the webhook is a rumor, the settlement file is the truth.Design for all three to disagree.

What this design does

Integrating a PSP looks like one API call until production teaches you otherwise: webhooks arrive twice or never, captures time out after succeeding, and the money in your database disagrees with the money in your settlement report. This design treats the payment as a state machine with an idempotent transition log, verifies signed webhooks and dedupes them, reconciles daily against the PSP's own files, and models chargebacks as first-class compensating transactions rather than surprises.

The patterns it composes

Import it, attach your own numbers, and verify the design against failures — or read the engineering notes.