mobilenig
v2.0.1
Published
A package designed to quickly handle Mobilenig Enterprise services, providing a seamless integration with a range of discounted offerings, including airtime, data, cable TV subscriptions, electricity payments, and exam pins in Nigeria. This package is ide
Maintainers
Readme
MobileNIG Enterprise Node.js SDK
A robust, secure, and fully type-safe Node.js package for integrating MobileNIG Enterprise services. Seamlessly purchase discounted mobile offerings and pay utility bills in Nigeria.
This SDK is fully backward compatible with Version 1 of this package while introducing a modern, modular design for enterprise workflows.
Features
- Zero Dependencies: Built on Node.js's native
fetch(requires Node 18+). - TypeScript Ready: Full type definitions (
index.d.ts) included out of the box. - Robust Network Resilience: Built-in automatic request retries and timeouts for network safety.
- Flexible Configuration: Initialize keys programmatically or fall back to environment variables.
- Complete Endpoint Coverage: Airtime, data, cable TV, electricity, and exam PINs (WAEC, NECO, JAMB).
Installation
npm install mobilenigEnvironment Variables (Optional)
You can set these environment variables to configure the SDK without hardcoding keys:
MOBILENIG_PUBLIC_KEY=your_public_key
MOBILENIG_SECRET_KEY=your_secret_key
MOBILENIG_BASE_URL=https://enterprise.mobilenig.com/api/v2/ # OptionalQuick Start (Modern API)
const Mobilenig = require('mobilenig');
// Fallback to environment variables if keys are omitted
const mobilenig = new Mobilenig();
async function run() {
try {
// 1. Check Balance
const balanceRes = await mobilenig.control.getBalance();
console.log(`Current Balance: ${balanceRes.details.balance}`);
// 2. Buy Airtime
const airtimeRes = await mobilenig.recharges.buyAirtime({
service_id: 'BAD', // MTN
trans_id: 'unique_tx_12345',
service_type: 'STANDARD',
phoneNumber: '08030000000',
amount: 100
});
console.log('Airtime Transaction status:', airtimeRes.details.status);
} catch (error) {
console.error('Request failed:', error.message);
}
}
run();Backward Compatibility (Version 1 Support)
All methods from the original SDK remain fully supported with unchanged signatures, return formats, and error behaviors:
Check Wallet Balance
const balance = await mobilenig.getBalance();
console.log(`Balance: ${balance}`); // returns number or error objectBuy Data
await mobilenig.buyData({
phoneNumber: '08123456789',
network: 'mtn',
amount: 273,
value: '1GB',
trans_id: 'tx_987654321',
service_type: 'SME'
});Buy Electricity
await mobilenig.buyLight({
service: 'ikejaPrepaid',
amount: 1000,
meter_number: '04042404048',
trans_id: 'tx_88776'
});Query Transaction Status
const details = await mobilenig.query_trans('tx_88776');
console.log('Transaction Details:', details);Modern API Reference (v2 Modules)
For a cleaner separation of concerns, the SDK exposes two distinct sub-services:
mobilenig.control
Exposes account management, wallet status, and service health endpoints.
getBalance(): Get wallet balance.getUniqueAccountDetails(): Get virtual account details for wallet funding.getWalletHistory(page, perPage): Retrieve transaction log.searchWalletHistory(transId): Search log by transaction ID.getServicesStatus(serviceId, requestType): Check if a provider is online.
mobilenig.recharges
Exposes raw billing operations. Allows separate validation and recharge calls.
validateCustomer({ service_id, customerAccountId, requestType }): Validates smartcard/meter numbers.getPackages({ service_id, requestType }): Fetches available variations and prices.recharge(payload): Submits custom raw transaction payloads.queryTransaction(transId): Checks transaction status.buyAirtime({ service_id, trans_id, service_type, phoneNumber, amount })buyData({ service_id, trans_id, service_type, beneficiary, code, amount })buyCable({ service_id, trans_id, smartcardNumber, amount, productCode, customerName })buyEducation({ service_id, trans_id, quantity, amount, productCode })buyJamb({ trans_id, confirmationCode, phoneNumber, productCode, amount })buySpectranet({ trans_id, productCode, quantity, amount })
Error Handling
The modern endpoints throw detailed, structured errors:
const {
MobilenigError,
MobilenigValidationError,
MobilenigNetworkError
} = require('mobilenig/src/errors');
try {
await mobilenig.recharges.buyAirtime({ ... });
} catch (error) {
if (error instanceof MobilenigValidationError) {
console.error('Invalid parameters:', error.message);
} else if (error instanceof MobilenigNetworkError) {
console.error(`Network status ${error.statusCode}:`, error.message);
} else {
console.error('API Error:', error.message);
}
}License
MIT License. Developed by Ezekiel Adejobi.
