npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

razorpay-sdk

v1.0.6

Published

A lightweight, secure, and reusable Node.js SDK for integrating Razorpay payments efficiently, with built-in helpers for order creation and payment verification.

Readme

Razorpay SDK for Node.js

A lightweight, secure, and reusable Node.js module for integrating Razorpay payments that saves development time and costs.

Overview

The razorpay-sdk is a comprehensive solution for backend payment integration with Razorpay. It simplifies common payment operations while ensuring security and scalability for applications of all sizes.

Key Features

  1. Simplified Order Management

    • Easily create payment orders with custom options
    • Support for multiple currencies
    • Custom notes and metadata for orders
  2. Payment Verification

    • Secure verification of payment responses
    • Protection against fraudulent transactions
  3. Webhook Handling

    • Automatic verification of Razorpay webhooks
    • Reliable handling of payment events
  4. Multi-Client / Multi-Tenant Support

    • Manage multiple merchant accounts in one application
    • Isolated and secure account handling
  5. Security & Compliance

    • HMAC signature validation for all operations
    • Safe handling of sensitive API keys
    • No hardcoded credentials
  6. Extensible & Scalable

    • Supports refunds, order listing, and payment details
    • Compatible with serverless environments
    • Easy to extend with custom functionality

Installation

For local development:

npm install

To use this package in another project locally:

npm install /path/to/this/directory

Or if you publish it to npm:

npm install @local/razorpay-sdk

Usage

Single Client Setup

const RazorpaySDK = require('@local/razorpay-sdk');

// Initialize with your API keys
const razorpay = new RazorpaySDK('YOUR_KEY_ID', 'YOUR_KEY_SECRET');

Creating an Order

async function createOrder() {
  try {
    const order = await razorpay.createOrder({
      amount: 50000, // amount in smallest currency unit (50000 paise = INR 500)
      currency: 'INR',
      receipt: 'order_rcptid_11',
      notes: {
        'description': 'Test order'
      }
    });
    
    console.log('Order created:', order);
    return order;
  } catch (error) {
    console.error('Error:', error.message);
  }
}

Verifying a Payment

// After receiving payment response in your backend
const isValid = razorpay.verifyPayment(
  razorpay_order_id, 
  razorpay_payment_id, 
  razorpay_signature
);

if (isValid) {
  // Payment is valid, proceed with business logic
  console.log('Payment verified successfully');
} else {
  // Invalid payment, do not proceed
  console.log('Payment verification failed');
}

Creating a Payment Link

async function createPaymentLink() {
  try {
    const paymentLink = await razorpay.createPaymentLink({
      amount: 50000, // amount in smallest currency unit (50000 paise = INR 500)
      currency: 'INR',
      description: 'Test payment',
      customer: {
        name: 'John Doe',
        email: '[email protected]',
        contact: '+919876543210'
      },
      notes: {
        'reference': 'Test payment link'
      }
      // UPI is enabled by default for Indian merchants
      // No additional configuration needed for basic UPI support
    });
    
    console.log('Payment link created:', paymentLink);
    return paymentLink;
  } catch (error) {
    console.error('Error:', error.message);
  }
}

Creating a UPI-Specific Payment Link

async function createUpiPaymentLink() {
  try {
    const paymentLink = await razorpay.createUpiPaymentLink({
      amount: 50000, // amount in smallest currency unit (50000 paise = INR 500)
      currency: 'INR',
      description: 'Test UPI payment',
      customer: {
        name: 'John Doe',
        email: '[email protected]',
        contact: '+919876543210'
      },
      notes: {
        'reference': 'Test UPI payment link'
      },
      // Optional: Specify a default UPI VPA
      upiVpa: 'john@upi' // This is just an example
    });
    
    console.log('UPI Payment link created:', paymentLink);
    return paymentLink;
  } catch (error) {
    console.error('Error:', error.message);
  }
}

createPaymentLink(options)

Create a payment link for customers to make payments.

createUpiPaymentLink(options)

Create a UPI-specific payment link for customers to make payments.

Options:

  • amount (number) - Amount in smallest currency unit
  • currency (string) - Currency code (e.g., 'INR')
  • description (string) - Description of the payment
  • customer (object) - Customer details
    • name (string) - Customer name
    • email (string) - Customer email
    • contact (string) - Customer contact number
  • notes (object) - Custom notes for the payment
  • upiVpa (string, optional) - Default UPI Virtual Payment Address

Note: UPI payments are enabled by default for Indian merchants. Customers will see the UPI option when they open the payment link on their mobile devices.

Multi-Tenant Support

const MultiTenantRazorpay = require('@local/razorpay-sdk/lib/multi-tenant-sdk');

const multiTenantRazorpay = new MultiTenantRazorpay();

// Add multiple merchant clients
multiTenantRazorpay.addClient('client1', 'CLIENT1_KEY_ID', 'CLIENT1_KEY_SECRET');
multiTenantRazorpay.addClient('client2', 'CLIENT2_KEY_ID', 'CLIENT2_KEY_SECRET');

// Get a specific client
const client1 = multiTenantRazorpay.getClient('client1');

// Create an order for client1
const order = await client1.createOrder({
  amount: 30000,
  currency: 'INR'
});

API Reference

RazorpaySDK

new RazorpaySDK(key_id, key_secret)

Initialize the SDK with your Razorpay API credentials.

createOrder(options)

Create a new payment order.

verifyPayment(razorpay_order_id, razorpay_payment_id, razorpay_signature)

Verify a payment response.

verifyWebhook(body, signature)

Verify a webhook signature.

fetchPayment(payment_id)

Fetch payment details.

capturePayment(payment_id, amount, currency)

Capture a payment.

refundPayment(payment_id, options)

Refund a payment.

fetchOrders(options)

Fetch all orders.

createPaymentLink(options)

Create a payment link for customers to make payments.

createUpiPaymentLink(options)

Create a UPI-specific payment link for customers to make payments.

Options:

  • amount (number) - Amount in smallest currency unit
  • currency (string) - Currency code (e.g., 'INR')
  • description (string) - Description of the payment
  • customer (object) - Customer details
    • name (string) - Customer name
    • email (string) - Customer email
    • contact (string) - Customer contact number
  • notes (object) - Custom notes for the payment
  • upi (object) - UPI payment options
    • enable (boolean) - Enable UPI payments
    • vpa (string) - Default UPI Virtual Payment Address
  • method (object) - Payment method options
    • netbanking (boolean) - Enable netbanking
    • card (boolean) - Enable card payments
    • wallet (boolean) - Enable wallet payments
    • upi (boolean) - Enable UPI payments

fetchPaymentLink(paymentLinkId)

Fetch a payment link by its ID.

MultiTenantRazorpay

addClient(clientId, key_id, key_secret)

Add a new merchant client.

getClient(clientId)

Get a merchant client by ID.

removeClient(clientId)

Remove a merchant client.

listClients()

List all client IDs.

Benefits

  • Saves Development Time: Pre-built functions for all common Razorpay operations
  • Reduces Errors: Built-in validation and error handling
  • Supports Growth: Multi-tenant architecture for scaling
  • Secure by Design: Cryptographically secure verification methods
  • Cost Effective: Reduces development and maintenance costs
  • Easy Integration: Simple API that works with any Node.js application

Testing

Run the test suite:

npm test

License

MIT

Support

For issues and feature requests, please open an issue on GitHub.