Ipay
iPay Africa payment provider for Medusa v2 - Supports M-Pesa, Airtel Money, Credit Cards, and PesaLink
Medusa Payment iPay
A Medusa v2 payment provider plugin for iPay Africa, supporting multiple payment channels including M-Pesa, Airtel Money, Credit/Debit Cards, and PesaLink.
Features
- ๐ Complete iPay Africa Integration - Full support for iPay's payment gateway
- ๐ณ Multiple Payment Channels:
- M-Pesa (Safaricom Mobile Money)
- Airtel Money
- Credit/Debit Cards (Visa, Mastercard)
- PesaLink (Bank transfers)
- ๐ Secure Transactions - HMAC SHA1 signature verification
- ๐๏ธ Admin Configuration - Easy setup through Medusa Admin dashboard
- ๐ Webhook Support - Real-time payment status updates
- ๐งช Test Mode - Sandbox environment for development
- ๐ฑ Responsive Design - Works on desktop and mobile
Installation
npm install medusa-payment-ipay# oryarn add medusa-payment-ipay
Configuration
1. Add to medusa-config.ts
import { defineConfig } from "@medusajs/medusa"export default defineConfig({// ... other configmodules: [{resolve: "@medusajs/medusa/payment",options: {providers: [{resolve: "medusa-payment-ipay/providers/ipay",id: "ipay",options: {vid: process.env.IPAY_VID, // Your iPay Vendor IDhashKey: process.env.IPAY_HASH_KEY, // Your iPay Hash Keylive: process.env.IPAY_LIVE === "true", // true for production, false for testingenabledChannels: {mpesa: true,airtel: true,creditcard: false, // Enable for card payments (requires PCI compliance)pesalink: false // Enable for bank transfers}}}]}}]})
2. Environment Variables
Add these to your file:
# iPay ConfigurationIPAY_VID=your_vendor_idIPAY_HASH_KEY=your_hash_keyIPAY_LIVE=false # Set to true for production# For testing, use these values:# IPAY_VID=demo# IPAY_HASH_KEY=demoCHANGED
3. Admin Configuration
- Navigate to your Medusa Admin dashboard
- Go to Settings โ Payment Providers
- Enable the iPay provider for your sales regions
- Configure your iPay credentials through the admin widget
Usage
Test Credentials
For development and testing:
- Vendor ID:
- Hash Key:
- Live Mode:
Test Card Numbers
When testing credit card payments:
- Success:
- Failure:
Payment Flow
- Customer selects iPay as payment method during checkout
- Customer is redirected to iPay's secure payment gateway
- Customer chooses payment channel (M-Pesa, Airtel, Card, etc.)
- Customer completes payment following iPay's interface
- Customer is redirected back to your store
- Webhook confirms payment status
API Reference
Payment Provider Options
interface IPayOptions {vid: string // iPay Vendor IDhashKey: string // iPay Hash Keylive: boolean // Production modeenabledChannels?: {mpesa?: boolean // Enable M-Pesaairtel?: boolean // Enable Airtel Moneycreditcard?: boolean // Enable Credit/Debit Cardspesalink?: boolean // Enable PesaLink}}
Webhook Endpoint
The plugin automatically creates a webhook endpoint at:
iPay will send payment status updates to this endpoint.
Payment Status Mapping
iPay Status | Description | Medusa Status |
---|---|---|
Success | AUTHORIZED | |
Pending | PENDING | |
Failed | ERROR | |
Less amount | ERROR | |
Used code | ERROR |
Development
Prerequisites
- Node.js 20+
- Medusa v2.4.0+
Setup
- Clone the repository
git clone https://github.com/your-org/medusa-payment-ipay.gitcd medusa-payment-ipay
- Install dependencies
yarn install
- Build the plugin
yarn build
- Run in development mode
yarn dev
Testing
# Run testsyarn test# Run with coverageyarn test:coverage
Production Deployment
-
Get Production Credentials:
- Register with iPay Africa
- Obtain your production Vendor ID and Hash Key
- Complete any required verification processes
-
Update Configuration:
IPAY_VID=your_production_vidIPAY_HASH_KEY=your_production_hash_keyIPAY_LIVE=true -
Enable Payment Channels:
- Configure which payment methods to accept
- For credit cards, ensure PCI compliance
- Test all payment flows
-
Webhook Configuration:
- Ensure your webhook endpoint is accessible
- Configure proper SSL certificates
- Test webhook delivery
Troubleshooting
Common Issues
-
Payment fails with "hash mismatch"
- Verify your hash key is correct
- Ensure no extra spaces in environment variables
- Check that all required parameters are included
-
Webhook not receiving callbacks
- Verify webhook URL is publicly accessible
- Check firewall settings
- Ensure proper HTTPS configuration
-
Payment gateway not loading
- Check if you're using correct iPay gateway URL
- Verify VID and hash key are valid
- Ensure live mode setting matches your credentials
Debug Mode
Enable debug logging:
// In your medusa-config.tsexport default defineConfig({projectConfig: {worker_mode: "server",// ... other config},// Add debug logginglogger: {level: "debug"}})
Contributing
Contributions are welcome! Please read our Contributing Guide for details.
Development Workflow
- Fork the repository
- Create a feature branch:
- Make your changes
- Add tests for new functionality
- Ensure all tests pass:
- Commit your changes:
- Push to the branch:
- Open a Pull Request
Support
- ๐ง Email: support@yourdomain.com
- ๐ฌ Discord: Join our community
- ๐ Issues: GitHub Issues
- ๐ Documentation: Full documentation
Related Links
License
This project is licensed under the MIT License - see the LICENSE file for details.
Acknowledgments
- iPay Africa for their payment gateway services
- Medusa team for the excellent e-commerce framework
- Contributors who help improve this plugin
โ ๏ธ Important Notes:
- Always test in sandbox mode before going live
- Ensure PCI compliance when accepting credit card payments
- Keep your hash key secure and never commit it to version control
- Regularly update the plugin to get security fixes and new features