npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

mobilevtu-sdk

v1.0.1

Published

client for MobileVTU API - Mobile airtime and data topup services

Downloads

139

Readme

MobileVtu SDK Documentation

Overview The mobilevtu-sdk is a JavaScript library designed to interact with the MobileVTU API, enabling users to perform various mobile top-up operations, check balances, and manage transactions easily.

Installation

To install the SDK, run the following command:

npm install mobilevtu-sdk

Example Usage

To use the Mobile VTU SDK, you can import the MobileVtuClient and create an instance as shown below:

import { MobileVtuClient } from 'mobilevtu-sdk';

async function example() {
  const client = new MobileVtuClient({
    apiKey: 'YOUR_API_KEY',
    apiToken: 'YOUR_API_TOKEN'
  });

  // Check balance
  const balance = await client.checkBalance();
  console.log('Balance:', balance);

  // Fetch data plans for an operator
  const dataPlans = await client.getDataPlans("9mobile");
  console.log('Data Plans:', dataPlans);
}

example().catch(console.error);

API Methods

| Method Name | Description | |-----------------------------------------|---------------------------------------------------------------------| | checkBalance(currency) | Checks the balance of the specified currency (default: NGN). | | getDataPlans(operator) | Fetches data plans for a specific operator. | | checkOperator(phone) | Checks the network operator for a given phone number. | | topup(request) | Tops up a specified account. | | bulkTopup(requests) | (Not available directly, handled in a different manner.) | | getTransactionStatus(transactionId) | Retrieves the status of a specific transaction. | | listTransactions() | Lists all transactions made. | | listSupportedOperators() | Lists all supported operators. | | listMethods() | Lists all available methods and their descriptions. |

Method Details

checkBalance(currency)

Parameters:

  • currency (optional): The currency to check balance for (default is 'NGN').

Returns: The current balance in the specified currency.


getDataPlans(operator)

Parameters:

  • operator: The operator for which to fetch data plans (e.g., 'mtn', 'airtel').

Returns: A list of available data plans for the specified operator.


checkOperator(phone)

Parameters:

  • phone: The phone number to check the operator for.

Returns: The network operator for the given phone number.


topup(request)

Parameters:

  • request: An object containing the phone number, amount, and operator details.

Returns: The response from the top-up operation.


bulkTopup(requests)

Description: This method is not available directly in the API. Adjustments may be needed in implementation.


getTransactionStatus(transactionId)

Parameters:

  • transactionId: The ID of the transaction to check.

Returns: The status of the specified transaction.


listTransactions()

Returns: A list of all transactions made.


listSupportedOperators()

Returns: A list of supported operators such as MTN, Airtel, Glo, and 9mobile.


listMethods()

Returns: An array of all available methods with descriptions.


Error Handling

Make sure to handle errors in your implementation. The SDK may throw errors for various reasons, such as invalid parameters or network issues. Use try-catch blocks to manage these exceptions effectively.

Example of Error Handling

try {
  const balance = await client.checkBalance();
  console.log('Balance:', balance);
} catch (error) {
  console.error('Error fetching balance:', error.message);
}

Error Handling

Make sure to handle errors in your implementation. The SDK may throw errors for various reasons, such as invalid parameters or network issues. Use try-catch blocks to manage these exceptions effectively.

Example of Error Handling

async function example() {
  const client = new MobileVtuClient({
    apiKey: 'YOUR_API_KEY',
    apiToken: 'YOUR_API_TOKEN'
  });

  try {
    const balance = await client.checkBalance();
    console.log('Balance:', balance);
  } catch (error) {
    console.error('Error checking balance:', error);
  }
}

Conclusion This documentation provides a comprehensive overview of the mobilevtu-sdk. With its straightforward methods and clear structure, it allows for easy integration with the MobileVTU API for mobile top-up services.