Building blocks for digital commerce
This starter is compatible with versions >= 2.4.0 of @medusajs/medusa
.
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.
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.
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.
A Medusa plugin that integrates Razorpay as a payment provider for your Medusa e-commerce store.
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.
- 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
- Install the plugin using npm:
npm install @devx-commerce/razorpay
yarn add @devx-commerce/razorpay
- 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,
},
},
],
},
},
],
};
- 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
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 |
- Clone the repo
git clone https://github.com/devx-commerce/plugin-razorpay-next-starter.git
- Install dependencies
npm install
yarn install
- Start the Medusa server
npm run dev
yarn dev
- Start the Next.js app
npm run dev
yarn dev
-
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
-
Set the webhook secret in your environment variables:
RAZORPAY_WEBHOOK_SECRET=your_webhook_secret
- Credit/Debit Cards
- UPI (Unified Payments Interface)
- Netbanking
- Wallets
- Cash on Delivery (COD)
- EMI
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
-
Payment not being captured: Check if
auto_capture
is set totrue
in your configuration. -
Webhook validation failing: Ensure your
RAZORPAY_WEBHOOK_SECRET
matches the secret in your Razorpay dashboard. -
Customer creation failing: Verify that the customer has a valid phone number and email.
Contributions are welcome! Please feel free to submit a Pull Request.
This project is licensed under the MIT License - see the LICENSE file for details.