Kkarthik.dev
Back to blogOpen Source

LocalPay: Why I Built an Offline Razorpay API Emulator

2026-11-23 · 3 min read

The problem

Testing a payment integration properly is painful. You need an account and test keys, internet access, a tunnel like ngrok to receive webhooks on localhost, and a lot of patience to trigger the outcomes that actually break apps: a UPI timeout, a bank outage, an authorized-but-not-captured payment, a duplicate webhook.

Most teams end up testing the happy path and hoping. I got tired of that, so I built LocalPay.

What it is

LocalPay is a free, open-source server that behaves like the Razorpay API on your own machine. Your app keeps using the official Razorpay SDK and checkout code — you just point them at http://127.0.0.1:4010.

npx localpay --webhook http://127.0.0.1:3000/webhooks

It never moves money. There is no bank, card network or NPCI behind it — only a deterministic model of Razorpay's public API.

What you can test

  • Orders, payments, captures and refunds, with Razorpay-shaped responses and error envelopes.
  • A test checkout popup where each button is an outcome: pay, insufficient funds, bank down, UPI timeout, authorize only.
  • Signed webhooks delivered straight to localhost with HMAC-SHA256 signatures, retries with backoff, replay, and fault injection: duplicates, out-of-order delivery, delays and missing signatures.
  • API faults such as rate limits and server errors, so your retry logic earns its keep.
  • Time travel: localpay time advance 3d makes refunds, payment-link expiry, subscription renewals and settlements happen in seconds.
  • Late authorization: a UPI payment that fails first and authorizes later, as real UPI sometimes does.

Why determinism matters

Ids are seeded and the clock is injectable, so the same inputs always produce the same outputs. That makes LocalPay usable in snapshot tests and in CI — with no secrets at all. You can even script a whole payment story in YAML (create order → UPI timeout → retry → paid) and assert on the result.

What it is not

LocalPay does not replace Razorpay's own test mode. It is for the fast inner loop and for CI. Before going live, you should still run your integration against the real test mode.

Stack

TypeScript on Node.js 22 in a pnpm monorepo: a Razorpay-compatible REST API, an engine of state machines and an event log, a webhook dispatcher, a clock, and a dashboard — tested with Vitest and Playwright, published on npm, Apache-2.0 licensed.

The code is on GitHub.