Developer ResourcesPayment
Adding a New Gateway
Order-centric checklist for introducing a new payment gateway.
Adding a New Gateway
Audience: Backend developers Scope: Registry, gateway implementation, env config, validation
Checklist
- Add gateway name to
PAYMENT_GATEWAYSinpackages/db/src/schema/payment.ts. - Implement gateway adapter in
apps/api/src/modules/payment/gateways/. - Register adapter in
PaymentModuleproviders. - Register adapter in
PaymentServiceconstructor map. - Add env keys to validation + sample env.
- Verify order checkout/buy-now initiation works with new gateway.
Minimal Adapter Template
@Injectable()
export class NewGateway implements PaymentGateway {
readonly name = "new_gateway";
async initiate(params: InitiatePaymentParams): Promise<InitiatePaymentResult> {
return {
gatewayTransactionId: `${params.referenceId}-${Date.now()}`,
initiationType: "redirect",
redirectUrl: "https://gateway.example.com/pay",
gatewayPayload: {
referenceId: String(params.referenceId),
amount: String(params.amountNpr),
},
};
}
async verify(params: VerifyPaymentParams): Promise<VerifyPaymentResult> {
return {
success: true,
amountNpr: 100,
};
}
}Module Registration
- Add provider in
payment.module.ts. - Inject and
this.gateways.set(adapter.name, adapter)inpayment.service.ts.
Env & Validation
- Add required gateway env vars to
apps/api/src/config/env.validation.ts. - Add examples to
apps/api/sample.env.
Verification
- API build passes.
- New gateway appears in user-facing allowed gateway list (excluding
admin_grant). - Initiation returns valid
initiationType,redirectUrl, andgatewayPayload. - Redirect callback verification updates payment status correctly.