Cashfree payment plugin
Cashfree Payment Plugin for MedusaJS 2
β¨ Features
-
π³ Multiple Payment Methods - UPI, Credit/Debit Cards, Net Banking, Paylater, EMI and Wallets
-
πΈ Easy Refunds - Process refunds directly from Medusa admin panel
-
π Secure Transactions - Webhook verification and PCI DSS compliance
-
π Dual Environment - Sandbox testing and production ready
-
β‘ Real-time Updates - Instant payment status synchronization
π Changelog
Version 1.0.4 (Latest)
-
π Security Enhancements
- Fixed webhook secret validation (now required for security)
- Enhanced sensitive data protection in error logging
- Improved cryptographic security for refund ID generation
- Added comprehensive input validation and sanitization
-
π Enhanced Monitoring
- Added detailed webhook security logging with IP tracking
- Improved error messages for better debugging
- Added request validation logging for troubleshooting
-
π Bug Fixes
- Fixed "UNSUPPORTED" error with better request formatting
- Enhanced phone number formatting for Cashfree API
- Improved customer name handling and validation
Version 1.0.3
- Initial release with core payment functionality
- Webhook signature verification
- Basic refund processing
- Medusa v2 compatibility
π Prerequisites
-
MedusaJS 2 store
-
Cashfree Payments merchant account
π§ To Do:
- Rewrite the plugin with more optimizations and code cleanup.
π οΈ Installation
Step 1: Install the Plugin
Choose your preferred package manager:
# npmnpm install medusa-cashfree-payment-plugin# yarnyarn add medusa-cashfree-payment-plugin# pnpmpnpm add medusa-cashfree-payment-plugin
Step 2: Configure Plugin
Add the plugin to your :
module.exports = defineConfig({modules: [// ... other plugins{resolve: "@medusajs/medusa/payment",options: {providers: [{resolve: "medusa-cashfree-payment-plugin/providers/cashfree",id: "cashfree",options: {app_id: process.env.CASHFREE_APP_ID,secret_key: process.env.CASHFREE_SECRET_KEY,environment: process.env.CASHFREE_ENV,webhook_secret: process.env.CASHFREE_WEBHOOK_SECRET,return_url: process.env.CASHFREE_RETURN_URL,notify_url: process.env.CASHFREE_NOTIFY_URL}}]}}];})
Step 3: Environment Variables
Create or update your file:
# Cashfree ConfigurationCASHFREE_APP_ID=your_app_id_hereCASHFREE_SECRET_KEY=your_secret_key_hereCASHFREE_ENVIRONMENT=sandboxCASHFREE_WEBHOOK_SECRET=your_webhook_secret_hereCASHFREE_RETURN_URL=https://your-store-domain.com/processing/orderCASHFREE_NOTIFY_URL=https://your-store-domain.com/hooks/payment/cashfree_cashfree
β οΈ Security Note: Never commit your production credentials to version control.
βοΈ Cashfree Configuration Options
| Option | Type | Required | Default | Description |
|---|---|---|---|---|
| string | β | - | Your Cashfree App ID | |
| string | β | - | Your Cashfree Secret Key | |
| string | β | Environment to use ( or ) | ||
| string | β | - | Webhook secret for signature verification (REQUIRED for security) | |
| string | β | - | URL to redirect the customer to after payment is complete | |
| string | β | - | URL to receive webhook notifications from Cashfree about payment status |
π― Setup Guide
Enable Payment Provider
-
Navigate to Medusa Admin β Settings β Regions
-
Select your target region - India
-
In Payment Providers, select
-
Click Save Changes
Configure Webhooks
-
Go to Cashfree Dashboard β Developers β Webhooks
-
Click Add Webhook
-
Configure webhook URL. You can use the from your file or another URL.
- Select these events:
-
Add your webhook secret to .env -
-
Save configuration
Note -
: The is where the customer is redirected after completing the payment. It's important to set this to a page on your storefront that can handle the order completion process.
: This is the webhook endpoint of your server where Cashfree will send automatic updates (like payment success, failure, or refund) for each order. Default is .
π§ API Reference
This plugin implements the complete interface:
Core Methods
- - Initialize payment session
- - Authorize payment amount
- - Capture authorized payment
- - Cancel pending payment
- - Process refunds
Utility Methods
- - Get current payment status
- - Fetch payment details
- - Update payment information
- - Remove payment record
π Troubleshooting
Common Issues
Plugin not appearing in admin
# Restart your Medusa servernpm run dev
Webhook verification failing
-
Ensure webhook secret matches in both Cashfree dashboard and
-
Check webhook URL is publicly accessible
Payment status not updating
-
Verify webhook events are properly configured
-
Check server logs for webhook errors
Getting Help
-
π¬ MedusaJS Discord
-
π Report Issues
π€ Contributing
We welcome contributions! Please see our Contributing Guide for details.
-
Fork the repository
-
Create your feature branch ()
-
Commit your changes ()
-
Push to the branch ()
-
Open a Pull Request
π License
This project is licensed under the MIT License - see the LICENSE file for details.
π Acknowledgments
-
MedusaJS - for the best open-source e-commerce platform.
-
Cashfree - for providing reliable payment processing service.