PayU Payment Integration
May 6, 2025 · 5 min read
#PayU Payment Integration
medusa-payu is a payment provider plugin that integrates PayU payment processing with your Medusa commerce platform.
#Compatibility
This plugin is compatible with Medusa v2.4.0+.
#Installation
Install the plugin using npm or yarn:
npm install @tax1driver/medusa-payu
# or
yarn add @tax1driver/medusa-payu
#Configuration
Add the PayU payment provider to your medusa-config.ts:
modules: [
{
resolve: "@medusajs/medusa/payment",
options: {
providers: [
{
resolve: "@tax1driver/medusa-payu/providers/payu",
options: {
clientId: process.env.PAYU_CLIENT_ID,
clientSecret: process.env.PAYU_CLIENT_SECRET,
merchantPosId: process.env.PAYU_MERCHANT_POS_ID,
secondKey: process.env.PAYU_SECOND_KEY,
sandbox: process.env.PAYU_SANDBOX === "true",
returnUrl: process.env.PAYU_RETURN_URL,
// Webhook callback URL (defaults to APP_BASE_URL + /hooks/payment/payu)
callbackUrl: process.env.PAYU_CALLBACK_URL || `${process.env.APP_BASE_URL}/hooks/payment/payu`,
title: "Payment for order", // Optional
refundDescription: "Refund", // Optional
},
},
],
}
}
]
#Environment Variables
You'll need to set the following environment variables:
PAYU_CLIENT_ID=your_client_id
PAYU_CLIENT_SECRET=your_client_secret
PAYU_MERCHANT_POS_ID=your_merchant_pos_id
PAYU_SECOND_KEY=your_second_key
PAYU_SANDBOX=true # or false for production
PAYU_RETURN_URL=https://yourstore.com/checkout/return
PAYU_CALLBACK_URL=https://yourstore.com/hooks/payment/payu
APP_BASE_URL=https://yourstore.com
Get these credentials from your PayU dashboard.
#Usage
#Required Data
When initiating a PayU payment session, provide the following customer data:
const payuData = {
customer_ip: string; // Customer's IP address
email: string; // Customer's email
}
This data should be passed in your checkout flow when calling initiatePaymentSession.
#Webhook Configuration
The webhook endpoint is automatically registered at /hooks/payment/payu.
Important setup steps:
- Your
callbackUrlmust point to this endpoint (e.g.,https://yourdomain.com/hooks/payment/payu) - The endpoint must be publicly accessible
- Configure your firewall to allow incoming requests from PayU's servers
- Add the callback URL to your PayU account settings
#Refunds
The plugin supports partial and full refunds through Medusa's admin panel or API.
You can customize the refund description by setting the refundDescription option in configuration.
#Sandbox Mode
For testing, enable sandbox mode:
PAYU_SANDBOX=true
Use test payment cards provided by PayU in sandbox environment.
#PayU Resources
- PayU Homepage
- PayU Developer Documentation
- PayU Test Cards (see sandbox section)