Developer ResourcesPayment
Adding a New Gateway
Checklist to add a gateway without breaking existing order/payment queue contracts.
Adding a New Gateway
Audience: Backend developers Scope: Enum, adapter, registration, env config, tests, docs
Required Steps
- Add gateway name to
PAYMENT_GATEWAYSinpackages/db/src/schema/payment.ts. - Create gateway adapter under
apps/api/src/modules/payment/gateways/. - Register adapter in
PaymentModuleproviders. - Register adapter in
PaymentServiceconstructor map. - Add env keys to
apps/api/src/config/env.validation.tsandapps/api/sample.env. - Add gateway tests:
- gateway adapter unit tests
- payment service registration/flow tests
- order integration tests for checkout/buy-now initiation payload expectations
- Update payment fumadocs pages and
payment/meta.jsonnavigation.
Keep Existing Contracts Stable
When adding gateways, do not change these contracts:
- payment events:
payment.completed,payment.failed - order jobs:
order.payment_success,order.payment_failed - checkout/buy-now response shape:
paymentId,initiationType,redirectUrl,gatewayPayload
Webhook-Capable Gateway Guidance
If the gateway provides signed webhooks (for example Stripe):
- add public webhook controller endpoint
- verify signature using raw request body
- process webhook idempotently in
PaymentService - retain redirect reconciliation endpoints for browser UX
Definition of Done
- Gateway is selectable in checkout/buy-now DTO validation.
- Gateway initiate flow returns valid redirect/form payload.
- Payment status finalization is idempotent.
- Existing legacy gateways continue to function.
- Payment and order test suites cover the new path.