Razorpay
The reference plugin — redirect checkout, raw-body HMAC webhooks, and the two-ID model.
Razorpay is the fully implemented reference plugin (src/gateways/razorpay/razorpay.plugin.ts)
and the one to read when writing a new one.
Configuration
ACTIVE_GATEWAY=razorpay
RAZORPAY_KEY_ID=rzp_live_xxxxxxxxxxxx
RAZORPAY_KEY_SECRET=xxxxxxxxxxxxxxxxxxxxxxxx
RAZORPAY_WEBHOOK_SECRET=xxxxxxxxxxxxxxxx
# Optional — point at the mock server in development
RAZORPAY_BASE_URL=http://localhost:9090Default base URL is https://api.razorpay.com/v1.
Checkout
GET /checkout/:chkId serves an HTML page carrying the Razorpay JS SDK. The user completes
the payment on Razorpay's hosted checkout; your server never handles card data.
The two IDs
| checkoutOs field | Razorpay value | Set when |
|---|---|---|
gatewayOrderId | order_XXXX | Payment creation |
gatewayPaymentId | pay_XXXX | The payment.captured webhook arrives |
gatewayPaymentId is an empty string until then, and a refund requires it — so a webhook must
precede any refund. Attempting one earlier returns REFUND_NOT_ALLOWED.
Webhooks
Configure the endpoint in the Razorpay dashboard:
https://api.checkoutos.in/webhooks/razorpayVerification is HMAC-SHA256 over the raw request body, compared against the
X-Razorpay-Signature header.
Body-parsing order is load-sensitive
src/app.ts mounts express.raw() for /webhooks/razorpay before express.json(). The
signature is computed over bytes, so a JSON round-trip invalidates it. Reordering that
middleware silently breaks every webhook.
The mock server
npm run mock:gateway starts an MSW server on :9090 (override with MOCK_PORT).
- Mocks Razorpay orders, order lookup and refunds, plus the Paytm transaction endpoints.
- Deterministic for order IDs and
created_at, so tests do not depend on wall-clock time. - Basic Auth is validated — wrong or missing credentials return
401.
RAZORPAY_KEY_ID=rzp_test_mockKeyId00001
RAZORPAY_KEY_SECRET=mockSecret00001To add another gateway's mocks, create mocks/gateways/<gateway>/handlers.ts and spread it
into mocks/server.ts.