Backend Development

Payment Gateway Integration India: Razorpay, PayU, Cashfree

Payment gateway integration India guide for custom apps: order creation, signature checks, webhooks, idempotency and reconciliation on Razorpay, PayU and Cashfree.

Illustration of a server verifying signed payment events from a gateway, representing payment gateway integration in India

Quick answer

Payment gateway integration in India means your server creates the order, the gateway collects UPI, card or netbanking payment, and your backend confirms the result through a verified webhook. Never trust the browser redirect alone. Verify every signature, process each event once, and reconcile payouts against orders. A solid integration typically takes one to four weeks.

Key takeaways

  • Create the order or transaction on your server, with the amount decided server-side, and never accept a price from the browser.
  • Treat the signed webhook, not the browser redirect, as the source of truth for marking an order paid.
  • Verify signatures against the raw request body, because parsing and re-serialising JSON changes the bytes and breaks the check.
  • Make fulfilment idempotent: store event IDs, expect duplicates and out-of-order events, and check payment state before acting.
  • Reconcile gateway payouts, your order table and bank credits every week so GST and refund queries are easy to answer.
On this page
  1. What does payment gateway integration involve?
  2. How do Razorpay, PayU and Cashfree differ for developers?
  3. Why must the webhook decide whether an order is paid?
  4. How do you verify webhook signatures correctly?
  5. How do you handle duplicate and out-of-order events?
  6. What should the build checklist include?
  7. How much does payment gateway integration cost in India?
  8. What mistakes should you avoid?
  9. How Arham Technology approaches payment gateway integration
  10. What should you do next?

If you are adding online payments to a custom website, SaaS product or internal portal, payment gateway integration India teams need goes well beyond pasting a checkout button. The part that decides whether money and orders stay in sync is on your server: how you create the order, verify the result and handle repeats.

This guide is written for founders and product owners who need to brief a developer, and for developers who want a checklist. It compares Razorpay, PayU and Cashfree on the points that matter for your backend, then walks through a safe build order, indicative costs and common mistakes.

What does payment gateway integration involve?

Payment gateway integration is the work of connecting your application's orders to a licensed payment provider so customers can pay by UPI, card, netbanking or wallet, and your system learns the result reliably. The gateway handles card entry, OTPs and bank redirects. You handle everything before and after.

A typical flow has five stages:

  1. Your server creates an order with the amount, currency and your own reference.
  2. The browser or app opens the gateway's checkout using that order.
  3. The customer pays, and the gateway returns a result to the browser.
  4. The gateway sends a signed webhook to your server with the final status.
  5. Your server marks the order paid, fulfils it and later reconciles the payout.

Steps 1 and 4 are where most bugs live, so they get most of the attention below. If you sell on Shopify instead of a custom stack, read our Shopify payment gateway guide for India, because the platform handles much of this for you.

How do Razorpay, PayU and Cashfree differ for developers?

All three give you server APIs, hosted or embedded checkout and webhooks, but they differ in how they identify and verify a payment. Check each provider's current documentation before you build, because parameters and versions change.

Area Razorpay PayU Cashfree
Starting point Create an Order on your server, pass its ID to Checkout Build a request hash and post a form with a unique transaction ID Create an order on your server and pass its session to checkout
Result check in the browser flow HMAC-SHA256 of order ID and payment ID with your key secret SHA-512 reverse hash of the response fields with your salt Fetch order status server-side
Webhook verification HMAC-SHA256 of the raw body, sent in X-Razorpay-Signature Transaction callback and webhooks, plus a status API HMAC-SHA256 of timestamp plus raw body, Base64 encoded, in x-webhook-signature
Duplicate detection x-razorpay-event-id header Unique transaction ID per attempt Idempotency key header and your order ID
Amount format Integer in paise String with two decimals Decimal in rupees

This is a summary, not a substitute for the docs. Razorpay documents its approach in Validate and Test Webhooks, PayU explains reverse hashing in its Generate Hash guide, and Cashfree describes its scheme in Webhook Signature Verification.

