Article
Integrating payment gateways, the calm way
Midtrans, Xendit, Flywire — every gateway is different, but the integration shape that keeps you sane is always the same.
After integrating a handful of payment gateways, you stop seeing the differences and start seeing the pattern. Every provider is a variation on the same three moving parts.
1. A request you control
You build the charge request, you sign it, you send it. Keep this layer thin and provider-specific, and normalise the response into your own shape immediately.
2. A webhook you do not control
The webhook is the source of truth for whether money actually moved. Treat it as hostile input:
- Verify the signature before you trust a single field.
- Look the transaction up by your reference, not theirs.
- Make the handler idempotent — providers retry aggressively.
3. A reconciliation you will be glad you built
Webhooks get lost. Networks fail. A nightly reconciliation job that compares your records against the provider's ledger turns "we think we got paid" into "we know we got paid."
Wrap all three behind a single interface in your application, and swapping or adding a gateway becomes an afternoon instead of a rewrite.