Payments that can be retried safely
Assume every payment event will arrive twice, late, or not at all. Then build the flow that survives it.
Payment integrations fail in boring, predictable ways. Webhooks arrive twice. A webhook never arrives. A client sends an amount it should not be allowed to choose. A request times out after the provider has already charged the card.
The MBS mobile API handles school fees through Paystack, so the flow has to assume all of those things at once.
The server owns the amount
The app never submits a price. It sends the invoice or payment reference, and the server calculates the total from its own records. Amounts are stored as integer kobo. That removes a whole class of tampering bugs before they can exist.
Verify, then verify again
Paystack webhooks are verified with HMAC-SHA512 and a timing-safe comparison. A charge.success event is then re-verified with Paystack by reference before the payment is marked successful. Duplicate events return a successful duplicate response instead of crediting twice.
A reconciliation job re-checks PENDING payments older than five minutes every ten minutes. If a webhook is missed, the payment does not stay pending forever.
- Store amounts in integer kobo and calculate them server-side.
- Verify webhook signatures before parsing business logic.
- Re-verify the transaction with the provider by reference.
- Deduplicate events with idempotency keys.
- Reconcile pending payments on a schedule.
