Razorpay Gateway (Express.js)

Developer-ready Express.js middleware for integrating Razorpay payments with modular REST endpoints, secure signature verification, and webhook automation. Designed for scalability and easy extension.

razorpaypaymentgatewayexpresssecureverifywebhooknodejs
v1.1.0payment

Overview

A modular Razorpay payment gateway built with Express.js, enabling seamless order creation, payment verification, and webhook handling for real-time payment updates. Includes strong HMAC SHA256 verification for security and a flexible architecture for extending with subscriptions, refunds, or custom workflows.

Installation

CLI
npx backternity add razorpay-gateway-express-js

What This Does

Installs a preconfigured Razorpay payment integration with clean route separation, secure webhook verification, and reusable payment services.

Files & Folders Created

File / PathDescription
/src/config/razorpay.jsInitializes Razorpay SDK and loads credentials from .env
/src/services/paymentService.jsCore logic for order creation, verification, and webhooks
/src/routes/payment.jsREST routes for order creation, verification, and fetching details
/server.js.exampleExpress server integrating payment routes
/.env.exampleExample config for Razorpay keys and webhook secret

Files to be modified

File / PathDescription
server.jsAdds /api/payment route and webhook middleware
.envAdds Razorpay credentials (RAZORPAY_KEY_ID, RAZORPAY_KEY_SECRET, WEBHOOK_SECRET)

Configuration

# Razorpay Configuration
RAZORPAY_KEY_ID=your_razorpay_key_id
RAZORPAY_KEY_SECRET=your_razorpay_key_secret
PORT=8000
WEBHOOK_SECRET=your_webhook_secret

Frontend Integration

Integrate directly with your frontend to initiate secure payment orders, verify signatures after checkout, and track payment statuses in real-time. Perfect for integrating with React, Next.js, or Vue apps.

POST/api/payment/order

Creates a new Razorpay order. Accepts amount, currency, metadata, and optional custom options.

POST/api/payment/verify

Verifies payment using the signature returned by Razorpay after successful payment.

GET/api/payment/order/:id

Fetches full Razorpay order details using the order ID.

POST/api/payment/webhook

Receives and verifies Razorpay webhooks for automatic payment events (e.g., payment captured, refund, etc.).

Example

1// Example frontend usage (Next.js) 2'use client'; 3import { useState } from 'react'; 4 5export default function RazorpayCheckout() { 6 const [loading, setLoading] = useState(false); 7 8 async function handlePayment() { 9 setLoading(true); 10 const res = await fetch('/api/payment/order', { 11 method: 'POST', 12 headers: { 'Content-Type': 'application/json' }, 13 body: JSON.stringify({ amount: 49900 }) // amount in paise 14 }); 15 const data = await res.json(); 16 17 const options = { 18 key: process.env.NEXT_PUBLIC_RAZORPAY_KEY_ID, 19 amount: data.order.amount, 20 currency: data.order.currency, 21 order_id: data.order.id, 22 handler: async (response) => { 23 await fetch('/api/payment/verify', { 24 method: 'POST', 25 headers: { 'Content-Type': 'application/json' }, 26 body: JSON.stringify(response) 27 }); 28 alert('Payment verified successfully!'); 29 } 30 }; 31 32 const razorpay = new window.Razorpay(options); 33 razorpay.open(); 34 setLoading(false); 35 } 36 37 return ( 38 <button 39 onClick={handlePayment} 40 disabled={loading} 41 className="bg-emerald-500 hover:bg-emerald-600 px-4 py-2 rounded-md text-white" 42 > 43 {loading ? 'Processing...' : 'Pay ₹499'} 44 </button> 45 ); 46}

Usage

1// Example service usage (server-side) 2const { createOrder, verifyPaymentSignature } = require('./src/services/paymentService'); 3 4(async () => { 5 const order = await createOrder({ amount: 10000, metadata: { user: 'John' } }); 6 console.log('Created order:', order); 7})();

Get in Touch

For partnerships, collaborations, or custom backend components - let’s build something powerful together.

Send us a message

Reach us directly

Email

team@backternity.dev

Quick Answers

Are components free?

Yes, they’re absolutely free to use.

Do you offer custom work?

Absolutely, we build scalable backend systems tailored to your stack.

How often are updates released?

Monthly, with new components, optimizations, and features.

Razorpay Gateway (Express.js) – Payment Component | Backternity