@devx-commerce/razorpay
Version:
Razorpay integration for Medusa
228 lines (166 loc) • 8.06 kB
Markdown
<p align="center">
<a href="https://www.medusajs.com">
<picture>
<source media="(prefers-color-scheme: dark)" srcset="https://user-images.githubusercontent.com/59018053/229103275-b5e482bb-4601-46e6-8142-244f531cebdb.svg">
<source media="(prefers-color-scheme: light)" srcset="https://user-images.githubusercontent.com/59018053/229103726-e5b529a3-9b3f-4970-8a1f-c6af37f087bf.svg">
<img alt="Medusa logo" src="https://user-images.githubusercontent.com/59018053/229103726-e5b529a3-9b3f-4970-8a1f-c6af37f087bf.svg">
</picture>
</a>
</p>
<h1 align="center">
Medusa Plugin - Razorpay Payment
</h1>
<h4 align="center">
<a href="https://docs.medusajs.com">Documentation</a> |
<a href="https://www.medusajs.com">Website</a>
</h4>
<p align="center">
Building blocks for digital commerce
</p>
<p align="center">
<a href="https://github.com/medusajs/medusa/blob/master/CONTRIBUTING.md">
<img src="https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat" alt="PRs welcome!" />
</a>
<a href="https://www.producthunt.com/posts/medusa"><img src="https://img.shields.io/badge/Product%20Hunt-%231%20Product%20of%20the%20Day-%23DA552E" alt="Product Hunt"></a>
<a href="https://discord.gg/xpCwq3Kfn8">
<img src="https://img.shields.io/badge/chat-on%20discord-7289DA.svg" alt="Discord Chat" />
</a>
<a href="https://twitter.com/intent/follow?screen_name=medusajs">
<img src="https://img.shields.io/twitter/follow/medusajs.svg?label=Follow%20@medusajs" alt="Follow @medusajs" />
</a>
</p>
## Compatibility
This starter is compatible with versions >= 2.4.0 of `@medusajs/medusa`.
## Getting Started
Visit the [Quickstart Guide](https://docs.medusajs.com/learn/installation) to set up a server.
Visit the [Plugins documentation](https://docs.medusajs.com/learn/fundamentals/plugins) to learn more about plugins and how to create them.
Visit the [Docs](https://docs.medusajs.com/learn/installation#get-started) 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](https://docs.medusajs.com/learn/introduction/architecture) and [commerce modules](https://docs.medusajs.com/learn/fundamentals/modules/commerce-modules) in the Docs.
## Community & Contributions
The community and core team are available in [GitHub Discussions](https://github.com/medusajs/medusa/discussions), where you can ask for support, discuss roadmap, and share ideas.
Join our [Discord server](https://discord.com/invite/medusajs) to meet other community members.
## Other channels
- [GitHub Issues](https://github.com/medusajs/medusa/issues)
- [Twitter](https://twitter.com/medusajs)
- [LinkedIn](https://www.linkedin.com/company/medusajs)
- [Medusa Blog](https://medusajs.com/blog/)
# 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:
```bash
npm install @devx-commerce/razorpay
yarn add @devx-commerce/razorpay
```
2. Add the plugin to your Medusa server's configuration:
```javascript
// 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,
},
},
],
},
},
],
};
```
3. 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
```bash
git clone https://github.com/devx-commerce/plugin-razorpay-next-starter.git
```
2. Install dependencies
```bash
npm install
yarn install
```
3. Start the Medusa server
```bash
npm run dev
yarn dev
```
4. Start the Next.js app
```bash
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.