Pick on commercial and operational fit as well: approved rates, settlement cycle, refund handling and support. Our Shopify payment gateway comparison table lists the questions to ask each provider, and they apply to custom builds too.

Why must the webhook decide whether an order is paid?

The signed webhook is the only message that comes from the gateway to your server directly, so it is the safest signal for marking an order paid. The browser callback depends on a customer's device and network, and it can be skipped or forged.

Razorpay's integration guide says plainly to rely on webhooks for all fulfilment and never use the browser callback alone for order confirmation. The same principle applies to PayU and Cashfree. Use the browser result to show "payment processing" and let the webhook, or a server-side status fetch, flip the order to paid.

Keep a fallback for the rare missed webhook. If an order has been pending longer than a few minutes, call the gateway's payment status API from a scheduled job and update the order from that response. This protects users who paid but never saw a confirmation page.

How do you verify webhook signatures correctly?

You verify a webhook by recomputing the HMAC of the raw request body with your secret and comparing it to the signature header before you parse or use any field. The raw body matters because re-serialising JSON can change spacing, field order or number formatting, which breaks the match.

In Node.js this means capturing the raw bytes before your JSON middleware runs. Use a constant-time comparison for the final check, and return a 4xx status when it fails.

Three details trip teams up:

  • Secret mismatch. Razorpay's webhook secret is set when you create the webhook and does not have to be your API key secret.
  • Rotated secrets. Retried events may be signed with the old secret, so keep it available while old events drain.
  • Decimal formatting. Cashfree notes that converting the payload to an object can turn 170.00 into 170, which changes the signature input.

Signature checks sit alongside the rest of your API hygiene, so pair this with our API security checklist for auth, rate limits and logging.

How do you handle duplicate and out-of-order events?

You handle them by recording every event ID once and by making the business action depend on current order state, not on event arrival order. Razorpay documents at-least-once delivery, so the same event can reach you several times, for example when your server accepts it but does not respond within the timeout.

A reliable pattern looks like this:

  1. Verify the signature on the raw body.
  2. Insert the event ID into a table with a unique constraint. If the insert fails, return 200 and stop.
  3. Return 200 quickly and push the real work onto a queue.
  4. In the worker, load the order and check its state. Only move forward, for example from pending to paid, never backwards.
  5. Fulfil once, using a unique key such as the order ID, so two different events about the same payment cannot ship twice.

Razorpay also warns that payment.captured can arrive before payment.authorized, so do not assume a sequence. Queues and retries are covered in our post on backend scalability with caching, queues and read replicas.

What should the build checklist include?

A complete build covers more than the happy path. Use this order of work:

  1. Define the order model. Store your order ID, gateway order or transaction ID, amount in paise or rupees, status and timestamps.
  2. Create orders server-side only. Calculate the amount from your own price data, never from a browser field. PayU also expects a fresh transaction ID for every retry.
  3. Verify the result. Check the checkout signature or reverse hash, then confirm the amount matches your order.
  4. Add the webhook endpoint with raw-body signature checks, event ID storage and a queue.
  5. Build refunds and failures. Handle failed payments, partial refunds and refund failure events, and show clear status to the customer.
  6. Add reconciliation. Match gateway settlement reports to your orders and your bank statement.
  7. Test in sandbox, including duplicate, delayed and out-of-order events and an expired UPI request.
  8. Go live with small real payments, refund them and confirm the full trail.

For API shape and versioning, our REST API design best practices post covers conventions that keep payment endpoints predictable.

How much does payment gateway integration cost in India?

Cost depends on scope, not on the gateway, because the gateways themselves provide SDKs and documentation. The ranges below are indicative estimates based on typical project scopes, not quotes.

Scope What is included Indicative cost Typical timeline
Basic checkout One gateway, order creation, result check, simple webhook โ‚น25,000โ€“โ‚น60,000 3โ€“7 working days
Production-grade payments Webhook queue, idempotency, refunds, admin view, reconciliation export โ‚น60,000โ€“โ‚น1,50,000 1โ€“3 weeks
Advanced payments Multiple gateways, subscriptions, split payouts or marketplace flows โ‚น1,50,000โ€“โ‚น4,00,000 or more 3โ€“8 weeks

