Executive summary
The cleanest integration is one where your core business rules never depend on a vendor SDK. You isolate vendors behind adapters, run side effects via queues, and store every external interaction as an auditable record.
The clean architecture approach
Think in layers. Your “Domain” and “Application” layers remain stable. Gateways (payments), SMS providers, and accounting systems live in Infrastructure adapters.
No controller should call a payment SDK directly. Controllers call a use-case service; the use-case calls interfaces; adapters implement those interfaces.
A production-grade integration flow
Payments and SMS are “side effects”. Treat them as asynchronous jobs whenever possible. Accounting sync should be consistent and auditable, not “best effort”.
- Webhooks are verified and idempotent (safe retries).
- Accounting and SMS run via queues (no UI slowdown).
- Every external call is recorded (audit trail).
Idempotency: the #1 reliability tool
In payments and webhooks, requests can be repeated. Idempotency ensures repeated events don’t double-charge or double-post to accounting.
- Payment intent creation
- Webhook processing
- Accounting posting
- SMS sending (avoid duplicates)
- Use an idempotency key = invoice_id + action
- Store “processed events” in a table
- Return early if already processed
- Make posting jobs safe to retry
Common anti-patterns to avoid
What to store for audit & debugging
You don’t need to store everything forever, but you do need enough to explain every external side effect.
| Record | Fields | Why |
|---|---|---|
| payment_attempts | invoice_id, idempotency_key, request, response, status | Trace payment lifecycle. |
| webhook_events | provider, event_id, payload_hash, received_at, processed_at | Idempotency and replay. |
| accounting_posts | invoice_id, journal_ref, request, response, status, retries | Audit and reconciliation. |
| sms_messages | to, template, payload, provider_msg_id, status | Delivery tracking. |
Need help implementing this?
ReanOrt can design the integration architecture, implement reliable webhooks and queues, and deliver audit-ready finance flows.