Independent QA Automation Project

Razorpay Payment Gateway QA & Automation

Testing a payment system beyond the happy path.

An independent QA engineering project built around a real Razorpay Test Mode payment — not just to make checkout work, but to test what happens when it doesn't. I verified the payment lifecycle, probed for tampered signatures and replayed requests, and pushed webhook handling and order state until two defects surfaced, both in the demo app I built as the test target. Both were investigated, fixed, and covered by regression tests.

Razorpay Payment Gateway QA & Automation: project coverCover for Razorpay Payment Gateway QA & Automation: 37 test definitions (34 run in CI, 3 live-gateway). Flow covered by the suite: create an order, verify the payment signature, receive a webhook, check its HMAC over the raw request body, update the order state. Built with Playwright, Node.js, Express, SQLite.PAYMENT WORKFLOW TESTINGRazorpayPayment GatewayQA & AutomationPlaywright · Node.js · Express · SQLite37test definitions34 run in CI, 3 live-gateway1Ordercreate order2Verifypay signature3Webhookevent ID4HMACraw body5StateSQLite stateTwo high-severity defects found, fixed and regression-testedsayedasif.comRazorpay Payment Gateway QA & Automation: project coverCover for Razorpay Payment Gateway QA & Automation: 37 test definitions (34 run in CI, 3 live-gateway). Flow covered by the suite: create an order, verify the payment signature, receive a webhook, check its HMAC over the raw request body, update the order state. Built with Playwright, Node.js, Express, SQLite.RazorpayPayment GatewayQA & Automation37test definitions34 run in CI, 3 live-gatewayPlaywright · Node.js · Express · SQLiteOrderVerifyWebhookHMACState
37
Automated Tests
2
High-Severity Defects in My Own App, Fixed
34
CI-Safe Tests
1
Real Test Mode Payment Completed

01 Context

Why I Built This

Most payment-testing demos stop at the same place: the checkout succeeds, the order updates, done. I wanted something small enough to fully own, so I could test it the way a payment actually gets used, not the way a demo gets shown.

That meant asking the questions a happy-path run never answers. What if the same verification request gets replayed? What if the amount is manipulated between the client and the server? What if a signature is invalid, or the payload has been tampered with after signing? What if the same webhook event arrives twice, or a state transition happens in an order the application didn't expect? What if a third-party SDK throws an error shape my code didn't plan for?

A successful checkout doesn't answer any of that. It just proves the happy path is happy.

02 Problem

The Testing Problem

A payment crosses several boundaries before it's actually done: the checkout UI, the application, the payment gateway, an asynchronous webhook, and whatever local record represents the order's state. Each boundary can disagree with the others — a UI success doesn't guarantee the server verified the payment correctly, and a verified payment doesn't guarantee a webhook, if one ever arrives, won't try to reapply the same event a second time.

UI → Application → Payment Gateway → Webhook → Order State

The job wasn't to make the payment work. It was to find out whether the system under test stayed correct when payment behavior became unreliable — because eventually, it will.

03 System under test

Payment / System Flow

Two paths can influence the same payment state. They need to remain consistent.

Two paths update the same order state Client verification path: Checkout to Application to Payment Verification. Webhook path: Razorpay to Webhook Handler. Both write to the order state stored in SQLite. Client verification path Checkout Application Payment Verification Webhook path Razorpay Webhook Handler Order stateSQLite Two paths update the same order state Client verification path: Checkout, Application, Payment Verification. Webhook path: Razorpay, Webhook Handler. Both write to the order state stored in SQLite. Client path Webhook path Checkout Application PaymentVerification Razorpay WebhookHandler Order stateSQLite

The client-verification path confirms the payment the moment Checkout completes. The webhook path is supposed to confirm it independently, asynchronously, whenever Razorpay's event arrives. Both write to the same order state — which means either path repeating itself, arriving late, or arriving out of order has to leave the record correct, not just whichever path gets there first.

04 Approach

How I Tested It

Rather than one long checklist, the suite is organized around what actually needed proving.

