A Pesapal payment provider plugin for Medusa v2 that enables seamless integration with Pesapal's payment gateway, supporting popular East African payment methods including M-Pesa, Airtel Money, and more.
- 🔄 Full Payment Lifecycle: Support for authorization, capture, refunds, and cancellations
- 🌍 Multi-Currency: Support for KES, USD, EUR, GBP, UGX, TZS and more
- 📱 East African Payment Methods: M-Pesa, Airtel Money, Bank transfers, and credit cards
- 🔒 Secure: Industry-standard security practices with OAuth 2.0 authentication
- 🎛️ Admin Dashboard: Easy configuration and management through Medusa Admin
- 🔔 Webhooks: Real-time payment status updates via IPN (Instant Payment Notifications)
- 🧪 Sandbox Support: Full testing environment with provided test credentials
- 🌍 East African Payment Methods: Support for M-Pesa, Airtel Money, bank transfers, and card payments
- 🔒 Secure Authentication: OAuth 2.0 integration with Pesapal API v3
- 🎯 Sandbox & Production: Easy environment switching for testing and live payments
- 🎛️ Admin Configuration: Beautiful admin widget for easy setup and management
- 🔔 Webhook Support: Real-time payment status updates via IPN callbacks
- 💱 Multi-Currency: Support for KES, USD, EUR, GBP, UGX, TZS and more
- ⚡ Modern Architecture: Built specifically for Medusa v2 framework
npm install medusa-payment-pesapal
# or
yarn add medusa-payment-pesapal
import { defineConfig } from '@medusajs/framework/utils'
export default defineConfig({
modules: [
{
resolve: "@medusajs/medusa/payment",
options: {
providers: [
{
resolve: "medusa-payment-pesapal",
id: "pesapal",
options: {
consumer_key: process.env.PESAPAL_CONSUMER_KEY,
consumer_secret: process.env.PESAPAL_CONSUMER_SECRET,
environment: process.env.PESAPAL_ENVIRONMENT || "sandbox",
currency: process.env.PESAPAL_CURRENCY || "KES",
merchant_name: process.env.PESAPAL_MERCHANT_NAME,
ipn_url: process.env.PESAPAL_IPN_URL,
}
}
]
}
}
]
})
Add these variables to your .env
file:
# Pesapal Configuration
PESAPAL_CONSUMER_KEY=your_consumer_key
PESAPAL_CONSUMER_SECRET=your_consumer_secret
PESAPAL_ENVIRONMENT=sandbox # or 'live' for production
PESAPAL_CURRENCY=KES
PESAPAL_MERCHANT_NAME="Your Business Name"
PESAPAL_IPN_URL=https://yourdomain.com/pesapal/webhook
For Kenyan merchants, you can use these test credentials:
PESAPAL_CONSUMER_KEY=qkio1BGGYAXTu2JOfm7XSXNruoZsrqEW
PESAPAL_CONSUMER_SECRET=osGQ364R49cXKeOYSpaOnT++rHs=
After installation, you can configure Pesapal directly from the Medusa Admin:
- Navigate to the Orders section in your admin panel
- Look for the "Pesapal Configuration" widget
- Fill in your credentials and settings
- Test the connection
- Enable the payment provider
The plugin automatically creates these endpoints:
-
GET /admin/custom/pesapal/config
- Get current configuration -
POST /admin/custom/pesapal/config
- Save configuration -
POST /admin/custom/pesapal/test
- Test connection -
GET /store/pesapal/webhook
- Handle IPN callbacks -
POST /store/pesapal/webhook
- Handle IPN callbacks
The payment provider will be automatically available in your checkout flow. Customers can select Pesapal as a payment method and will be redirected to Pesapal's secure payment page.
- M-Pesa (Kenya, Tanzania)
- Airtel Money (Kenya, Uganda, Tanzania)
- Bank Transfers (Multiple banks across East Africa)
- Credit/Debit Cards (Visa, Mastercard)
- Mobile Banking (Equity, KCB, etc.)
- KES (Kenyan Shilling)
- USD (US Dollar)
- EUR (Euro)
- GBP (British Pound)
- UGX (Ugandan Shilling)
- TZS (Tanzanian Shilling)
- Clone the repository
- Install dependencies:
npm install
- Build the plugin:
npm run build
- Link for local testing:
npm link
npm run build
npm test
For production use, configure your webhook URL in the Pesapal merchant dashboard:
- Login to your Pesapal merchant account
- Go to Settings > IPN Settings
- Set your IPN URL to:
https://yourdomain.com/store/pesapal/webhook
- Select the events you want to receive notifications for
If you're migrating from Medusa v1, please note that this plugin is specifically designed for Medusa v2 and uses the new payment provider architecture.
- Documentation: Pesapal API Documentation
- Issues: GitHub Issues
- Community: Medusa Discord
Contributions are welcome! Please read our contributing guidelines and submit pull requests to help improve this plugin.
MIT © Antony Ngigge
Antony Ngigge (Machomaniac)
- Website: iWorldAfric
- GitHub: @mrrobotke
- Email: antonyngigge@gmail.com
Made with ❤️ for the East African e-commerce community