checkoutOs
Rails & gateways

Overview

The gateway registry, what each plugin must implement, and the current implementation status of every supported gateway.

The registry at src/gateways/gateway.registry.ts is the single source of truth for supported gateway names, their required environment keys, and their base URLs. Adding a gateway is a registry entry plus a plugin file — no service or controller changes.

Status

GatewayPluginRegisteredNotes
RazorpayImplementedYesFully working; the reference implementation
PaytmImplementedYesRegistered via createPaytmPlugin(); websiteName needs overriding for production
PayUEmpty fileNoThe registry throws at registration
CashfreeEmpty fileNoThe registry throws at registration

PayU and Cashfree will not start

Their plugin files are empty, and the registry throws an explicit error for both rather than registering undefined. Setting ACTIVE_GATEWAY=payu exits at startup — deliberately, so the failure is a boot error and not a mystery at the first payment.

Selecting the active gateway

One environment variable:

ACTIVE_GATEWAY=razorpay

A Zod superRefine in src/config/env.schema.ts makes that gateway's credentials required at startup. Invalid config exits the process rather than starting a server that will fail on its first request.

Switching is a config change for new payments: no code changes, and all chk_ payment IDs stay stable. Existing payments continue to poll and refund through the gateway that created them, so one deployment has one active gateway.

Switch to Paytm
ACTIVE_GATEWAY=paytm
PAYTM_MERCHANT_ID=your_merchant_id
PAYTM_MERCHANT_KEY=your_merchant_key
PAYTM_WEBHOOK_SECRET=your_webhook_secret
PAYTM_WEBSITE_NAME=DEFAULT

Required environment keys

GatewayKeysDefault base URL
razorpayRAZORPAY_KEY_ID, RAZORPAY_KEY_SECRET, RAZORPAY_WEBHOOK_SECREThttps://api.razorpay.com/v1
paytmPAYTM_MERCHANT_ID, PAYTM_MERCHANT_KEYhttps://securegw.paytm.in
payuPAYU_MERCHANT_KEY, PAYU_MERCHANT_SALT, PAYU_WEBHOOK_SECREThttps://api.payu.in
cashfreeCASHFREE_APP_ID, CASHFREE_SECRET_KEY, CASHFREE_WEBHOOK_SECREThttps://api.cashfree.com

Each gateway also accepts a <GATEWAY>_BASE_URL override — set it to http://localhost:9090 to point at the mock server during development.

How services reach the gateway

Never by importing a gateway folder.

import { getActiveGateway } from '../gateways/gateway.registry';

const gateway = getActiveGateway();
const result = await gateway.createPayment({ /* … */ });

registerGateways() runs once at startup, after config validation, and populates the plugin map. getActiveGateway() throws GatewayUnavailableError if it was never called — a startup contract violation that surfaces on the first request rather than returning undefined.

Two rules that keep the registry decoupled

The registry never imports config/index.ts (circular dependency risk) and never reads process.env directly — it receives the validated env object as a parameter.

What a plugin must implement

Every gateway needs all seven operations:

<gateway>.types.ts
<gateway>.mapper.ts
<gateway>.plugin.ts
src/gateways/gateway.registry.ts — registry entry

The interface covers createPayment, getPaymentStatus, createRefund, getRefundStatus, parseWebhookEvent, getCheckoutAction and healthCheck.

Plus webhook signature verification inside the plugin. See Adding a gateway.

On this page