Functional Testing

Order creation, a real Test Mode payment through Razorpay Checkout, a real cancel-and-retry session, and refund request validation — the baseline every payment flow has to get right before anything else matters. The Checkout sessions were driven with Playwright and documented in the repository's Phase 3.3 report, but they are not committed as repeatable tests.

API Testing

Request and response validation across the order and configuration endpoints, payment verification behavior, and error handling that never leaks raw SDK internals back to the client.

Security Testing

Signature verification under tampering, amount integrity — the server trusts its own records, not client-supplied amounts — and replay protection on the verification endpoint.

Webhook Testing

Raw-body handling ahead of any parsing middleware, HMAC validation over that untouched body, and idempotency so a duplicated delivery can't be applied twice.

State & Persistence Testing

The order state machine rejects invalid transitions and treats duplicate ones as safe no-ops. The repository's tests exercise created → paid and idempotent replay; failed, out-of-order and refund transitions are implemented but not directly tested.

UI Testing

The committed Playwright UI tests load the checkout page in Chromium and check the page content, the official Checkout script source, the Test Mode indicator and that no secrets are exposed. Separately, Playwright drove the real hosted Checkout during Phase 3.3 (a successful payment, a real Razorpay decline, and cancel/retry); that is documented in the repository but is not part of the 37 committed tests.

CI Testing

34 of the 37 tests deliberately isolated from real credentials and live gateway state, so the suite can run unattended on every push.

05 Scenarios

Payment Scenarios, Mapped to the Tests That Prove Them

These are the payment failure scenarios I check first on any gateway integration. For each one, this is what the repository does and does not prove, with the test excerpt and a link to the exact lines on GitHub.

Duplicate payment attempts

What I verify: a customer who clicks Pay twice, or a client that retries, cannot create a second charge or corrupt the order.

Live gateway only REPLAY-001 verifies the same real captured payment twice and checks the order stays paid with the same payment ID. It is tagged @razorpay-live: it needs the original Test Mode payment, so it is not one of the 34 CI tests. A double-click on the Pay button in the browser is not tested.

const first = await request.post('/api/payments/verify', {
  data: { orderId: realOrderId, paymentId: realPaymentId, signature: validSignature },
});
const second = await request.post('/api/payments/verify', {
  data: { orderId: realOrderId, paymentId: realPaymentId, signature: validSignature },
});

expect(first.status()).toBe(200);
expect(second.status()).toBe(200);
// ...
const orderState = await (await request.get(`/api/payments/orders/${realOrderId}`)).json();
expect(orderState.status).toBe('paid');
expect(orderState.paymentId).toBe(realPaymentId);
REPLAY-001. tests/security/signature-verification.spec.js, lines 61–69, 77–79 @ da9e7a2 (opens in a new tab)

3D Secure and redirect flows

What I verify: a customer who authenticates, cancels, abandons or lets the session expire, then returns to the app, ends with the correct final payment status.

Not tested here No committed test covers authentication or redirect paths. The Phase 3.3 report documents Playwright driving the hosted Checkout through one successful payment, a real decline and a cancel-and-retry; those sessions are not repeatable tests. Cancelled authorisations, expired sessions and interrupted redirects are scenarios I would design next, not results I can show.

Webhook retries

What I verify: when a gateway redelivers an event because the first attempt timed out, the app acknowledges it without applying it twice.

Runs in CI WEB-005 sends the same event ID twice and expects the second response to say it was already processed. The redelivery is simulated by the test; no retry sent by Razorpay itself was observed.

// Send the SAME webhook again (same event ID)
const secondResponse = await request.post('/api/webhooks/razorpay', {
  data: payload,
  headers,
});

expect(secondResponse.status()).toBe(200);
const secondBody = await secondResponse.json();
expect(secondBody.success).toBe(true);
// Verify it indicates already processed
expect(secondBody.message).toContain('already processed');
WEB-005, second delivery of the same event. tests/security/webhook-validation.spec.js, lines 147–157 @ da9e7a2 (opens in a new tab)

