Medusa plugins
R

Razorpay

Razorpay integration for Medusa

Need customizations for this plugin?

Get in touch
npm install @devx-commerce/razorpay
Category
other
Built by
devx-commerce
Type
unknown
Last updated
1 month ago
Monthly downloads
697

Compatibility

This starter is compatible with versions >= 2.4.0 of .

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 file:

Configuration Options

OptionTypeDefaultDescription
string-Your Razorpay API key ID (required)
string-Your Razorpay API key secret (required)
string-Secret for validating webhook signatures
booleanfalseWhether to automatically capture payments
string"normal"Speed of refund processing ("normal" or "optimum")
number20Expiry period in minutes for automatic capture
number10Expiry period in minutes for manual capture
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:
    • Add secret key in the webhook secret field
    • Select events: , , , , ,
  2. Set the webhook secret in your environment variables:

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 is set to in your configuration.

  2. Webhook validation failing: Ensure your 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.