leja-recharge-node-sdk
v0.1.2
Published
Node.js SDK for Leja Recharge API
Maintainers
Readme
Leja Recharge Node.js SDK
A Node.js SDK for interacting with the Leja Recharge API.
Documentation
Take a look at the API docs here
Installation
npm install leja-recharge-node-sdk
# or
yarn add leja-recharge-node-sdkAuthentication
The SDK uses Basic Authentication with your Client ID and API key (Both found on your dashboard). You'll need both credentials to initialize the client:
import { LejaRechargeClient } from 'leja-recharge-node-sdk';
// Initialize the client with your credentials
const client = new LejaRechargeClient({
clientId: 'your_client_id',
apiKey: 'your_api_key'
});Quick Start
import { LejaRechargeClient, AirtimeRecipient } from 'leja-recharge-node-sdk';
// Initialize the client with your credentials
const client = new LejaRechargeClient({
clientId: 'your_client_id',
apiKey: 'your_api_key'
});
// Purchase airtime
const recipients: AirtimeRecipient[] = [
{
phoneNumber: '+254712345678',
amount: 10.0,
country: 'KE'
}
];
const transaction = await client.purchaseAirtime(
'+254712345678',
recipients,
true,
'https://your-callback-url.com/webhook'
);
// Get transaction details
const transactionDetails = await client.getTransaction(transaction.trackingId);
// Get account balance
const balance = await client.getBalance();
// Get supported countries
const countries = await client.getCountries(1, 20);Features
- Purchase airtime for multiple recipients
- Get transaction details
- Check account balance
- List supported countries
- Async support for airtime purchases
- Webhook callbacks for async transactions
- Comprehensive error handling
- TypeScript support with type definitions
- Request and response validation using Zod
Error Handling
The SDK provides custom exceptions for different error scenarios:
import {
LejaRechargeError,
AuthenticationError,
ValidationError,
APIError,
NetworkError
} from 'leja-recharge-node-sdk';
try {
const client = new LejaRechargeClient({
clientId: 'invalid_client_id',
apiKey: 'invalid_api_key'
});
} catch (error) {
if (error instanceof AuthenticationError) {
console.error(`Authentication failed: ${error.message}`);
}
}Exception Types
LejaRechargeError: Base exception class for all SDK errorsAuthenticationError: Raised when authentication failsValidationError: Raised when input validation failsAPIError: Raised when the API returns an error responseNetworkError: Raised when network communication fails
TypeScript Support
The SDK is written in TypeScript and provides type definitions for all models:
import {
AirtimeRecipient,
TransactionResponse,
BalanceResponse,
CountryResponse,
PaginatedResponse
} from 'leja-recharge-node-sdk';Development
Clone the repository
git clone https://github.com/Asilimia/leja-recharge-node-sdk.git cd leja-recharge-node-sdkInstall dependencies:
npm install # or yarn installBuild the project:
npm run build # or yarn buildRun tests:
npm test # or yarn test
Testing
The test suite includes:
- Unit tests for all SDK functionality
- Mock tests for API interactions
- Model validation tests
- Error handling tests
- Integration test examples
Contributing
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
License
MIT License