Idempotency

What I verify: a duplicate event changes nothing: same order status, same payment ID, no repeated transition.

Runs in CI WEB-FIX-004 replays a signed event against a freshly seeded order and asserts the order is still paid with the original payment ID. WEB-006 checks that different event IDs are processed independently.

const first = await request.post('/api/webhooks/razorpay', { data: payload, headers });
expect(first.status()).toBe(200);
expect((await first.json()).message).toContain('Webhook received and validated');

const second = await request.post('/api/webhooks/razorpay', { data: payload, headers });
expect(second.status()).toBe(200);
expect((await second.json()).message).toContain('already processed');
// ...
// Idempotent replay must not have re-applied or duplicated the transition.
const order = await (await request.get(`/api/payments/orders/${orderId}`)).json();
expect(order.status).toBe('paid');
expect(order.paymentId).toBe(paymentId);
WEB-FIX-004. tests/security/webhook-validation.spec.js, lines 350–356, 358–361 @ da9e7a2 (opens in a new tab)

HMAC-signed webhooks

What I verify: the signature is computed over the exact raw bytes received, and anything unsigned, mis-signed or modified is rejected.

Runs in CI WEB-002, WEB-003, WEB-007, WEB-FIX-001, WEB-FIX-002 and WEB-FIX-003 cover invalid, missing, tampered and valid signatures. They exist because of defect DEF-002, written up on the Evidence page. The webhook handler's check:

function validateWebhookSignature(rawBody, signature) {
  if (!config.razorpay.webhookSecret) {
    console.warn('⚠️  Webhook secret not configured. Validation skipped.');
    return false;
  }

  const expectedSignature = crypto
    .createHmac('sha256', config.razorpay.webhookSecret)
    .update(rawBody)
    .digest('hex');

  return expectedSignature === signature;
}
The check the webhook tests exercise. src/routes/webhooks.js, lines 34–46 @ da9e7a2 (opens in a new tab)

Refund state transitions

What I verify: a refund moves an order from paid to refunded only, never from an unpaid state, and a repeated refund event is harmless.

Partly tested The transition rules are implemented in src/stateMachine.js (below) but no test exercises paid → refunded, and no successful refund was completed against Razorpay. What is tested is refund error handling: REF-ERR-001 and REF-ERR-002 (CI) prove a rejected refund returns a controlled error and the server stays up.