GST applies to development fees, and gateway charges are separate. Recurring billing needs extra design work, which we cover in our post on SaaS subscription billing in India. Your final estimate will depend on your existing codebase, compliance needs and the number of payment flows.

What mistakes should you avoid?

Most payment incidents come from a small set of shortcuts:

  • Trusting the browser redirect and shipping before the webhook arrives.
  • Taking the amount from the client, which lets a user pay โ‚น1 for a โ‚น10,000 order.
  • Parsing the body before verifying, then wondering why signatures fail.
  • Skipping duplicate handling, so a retry credits wallet balance or sends goods twice.
  • Leaving test keys in production or live keys in a public repository.
  • Not logging gateway IDs, which makes a support case slow to resolve.
  • Never reconciling, so settlement gaps surface only at GST filing time.

How Arham Technology approaches payment gateway integration

Payments sit inside our backend development service, where we treat correctness and operability as the main goals rather than extra features. For a gateway project the process is:

  • Domain and threat sketch: we map your order lifecycle, trust boundaries and the abuse cases that matter, such as amount tampering and replayed events.
  • Contract first: we agree API contracts so your web or mobile client and the payment endpoints can be built in parallel.
  • Core build: order creation, verification and webhook handling ship with automated tests around the state transitions.
  • Integration reality: background workers, retries and idempotent write paths are exercised against sandbox events, including duplicates and delays.
  • Runbook handover: deploy steps, secret handling and incident basics are documented for your team.

If payments are part of a larger product, our SaaS development service covers the surrounding billing, tenancy and admin features.

What should you do next?

Write down your payment flows first: one-time orders, refunds, subscriptions and payouts. Shortlist two gateways, ask for written rates and sandbox access, and decide how you will reconcile before you write code. If you want a second pair of eyes on an existing integration or a plan for a new one, review our backend development service and contact us with your order volume and stack. We will outline a pragmatic scope and test plan before you commit.

Frequently asked questions

How long does payment gateway integration take in India?

A single-gateway checkout with webhooks and refunds usually takes one to two weeks of development once the merchant account is approved. Multi-gateway routing, subscriptions or marketplace payouts can take three to six weeks. Gateway approval itself can take several working days, so start it early.

Which payment gateway is best for a custom website in India?

There is no single best choice. Razorpay, PayU and Cashfree all support UPI, cards and netbanking with server APIs and webhooks. Choose on approved rates, success rate on your traffic, settlement time, documentation quality and support. Keep your code behind a small payment interface so you can add a second gateway later.

Is the browser redirect enough to confirm a payment?

No. A customer can close the tab, lose network or tamper with a redirect before your page loads. Use the browser response only to show a pending screen, then confirm the order through a signed webhook or a server-side payment status call before you deliver anything.

What is webhook idempotency in payments?

Idempotency means processing the same event twice has the same effect as processing it once. Gateways such as Razorpay use at-least-once delivery, so duplicates are normal. Store each event ID with a unique constraint and make fulfilment depend on order state, so a repeat never ships or credits twice.

Do I need a separate integration for UPI?

Usually not. UPI is offered as a payment method inside the gateway's checkout, so one integration covers UPI, cards, netbanking and wallets. You only need extra work if you want features such as UPI AutoPay mandates, which depend on the gateway's recurring payment products.

How should I store gateway API keys safely?

Keep keys and webhook secrets in environment variables or a secrets manager, never in git or in browser code. Use separate test and live credentials, restrict who can read production secrets, and plan a rotation process. Webhook secrets can differ from API secrets, so store them separately.

NEXT STEP

Want Backend Development done right?

Get a free consultation and a clear plan โ€” scope, timeline and cost โ€” from our Mumbai team.

Get a free consultation โ†’See Backend Development