Elance Consulting Services Pvt Ltd
Development
12 min read
Updated 2026-11-18

Razorpay Integration Guide for Websites and Apps: Complete Tutorial

Razorpay is India's most popular payment gateway. Here's how to integrate it into your website, app or ecommerce store.

EC
Elance Consultancy Editorial
Senior Digital Strategy Team · Reviewed 2026-11-18

Need a payment gateway set up on your site?

We integrate Razorpay, Stripe, PayU, Cashfree or PayPal into websites, Shopify/WooCommerce stores and apps — checkout, webhooks, refunds and testing. Send your WhatsApp number for a fixed quote.

Only used to reply to this project enquiry on WhatsApp — never shared, no spam. Job seekers: careers@elanceconsultancy.com. Privacy

Short answer

To integrate Razorpay: create an order on your server with the Orders API, open Razorpay Checkout in the browser with that order ID, then verify the returned signature on your server (HMAC-SHA256 of order_id|payment_id with your key secret) before marking the order paid. Add webhooks so payments still register if the buyer closes the tab.

Before you start

  • A Razorpay account. You can build and test with test-mode keys before KYC is approved.
  • Your Key ID and Key Secret from the API Keys section of the Razorpay Dashboard. The Key ID is public; the Key Secret must only ever live on your server.
  • A server you control (Node, PHP, Python, Java — Razorpay has SDKs for all) or a platform plugin if you're on WooCommerce or Shopify.

Step 1 — Create an order on the server

Every payment should start from an order created server-side, so the amount can't be changed in the browser. Amounts are in the smallest currency unit: paise for INR.

// Node.js — npm install razorpay
const Razorpay = require("razorpay");
const razorpay = new Razorpay({
  key_id: process.env.RAZORPAY_KEY_ID,
  key_secret: process.env.RAZORPAY_KEY_SECRET,
});

app.post("/api/orders", async (req, res) => {
  const amount = priceFromYourDatabase(req.body.productId); // never trust the browser
  const order = await razorpay.orders.create({
    amount: amount * 100,          // ₹499 → 49900 paise
    currency: "INR",
    receipt: `order_${Date.now()}`,
  });
  res.json({ orderId: order.id, amount: order.amount });
});

Step 2 — Open Checkout in the browser

<script src="https://checkout.razorpay.com/v1/checkout.js"></script>
<script>
  async function pay() {
    const { orderId, amount } = await fetch("/api/orders", { method: "POST" }).then(r => r.json());
    const rzp = new Razorpay({
      key: "rzp_test_xxxxxxxx",      // Key ID only — never the secret
      order_id: orderId,
      amount,
      currency: "INR",
      name: "Your Store",
      prefill: { name: "", email: "", contact: "" },
      handler: (response) => fetch("/api/verify", {
        method: "POST",
        headers: { "Content-Type": "application/json" },
        body: JSON.stringify(response), // razorpay_order_id, razorpay_payment_id, razorpay_signature
      }),
    });
    rzp.open();
  }
</script>

Step 3 — Verify the signature on the server

The browser callback can be faked, so only treat a payment as successful after this check passes.

const crypto = require("crypto");

app.post("/api/verify", (req, res) => {
  const { razorpay_order_id, razorpay_payment_id, razorpay_signature } = req.body;
  const expected = crypto
    .createHmac("sha256", process.env.RAZORPAY_KEY_SECRET)
    .update(`${razorpay_order_id}|${razorpay_payment_id}`)
    .digest("hex");
  if (expected !== razorpay_signature) return res.status(400).json({ ok: false });
  markOrderPaid(razorpay_order_id, razorpay_payment_id);
  res.json({ ok: true });
});

Step 4 — Add webhooks (don't skip this)

Buyers close tabs, lose network or get bounced between UPI apps. Webhooks tell your server about the payment regardless. In the Dashboard, add a webhook URL with a secret and subscribe to at least payment.captured, payment.failed and order.paid. Verify each webhook by computing an HMAC-SHA256 of the raw request body with the webhook secret and comparing it to the X-Razorpay-Signature header. Make your handler idempotent — the same event can arrive more than once.

Step 5 — Test, then go live

  • In test mode, run a successful payment, a failed payment, a closed-tab payment and a refund. Check your order status after each.
  • Check payment capture settings: with auto-capture on, authorised payments are captured automatically; otherwise you must capture them via the API or they are refunded.
  • After KYC approval, generate live keys, swap them into your environment variables, and make one small real payment and refund it.

Using WooCommerce or Shopify instead?

You don't need custom code. On WooCommerce install the official Razorpay plugin and paste your keys; on Shopify add Razorpay from the payment providers settings. Custom integration only makes sense for custom-built sites, apps, or flows like subscriptions, split payments (Route) or marketplace payouts.

Frequently asked questions

Is Razorpay integration free?

Razorpay charges no setup or annual fee on its standard plan; you pay a per-transaction fee (about 2% plus GST for domestic payments). Developer time for a custom integration is the main cost — a plugin on WooCommerce or Shopify is usually free.

How long does Razorpay integration take?

A plugin setup takes under an hour plus KYC approval time. A custom integration with server-side orders, signature verification, webhooks and testing usually takes a developer one to three days, longer for subscriptions or marketplace payouts.

Can I integrate Razorpay in a mobile app?

Yes. Razorpay provides Android, iOS, Flutter and React Native SDKs. The same rule applies: create the order and verify the signature on your server, never in the app.

Sources

Last reviewed 2026-11-18. Third-party prices and policies change — confirm on the provider's site before deciding.

Need a payment gateway set up on your site?

We integrate Razorpay, Stripe, PayU, Cashfree or PayPal into websites, Shopify/WooCommerce stores and apps — checkout, webhooks, refunds and testing. Send your WhatsApp number for a fixed quote.

Only used to reply to this project enquiry on WhatsApp — never shared, no spam. Job seekers: careers@elanceconsultancy.com. Privacy

More Resources

Guides, case studies, and calculators for Indian businesses going digital.

CallWhatsAppQuote