const ALLOWED_TRANSITIONS = {
  [STATES.CREATED]: [STATES.AUTHORIZED, STATES.PAID, STATES.FAILED],
  [STATES.AUTHORIZED]: [STATES.PAID, STATES.FAILED],
  [STATES.PAID]: [STATES.REFUNDED],
  [STATES.FAILED]: [],
  [STATES.REFUNDED]: [],
};
The allowed order transitions. Same-state repeats are treated as no-ops elsewhere in the file. src/stateMachine.js, lines 14–20 @ da9e7a2 (opens in a new tab)
test('REF-ERR-002: the server remains available immediately after a refund error', async ({ request }) => {
  // Trigger the same class of Razorpay-rejected refund as REF-ERR-001.
  await request.post('/api/refunds/create', {
    data: { paymentId: 'pay_another_nonexistent_id_67890' },
  });
  // ...
  const health = await request.get('/health');
  expect(health.status()).toBe(200);
REF-ERR-002, condensed: the regression assertion for DEF-001 is that the server is still alive after a rejected refund. tests/security/refund-error-handling.spec.js, lines 34–38, 42–43 @ da9e7a2 (opens in a new tab)

For the method behind these checks, with more test code, read How to Test a Payment Gateway with Playwright.

06 Regression test

The HMAC webhook test, from the repository

One of the four regression tests added for DEF-002. It signs the original payload, changes the amount, and checks the webhook is rejected and the order is untouched.

test('WEB-FIX-002: a modified payload with the original signature is rejected', async ({ request }) => {
  // ...
  const signature = generateWebhookSignature(payload); // signed over the ORIGINAL amount
  const modifiedPayload = shapedPayload(orderId, paymentId, { amount: 1 }); // same shape, different amount
    // ...
    data: modifiedPayload,
  // ...
  expect(response.status()).toBe(401);
  // ...
  // The rejected webhook must not have touched the order.
  const order = await (await request.get(`/api/payments/orders/${orderId}`)).json();
  expect(order.status).toBe('created');
});
WEB-FIX-002, condensed. tests/security/webhook-validation.spec.js, lines 288, 295–296, 299, 307, 311–314 @ da9e7a2 (opens in a new tab)

07 Defects

Two failures I didn't expect to find

Both were defects in the demo app I built as the test target, found by the automation. They are bugs in my own code, not in Razorpay's product.

Refund Error Handling — Server Crash

ID
DEF-001
Severity
High
Status
Fixed
Component
Refund route
Risk

A payment gateway rejection should never take the application down with it.

What I observed

A refund request Razorpay rejected didn't fail cleanly — it crashed the server process.

Investigation

I reproduced the crash with a refund I knew Test Mode would reject, then looked at the actual shape of the thrown error instead of trusting the SDK's documented format. The refund route's catch block was calling .message.includes() on it, assuming a .message string the way a standard JavaScript Error exposes one.

Root cause

The SDK error didn't populate .message the way the handler assumed. Calling .includes() on undefined threw a second, unhandled exception inside the error handler itself — and that's what actually took the process down. The information the handler needed was available on error.statusCode.

Fix

Rewrote the handler to read error.statusCode and return a sanitized, controlled error response instead of trusting SDK internals it hadn't verified.

Regression

REF-ERR-001 and REF-ERR-002 now assert the server stays alive and returns a proper error response whenever Razorpay rejects a refund.

Result

The same rejected refund that used to crash the process now returns a controlled response, and the server keeps running.

Webhook Signature Validation — Raw Body Failure

ID
DEF-002
Severity
High
Status
Fixed
Component
Webhook route
Risk

A webhook signature has to be calculated against the exact bytes Razorpay signed — anything that touches those bytes first breaks verification silently.

What I observed

Correctly signed webhook requests were being rejected as invalid, every time.

Investigation

The cryptographic logic itself was correct — I confirmed that by hand-building signatures with the right secret and watching them fail too. That pointed away from the HMAC comparison and toward what the route was actually receiving.

Root cause

Express's global express.json() middleware was mounted ahead of the webhook route. It consumed and parsed the body first, so the route's own express.raw() received an already-parsed object instead of a Buffer. The handler's req.body.toString('utf-8') then returned the string "[object Object]", and the HMAC was computed over that instead of the real payload. The signature check was correct; it was checking the wrong bytes.

Fix

Mounted the webhook route before the global JSON parser, so it receives the untouched raw body before any middleware can transform it.

Regression

Deterministic coverage across a valid signature, an invalid signature, a tampered payload, and a duplicate event ID — each confirming the handler now sees and verifies the exact bytes it's supposed to.

Result

The four signature scenarios passed in the last recorded CI run (14 Sep 2026, commit da9e7a2). That is a historical result, not a guarantee for future runs.

What this doesn't prove: a real Razorpay-originated webhook was never observed arriving at the running application. That's a separate, honest limitation, covered below — not something this fix papers over.

08 State machine

The State Machine

State-transition testing, not just architecture. The order state machine has five states, and the transitions between them are validated explicitly rather than left to application logic scattered across routes.

Order state machine created moves to authorized, paid or failed. authorized moves to paid or failed. paid moves to refunded. refunded and failed are terminal. created authorized paid refunded created to paid directly failed Order state machine created moves to authorized, paid or failed. authorized moves to paid or failed. paid moves to refunded. refunded and failed are terminal. created authorized paid refunded failed created also moves directly to paid or failed
Transitions as defined in src/stateMachine.js. Terminal states are shaded.

Invalid transitions are rejected — paid can't move back to authorized, and neither failed nor refunded transition anywhere else; they're terminal. Repeating the same transition is treated as a safe no-op, not an error — which is exactly what a webhook redelivering the same event needs to be able to rely on, and exactly what stops a late or out-of-order event from incorrectly reapplying state.

09 Test counts

37 Tests, But the Number Is Only Useful With Context

37
Total Tests
34
CI-Safe
3
Razorpay-Live

The 34-test suite is deliberately isolated from credentials and live gateway state, so it can run unattended on every push and pull request. The remaining 3 — SIG-001, REPLAY-001, UI-002 — need genuine Razorpay Test Mode conditions and are run separately, on purpose. Mixing them into CI would mean either committing real credentials or making the pipeline flaky against a service it doesn't control. That's a test-strategy decision, not a shortcut.

10 CI

CI / Reproducibility

Regression confidence, not a deployment feature. The CI-safe suite runs automatically through the "Playwright CI" GitHub Actions workflow — Node 24, Chromium, npm ci, placeholder Razorpay configuration so no real secrets sit in CI. The workflow is configured to upload the HTML report (14-day retention) and, when a run fails, the test-results folder. Traces are captured on the first retry; screenshots are not configured. No artifacts are currently available (checked 12 October 2026).

Keeping this suite separate from live gateway dependencies is what makes it trustworthy for regression testing — it doesn't need Razorpay to be reachable, or a Test Mode account to be in a particular state, to tell me whether something broke.

11 Limits

What I Could Not Fully Prove

Real webhook delivery

I never observed a genuine Razorpay-originated webhook arrive at the running application, even with a reachable public tunnel confirmed. What I did verify deterministically: raw-body handling, HMAC validation, correctly and incorrectly signed payloads, tampered payloads, and duplicate event IDs — all generated by the test suite itself, not received live from Razorpay. Those are two different claims, and I'm only making the one I can back up.

Successful real refund

No real Razorpay refund was completed — an account/environment restriction on this specific Test Mode account blocked it, confirmed to be external to the application. The refund route, its validation, its error handling (see DEF-001 above), and its state transitions are implemented and tested; the one thing untested is a live, successful refund response from Razorpay itself.

12 Lessons

What I Learned

Payment testing turned out to be state testing more than checkout testing — most of the interesting failures lived in what happens between systems, not inside any single request.

DEF-001 changed how I treat third-party SDK errors — "the docs describe a .message property" isn't the same as verifying what actually gets thrown, and I don't assume SDK error shapes anymore. DEF-002 turned something I only knew abstractly into something concrete: webhook correctness depends entirely on the exact bytes you hash, which makes middleware ordering a security decision, not just a code-organization one.

The two limitations taught me the most, honestly. "Implemented," "automated," and "observed working end-to-end" are three different claims, and it's easy to blur them together in a portfolio. This project is where I practiced keeping them separate.

13 Skills

What This Demonstrates

  • Risk-Based Testing
  • Functional Testing
  • API Testing
  • Security Testing
  • Payment Lifecycle Testing
  • Defect Investigation
  • Root-Cause Analysis
  • Regression Automation
  • State-Transition Testing
  • Webhook Testing
  • CI Regression
  • Honest Test Reporting

14 Evidence

Evidence & Verification

Source code, tests and the CI workflow are public on GitHub. CI run logs require a GitHub sign-in, and the report artifacts (14-day retention) have expired.

  • Source Code

    Complete Express application, Playwright test suite, state machine, and route handlers.

  • CI Execution

    GitHub Actions "Playwright CI" workflow — run history (last recorded run 14 Sep 2026). Job logs require a GitHub sign-in; report artifacts have expired.

  • QA Documentation

    Test strategy, full test case inventory, defect reports with root causes, and the real-payment evidence walkthrough.

Want to see the testing evidence?

The source code, test strategy, defect documentation and CI execution are all in the repository — including the two things I couldn't fully prove.

For the method behind it, read How to Test a Payment Gateway with Playwright. If you need something similar tested, see QA Services.