African Mobile Money SDK - M-Pesa, MTN MoMo, Airtel Money
# M-Pal - African Mobile Money SDK
🚀 The unified SDK for African mobile money payments
M-Pesa • MTN MoMo • Airtel Money — one clean API
---
## ✨ Features
- **M-Pesa Kenya** - STK Push, B2C, C2B, Reversals
- **MTN MoMo** - RequestToPay, Collections, Transactions
- **Airtel Money** - Payments, Refunds, B2C
- **Offline Queue** - Survives network failures, auto-retry
- **TypeScript** - 100% type-safe with full autocomplete
- **Zero Dependencies** - Only axios, zod, p-queue
---
## 📦 Installation
```bash
npm install m-pal
# or
yarn add m-pal
```
---
## 💻 Quick Start
```javascript
const { MPal } = require('m-pal');
const mp = new MPal({
environment: 'sandbox',
providers: {
'mpesa-ke': {
consumerKey: process.env.MPESA_CONSUMER_KEY,
consumerSecret: process.env.MPESA_CONSUMER_SECRET,
shortCode: process.env.MPESA_SHORT_CODE,
passkey: process.env.MPESA_PASSKEY,
callbackUrl: '
your-app.com',
},
},
});
// Make a payment
async function pay() {
try {
const result = await mp.pay({
provider: 'mpesa-ke',
amount: 100,
phone: '254712345678',
reference: 'ORDER-001',
description: 'Product payment',
});
console.log('Payment result:', result);
// { success: true, transactionId: '...', status: 'pending', ... }
} catch (error) {
console.error('Payment failed:', error.message);
}
}
pay();
```
---
## 🛠️ Development Setup
1. Clone the repository:
```bash
git clone
github.com
cd m-pal
```
2. Install dependencies:
```bash
npm install
```
3. Copy the environment variables file:
```bash
cp .env.example .env
# Edit .env with your configuration
```
4. Build the project:
```bash
npm run build
```
5. Run tests:
```bash
npm test
```
---
## 📚 API Reference
### MPal Class
```javascript
const mp = new MPal(config)
```
#### Configuration
```javascript
const config = {
environment: 'sandbox', // or 'production'
providers: {
'mpesa-ke': { /* M-Pesa config */ },
'mtn-momo': { /* MTN config */ },
'airtel-money': { /* …