A unified backend API that standardizes payment across multiple African mobile money providers (MTN, Airtel Money, M-Pesa).
MobiPay Africa
Unified Mobile Money Payment SDK for Africa
Supports M-Pesa, MTN Mobile Money, Airtel Money, Zain, and extensible for more.
MobiPay Africa provides a consistent, simple-to-use API that abstracts the differences across African mobile money providers, allowing you to:
- Process payments
- Verify transactions
- Check balances
- Swap providers dynamically
Build gateways, backend apps, and integrations faster
## Features
- Strategy Pattern Architecture (plug-and-play providers)
- Supports multiple African mobile money operators
- Unified API interface
- Secure API requests via axios
- Written in TypeScript
- Dual support for TypeScript and CommonJS
- Easy to extend and customize
## Installation
```bash
npm install mobipay-africa
```
Or with Yarn:
```bash
yarn add mobipay-africa
```
### Directory Structure
```
src/
├── core/
│ ├── PaymentProvider.ts
│ └── PaymentContext.ts
├── providers/
│ ├── MpesaProvider.ts
│ ├── MtnProvider.ts
│ ├── AirtelProvider.ts
│ └── ZainProvider.ts
├── utils/
│ ├── httpClient.ts
│ └── logger.ts
└── index.ts
```
## Usage
1. Import and Initialize a Provider
Example: M-Pesa
```js
import { PaymentContext, MpesaProvider } from "mobipay-africa";
const mpesa = new MpesaProvider({
apiKey: process.env.MPESA_API_KEY!,
shortcode: "123456",
baseUrl: "
api.safaricom.co.ke"
});
const payment = new PaymentContext(mpesa);
```
2. Initiate a Payment
```js
await payment.initiatePayment({
amount: 100,
phone: "254712345678",
reference: "ORDER12345"
});
```
3. Verify a Payment
```js
const status = await payment.verifyPayment("ORDER12345");
console.log(status.data);
```
4. Check Balance
```js
const balance = await payment.checkBalance();
console.log(balance.data);
🔌 Switching Providers (Strategy Pattern)
import { PaymentContext, MpesaProvider, MtnProvider } from "mobipay-africa";
const context = new PaymentContext(new MpesaProvider(mpesaConfig));
await context.initiatePayment({ amount: 150, phone: "254. …