Razorpay
Razorpay integration for Medusa
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
- Install the plugin using npm:
npm install @devx-commerce/razorpayyarn add @devx-commerce/razorpay
- Add the plugin to your Medusa server's configuration:
// medusa-config.jsmodule.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,},},],},},],};
- Add the required environment variables to your file:
Configuration Options
Option | Type | Default | Description |
---|---|---|---|
string | - | Your Razorpay API key ID (required) | |
string | - | Your Razorpay API key secret (required) | |
string | - | Secret for validating webhook signatures | |
boolean | false | Whether to automatically capture payments | |
string | "normal" | Speed of refund processing ("normal" or "optimum") | |
number | 20 | Expiry period in minutes for automatic capture | |
number | 10 | Expiry period in minutes for manual capture | |
string | - | Razorpay account ID for multi-account setups |
Usage
Frontend Integration
- Clone the repo
git clone https://github.com/devx-commerce/plugin-razorpay-next-starter.git
- Install dependencies
npm installyarn install
- Start the Medusa server
npm run devyarn dev
- Start the Next.js app
npm run devyarn dev
Webhook Setup
-
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: , , , , ,
-
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
-
Payment not being captured: Check if is set to in your configuration.
-
Webhook validation failing: Ensure your matches the secret in your Razorpay dashboard.
-
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.