@strongmb/node
v1.0.0
Published
Official Node.js SDK for the Strongmb API — Nigeria's #1 bill payment platform.
Maintainers
Readme
Strongmb Node.js SDK
Official Node.js SDK for the Strongmb API — Nigeria's #1 bill payment platform.
For the full API reference and endpoint details, visit developers.strongmb.ng.
Requirements
- Node.js 18+
Installation
npm install @strongmb/nodeQuick Start
const { Strongmb } = require('@strongmb/node');
const strongmb = new Strongmb('your-api-key');
const response = await strongmb.data.purchase({
phone: '08012345678',
productCode: 'smb_mtn_sme_1gb_30days',
reference: 'MYAPP' + Date.now(),
});
if (response.successful()) {
console.log('Data sent! Reference:', response.data().reference);
} else if (response.processing()) {
console.log('Processing — poll by reference to check status.');
} else if (response.failed()) {
console.log('Transaction failed. Contact support if wallet was debited.');
}Authentication
Get your API key from the Developer tab in your Strongmb dashboard.
// Live mode
const strongmb = new Strongmb('your-api-key');
// Sandbox / test mode
const strongmb = new Strongmb('your-api-key', { sandbox: true });Data
// List all available data plans and product codes
const response = await strongmb.data.plans();
const billers = response.data().billers;
// Purchase a data plan
const response = await strongmb.data.purchase({
phone: '08012345678',
productCode: 'smb_mtn_sme_1gb_30days',
reference: 'MYAPP_UNIQUE_REF_001',
});Airtime
// List all airtime providers and product codes
const response = await strongmb.airtime.plans();
// Top up airtime
const response = await strongmb.airtime.purchase({
phone: '08012345678',
productCode: 'smb_mtn_vtu',
amount: '100',
reference: 'MYAPP_UNIQUE_REF_002',
});Account
// Authenticated user profile
const response = await strongmb.account.user();
// Wallet balances
const response = await strongmb.account.wallets();
// Transaction history
const response = await strongmb.account.transactions();
// Single transaction by reference
const response = await strongmb.account.transaction('MYAPP_UNIQUE_REF_001');Response
Every method returns a Response object:
response.ok() // bool — true when the API status is successful
response.message() // string — human-readable message from the API
response.data() // object — the response payload
response.code() // string — machine-readable code (e.g. TRANSACTION_SUCCESSFUL)
response.traceId() // string — use this when contacting support
response.httpStatus() // number — HTTP status code
response.toObject() // object — full raw response
// Purchase transaction helpers
response.successful() // true when code === TRANSACTION_SUCCESSFUL
response.processing() // true when still being processed — poll by reference
response.failed() // true when transaction failed — wallet may have been debitedHandling all purchase outcomes
if (response.successful()) {
const data = response.data();
console.log('Done! Reference:', data.reference);
} else if (response.processing()) {
// Request accepted but not yet fulfilled.
// Poll account.transaction(reference) until it resolves.
console.log('Processing — reference:', response.data().reference);
} else if (response.failed()) {
// Transaction was attempted but failed.
// Provide the trace ID to support if the wallet was debited.
console.log('Failed. Trace ID:', response.traceId());
}Error Handling
const { Strongmb, ApiError, AuthError, StrongmbError } = require('@strongmb/node');
try {
const response = await strongmb.data.purchase({ ... });
} catch (err) {
if (err instanceof AuthError) {
// HTTP 401 — invalid or missing API key
console.error('Invalid API key.');
} else if (err instanceof ApiError) {
// HTTP 4xx / 5xx — the API returned an error
console.error(err.message); // Human-readable message
console.error(err.getApiCode()); // e.g. ERR_INSUFFICIENT_BALANCE
console.error(err.getHttpStatus()); // e.g. 402
console.error(err.getTraceId()); // Send this to [email protected]
} else if (err instanceof StrongmbError) {
// Network error or unexpected failure
console.error('Network error:', err.message);
}
}Exception hierarchy
StrongmbError — base: network errors, unexpected failures
└── ApiError — HTTP 4xx/5xx returned by the API
└── AuthError — HTTP 401: invalid or missing API keyNotes
- Always use a unique
referenceper transaction — duplicate references will be rejected. - References must contain only
a-zA-Z0-9characters. No spaces, dashes, or special characters. - Call
strongmb.data.plans()orstrongmb.airtime.plans()to discover validproductCodevalues before purchasing. - All methods are
asyncand return a Promise — useawaitor.then().
Links
License
MIT
