A unified TypeScript SDK for seamless integration with African payment providers. Type-safe, reliable, and built for production.
npm install afrimomo-sdk
# or
pnpm add afrimomo-sdk
# or
yarn add afrimomo-sdkThe SDK requires Node.js 18.0.0 or higher and includes full TypeScript type definitions.
import { AfromomoSDK } from "afrimomo-sdk";
// Initialize the SDK
const sdk = new AfromomoSDK({
environment: "sandbox", // or "production"
pawapay: {
apiToken: "your-pawapay-token"
},
paychangu: {
secretKey: "your-paychangu-secret"
}
});
// Use PawaPay
const payment = await sdk.pawapay.payments.initiate({
depositId: "order-123",
amount: "50.00",
msisdn: "260971234567",
country: "ZMB",
returnUrl: "https://your-app.com/callback",
statementDescription: "Payment for services",
language: "EN",
reason: "Service payment"
});
// Use PayChangu
const operators = await sdk.paychangu.getMobileMoneyOperators();The SDK supports both sandbox and production environments. Use sandbox credentials during development and switch to production when ready to process real payments.
import { AfromomoSDK, Environment } from "afrimomo-sdk";
const sdk = new AfromomoSDK({
environment: Environment.SANDBOX, // or Environment.PRODUCTION
pawapay: {
apiToken: process.env.PAWAPAY_TOKEN
},
paychangu: {
secretKey: process.env.PAYCHANGU_SECRET
}
});Security Tip: Never commit API keys to version control. Use environment variables or secure configuration management.
// Request a deposit
const deposit = await sdk.pawapay.payments.initiate({
depositId: "unique-deposit-id",
amount: "100.00",
msisdn: "260971234567",
country: "ZMB",
returnUrl: "https://your-app.com/callback",
statementDescription: "Online purchase",
language: "EN",
reason: "Payment for goods"
});
// Get deposit details
const details = await sdk.pawapay.payments.getDeposit(depositId);
// Resend callback
await sdk.pawapay.payments.resendCallback(depositId);// Send a payout
const payout = await sdk.pawapay.payouts.send({
payoutId: "payout-123",
amount: "50.00",
msisdn: "260701234567",
country: "ZMB",
statementDescription: "Withdrawal"
});
// Send bulk payouts
const bulkPayout = await sdk.pawapay.payouts.sendBulk([
{
payoutId: "payout-001",
amount: "25.00",
msisdn: "260701234567",
country: "ZMB"
},
{
payoutId: "payout-002",
amount: "30.00",
msisdn: "260709876543",
country: "ZMB"
}
]);
// Get payout status
const status = await sdk.pawapay.payouts.getStatus(payoutId);// Get all wallet balances
const balances = await sdk.pawapay.wallets.getBalances();
// Get balance for specific country
const zambiaBalance = await sdk.pawapay.wallets.getCountryBalance("ZMB");// Initiate hosted checkout
const payment = await sdk.paychangu.initiatePayment({
amount: 1000,
currency: "MWK",
tx_ref: "order-456",
email: "customer@example.com",
first_name: "John",
last_name: "Doe",
callback_url: "https://your-app.com/webhook",
return_url: "https://your-app.com/success"
});
// Verify transaction
const verification = await sdk.paychangu.verifyTransaction(tx_ref);
// Initiate direct charge
const directCharge = await sdk.paychangu.initiateDirectChargePayment({
amount: 5000,
currency: "MWK",
chargeId: "charge-789",
accountInfo: {
email: "customer@example.com",
first_name: "John",
last_name: "Doe"
}
});// Get mobile money operators
const operators = await sdk.paychangu.getMobileMoneyOperators();
// Send mobile money payout
const payout = await sdk.paychangu.mobileMoneyPayout({
amount: 2000,
currency: "MWK",
recipient_phone: "265991234567",
operator_id: "operator-uuid",
reference: "payout-123"
});
// Get payout details
const details = await sdk.paychangu.getMobilePayoutDetails(reference);// Get supported banks
const banks = await sdk.paychangu.getSupportedBanks("MWK");
// Process bank transfer
const transfer = await sdk.paychangu.processBankTransfer({
amount: 10000,
currency: "MWK",
bank_id: "bank-uuid",
account_number: "123456789",
account_name: "John Doe"
});
// Send bank payout
const bankPayout = await sdk.paychangu.bankPayout({
amount: 5000,
currency: "MWK",
account_number: "987654321",
bank_uuid: "bank-uuid",
reference: "bank-payout-456"
});All types are exported from the main package. No deep imports needed:
// ✅ Correct way
import type {
ActiveConfigResponse,
PayChanguOperatorsResponse,
PayChanguTypes,
PawaPayTypes
} from "afrimomo-sdk";
// ❌ Avoid deep imports
import type { ActiveConfigResponse } from "afrimomo-sdk/dist/...";
Vwaza Multimedia uses Afrimomo SDK in production