khanya-momo
v1.0.0
Published
A Node.js library for MTN MoMo sandbox integration. Designed for developers to test payments using MTN MoMo sandbox environment.
Maintainers
Readme
Khanya MoMo
A Node.js library for MTN MoMo sandbox integration, designed for developers to test payments using the MTN MoMo sandbox environment.
This library simplifies creating API users, generating tokens, sending payment requests, and checking transaction statuses in a modular and reusable way.
Installation
npm install khanya-momo
# or using yarn
yarn add khanya-momo
Features
- ✅ Create sandbox API users
- ✅ Generate API keys and access tokens
- ✅ Request payments (sandbox)
- ✅ Check transaction status
- ✅ Modular and easy to integrate
Usage
const { createMomoUser, getToken, requestToPay, getTransactionStatus } = require('khanya-momo');
(async () => {
try {
// 1️⃣ Create new API user + key
const { userReferenceId, apiKey } = await createMomoUser();
// 2️⃣ Generate access token
const token = await getToken({ apiUser: userReferenceId, apiKey });
console.log('🔑 Access Token:', token);
// 3️⃣ Send payment request
const payment = await requestToPay({
token,
amount: '100',
currency: 'EUR',
externalId: '123456789',
partyId: '256774123456',
payerMessage: 'Payment Test',
payeeNote: 'Thanks!',
});
console.log('💰 Payment Response:', payment);
// 4️⃣ Check transaction status
const status = await getTransactionStatus(payment.referenceId, { token });
console.log('🧾 Transaction Status:', status);
} catch (error) {
console.error('❌ Error:', error.response?.data || error.message);
}
})();
API Reference
License
MIT © Dlamini Khanyakwezwe
