
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
momo-payment-lib
Advanced tools
A simple TypeScript library to integrate the MTN MoMo API for payment requests and transaction status retrieval.
A TypeScript library for integrating MTN MoMo API to manage various payment-related operations such as Request to Pay, Remittances, Transfers, and more. This library provides a simple interface to interact with the MoMo API, supporting both sandbox and production environments.
Install the package via npm:
npm install momo-payment-lib
Add the following to your .env file:
COLLECTION_API_USER_ID=your_collection_api_user_id
COLLECTION_API_KEY=your_collection_api_key
COLLECTION_PRIMARY_KEY=your_collection_primary_key
REMITTANCE_API_USER_ID=your_remittance_api_user_id
REMITTANCE_API_KEY=your_remittance_api_key
REMITTANCE_PRIMARY_KEY=your_remittance_primary_key
Replace placeholders with your MTN MoMo API credentials for each service.
Create an instance of MoMoClient with separate configurations for each product:
import { MoMoClient } from 'momo-payment-lib';
const momoClient = new MoMoClient({
collection: {
apiUserId: process.env.COLLECTION_API_USER_ID || '',
apiKey: process.env.COLLECTION_API_KEY || '',
primaryKey: process.env.COLLECTION_PRIMARY_KEY || '',
},
remittance: {
apiUserId: process.env.REMITTANCE_API_USER_ID || '',
apiKey: process.env.REMITTANCE_API_KEY || '',
primaryKey: process.env.REMITTANCE_PRIMARY_KEY || '',
},
environment: 'sandbox', // Use 'sandbox' for testing or 'production' for live
});
To request a payment:
const requestPayment = async () => {
try {
const response = await momoClient.requestPayment({
amount: 100,
currency: 'EUR',
phoneNumber: '256700123456',
reference: 'Invoice123',
});
console.log('Payment requested:', response);
} catch (error) {
console.error('Error requesting payment:', error.message);
}
};
requestPayment();
| Parameter | Type | Description |
|---|---|---|
amount | number | Amount to charge. |
currency | string | Currency code (e.g., "UGX", "EUR"). |
phoneNumber | string | Phone number (MSISDN format). |
reference | string | Your reference number for tracking. |
{
"referenceId": "unique-identifier"
}
To check the status of a payment:
const checkPaymentStatus = async () => {
try {
const status = await momoClient.getPaymentStatus('reference-id');
console.log('Payment status:', status);
} catch (error) {
console.error('Error fetching status:', error.message);
}
};
checkPaymentStatus();
{
"amount": "100.00",
"currency": "EUR",
"status": "SUCCESSFUL",
"payer": {
"partyIdType": "MSISDN",
"partyId": "256700123456"
},
"reason": null
}
To send money via the remittance API:
const sendMoney = async () => {
try {
const response = await momoClient.sendRemittance({
amount: 50,
currency: 'USD',
phoneNumber: '256700123456',
externalId: 'Remittance123',
});
console.log('Remittance sent:', response);
} catch (error) {
console.error('Error sending remittance:', error.message);
}
};
sendMoney();
Here’s an end-to-end integration example:
import { MoMoClient } from 'momo-payments-lib';
import dotenv from 'dotenv';
dotenv.config();
const momoClient = new MoMoClient({
collection: {
apiUserId: process.env.COLLECTION_API_USER_ID || '',
apiKey: process.env.COLLECTION_API_KEY || '',
primaryKey: process.env.COLLECTION_PRIMARY_KEY || '',
},
remittance: {
apiUserId: process.env.REMITTANCE_API_USER_ID || '',
apiKey: process.env.REMITTANCE_API_KEY || '',
primaryKey: process.env.REMITTANCE_PRIMARY_KEY || '',
},
environment: 'sandbox',
});
const processTransaction = async () => {
try {
const paymentResponse = await momoClient.requestPayment({
amount: 100,
currency: 'UGX',
phoneNumber: '256700123456',
reference: 'Invoice001',
});
console.log('Payment Requested:', paymentResponse);
const paymentStatus = await momoClient.getPaymentStatus(paymentResponse.referenceId);
console.log('Payment Status:', paymentStatus);
} catch (error) {
console.error('Error:', error.message);
}
};
processTransaction();
This library is released under the MIT License.
FAQs
A simple TypeScript library to integrate the MTN MoMo API for payment requests and transaction status retrieval.
The npm package momo-payment-lib receives a total of 1 weekly downloads. As such, momo-payment-lib popularity was classified as not popular.
We found that momo-payment-lib demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.