@devx-commerce/razorpay

0.0.14 • Public • Published

Medusa logo

Medusa Plugin - Razorpay Payment

Building blocks for digital commerce

PRs welcome! Product Hunt Discord Chat Follow @medusajs

Compatibility

This starter is compatible with versions >= 2.4.0 of @medusajs/medusa.

Getting Started

Visit the Quickstart Guide to set up a server.

Visit the Plugins documentation to learn more about plugins and how to create them.

Visit the Docs to learn more about our system requirements.

What is Medusa

Medusa is a set of commerce modules and tools that allow you to build rich, reliable, and performant commerce applications without reinventing core commerce logic. The modules can be customized and used to build advanced ecommerce stores, marketplaces, or any product that needs foundational commerce primitives. All modules are open-source and freely available on npm.

Learn more about Medusa’s architecture and commerce modules in the Docs.

Community & Contributions

The community and core team are available in GitHub Discussions, where you can ask for support, discuss roadmap, and share ideas.

Join our Discord server to meet other community members.

Other channels

Medusa Razorpay Payment Plugin

A Medusa plugin that integrates Razorpay as a payment provider for your Medusa e-commerce store.

Overview

This plugin allows you to accept payments through Razorpay, a popular payment gateway in India and other countries. It supports various payment methods including credit/debit cards, UPI, netbanking, and more.

Features

  • Payment Processing: Accept payments through Razorpay's payment gateway
  • Customer Management: Automatically create and manage customers in Razorpay
  • Webhook Support: Handle payment status updates via webhooks
  • Refund Support: Process refunds for captured payments
  • Auto-capture Option: Configure automatic or manual payment capture
  • Multi-currency Support: Handle payments in different currencies with proper conversion

Installation

  1. Install the plugin using npm:
npm install @devx-commerce/razorpay
yarn add @devx-commerce/razorpay
  1. Add the plugin to your Medusa server's configuration:
// medusa-config.js
module.exports = {
  projectConfig: {
    // ... other config
  },
  modules: [
    {
      resolve: "@medusajs/medusa/payment",
      options: {
        providers: [
          {
            resolve: "@devx-commerce/razorpay/providers/payment-razorpay",
            id: "razorpay",
            options: {
              key_id: process?.env?.RAZORPAY_ID,
              key_secret: process?.env?.RAZORPAY_SECRET,
              razorpay_account: process?.env?.RAZORPAY_ACCOUNT,
              automatic_expiry_period: 30,
              manual_expiry_period: 20,
              refund_speed: "normal",
              webhook_secret: process?.env?.RAZORPAY_WEBHOOK_SECRET,
              auto_capture: true,
            },
          },
        ],
      },
    },
  ],
};
  1. Add the required environment variables to your .env file:
RAZORPAY_ID=your_razorpay_key_id
RAZORPAY_SECRET=your_razorpay_key_secret
RAZORPAY_ACCOUNT=your_razorpay_account_id
RAZORPAY_WEBHOOK_SECRET=your_razorpay_webhook_secret

Configuration Options

Option Type Default Description
key_id string - Your Razorpay API key ID (required)
key_secret string - Your Razorpay API key secret (required)
webhook_secret string - Secret for validating webhook signatures
auto_capture boolean false Whether to automatically capture payments
refund_speed string "normal" Speed of refund processing ("normal" or "optimum")
automatic_expiry_period number 20 Expiry period in minutes for automatic capture
manual_expiry_period number 10 Expiry period in minutes for manual capture
razorpay_account string - Razorpay account ID for multi-account setups

Usage

Frontend Integration

  1. Clone the repo
git clone https://github.com/devx-commerce/plugin-razorpay-next-starter.git
  1. Install dependencies
npm install
yarn install
  1. Start the Medusa server
npm run dev
yarn dev
  1. Start the Next.js app
npm run dev
yarn dev

Webhook Setup

  1. Configure your Razorpay webhook endpoint in the Razorpay dashboard:

    • Go to Settings > Webhooks
    • Add a new webhook with URL: https://your-medusa-server.com/hooks/payment/razorpay_razorpay
    • Add secret key in the webhook secret field
    • Select events: payment.captured, payment.authorized, payment.failed, order.paid, refund.failed, refund.created
  2. Set the webhook secret in your environment variables:

    RAZORPAY_WEBHOOK_SECRET=your_webhook_secret
    

Supported Payment Methods

  • Credit/Debit Cards
  • UPI (Unified Payments Interface)
  • Netbanking
  • Wallets
  • Cash on Delivery (COD)
  • EMI

Currency Support

The plugin supports multiple currencies with proper conversion to the smallest unit. For example:

  • INR (Indian Rupee): Amount is converted to paise (1 INR = 100 paise)
  • Other currencies: Amount is converted based on their respective smallest units

Troubleshooting

Common Issues

  1. Payment not being captured: Check if auto_capture is set to true in your configuration.

  2. Webhook validation failing: Ensure your RAZORPAY_WEBHOOK_SECRET matches the secret in your Razorpay dashboard.

  3. Customer creation failing: Verify that the customer has a valid phone number and email.

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Package Sidebar

Install

npm i @devx-commerce/razorpay

Weekly Downloads

49

Version

0.0.14

License

MIT

Unpacked Size

72.1 kB

Total Files

13

Last publish

Collaborators

  • brijeshagarwal
  • vasuchapadia
  • brijesh_at_devx