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

mavapay-sdk

v0.0.1

Published

JavaScript SDK for MavaPay API

Downloads

70

Readme

MavaPay JavaScript SDK

MavaPay SDK is a JavaScript library that provides an interface for interacting with the MavaPay API. It allows users to send Bitcoin and receive the equivalent fiat amount in their bank accounts, using the Bitcoin Lightning Network for low fees and quick transfers.

Table of Contents

Installation

To install the MavaPay SDK, simply add it to your project:

npm install mavapay-sdk

The SDK includes all dependencies, so you don’t need to install any additional packages.

Usage

  1. Initialize the SDK: Start by creating an instance of MavaPay with your API key and base URL (either staging or production).
const MavaPay = require('mavapay-sdk');

const apiKey = 'your-api-key';
const baseURL = 'https://staging.mavapay.co/api';

const mavapay = new MavaPay(baseURL, apiKey);
  1. Using API Methods: Use the SDK methods for various functionalities like retrieving bank codes, creating quotes, or viewing transactions.
// Example: Fetching Bank Codes
mavapay.bank.getBankCode()
  .then(data => console.log('Bank Codes:', data))
  .catch(error => console.error('Error:', error));

API Reference

Bank

  • getBankCode: Retrieves a list of bank codes.
const bankCodes = await mavapay.bank.getBankCode();
  • nameEnquiry: Verifies an account number and bank code to fetch account name details.
const accountInfo = await mavapay.bank.nameEnquiry('0100242011', '000013');

Quote

  • createQuote: Creates a new quote for transferring Bitcoin to fiat.
const newQuote = await mavapay.quote.createQuote({
  amount: 300000,
  sourceCurrency: Currency.BTC,
  targetCurrency: Currency.NGN,
  paymentMethod: PaymentMethod.LIGHTNING,
  paymentCurrency: Currency.NGN,
});
  • acceptQuote: Accepts a quote with additional banking details.
const acceptedQuote = await mavapay.quote.acceptQuote({
  id: 'quote_id',
  autopayout: true,
  bankAccountNumber: '12345678',
  bankCode: '000013',
  bankAccountName: 'John Doe',
  memo: 'Payment for services',
  descriptionHash: 'example_hash',
});

Order

  • getOrder: Retrieves details of a specific order by ID.
const orderDetails = await mavapay.order.getOrder('order_id');
  • getAllOrders: Retrieves a list of all orders.
const allOrders = await mavapay.order.getAllOrders();

Transaction

  • getAllTransactions: Retrieves a list of all transactions.
const transactions = await mavapay.transaction.getAllTransactions();
  • getTransaction: Retrieves details of a specific transaction by ID.
const transaction = await mavapay.transaction.getTransaction('transaction_id');

Enums

Currency

Currency provides constants for supported currencies in MavaPay transactions.

  • BTC: Bitcoin
  • NGN: Nigerian Naira
  • KES: Kenyan Shilling

Example usage:

const Currency = require('mavapay-sdk/enums/currency');
console.log(Currency.BTC); // 'BTC'

Payment Method

PaymentMethod provides constants for available payment methods.

  • LIGHTNING: Bitcoin Lightning Network
  • ONCHAIN: On-chain Bitcoin transfer
  • USDT: USDT (Tether)

Example usage:

const PaymentMethod = require('mavapay-sdk/enums/paymentMethod');
console.log(PaymentMethod.LIGHTNING); // 'LIGHTNING'

Error Handling

The MavaPay SDK has built-in error handling for:

  • HTTP Errors: Provides specific messages for errors like 400 (Bad Request), 401 (Unauthorized), 404 (Not Found), etc.
  • Network Errors: Handles issues where the request cannot reach the server.
  • Timeout Errors: Configurable timeout with a default of 10 seconds, with error handling for request timeouts. Example of catching errors:
mavapay.bank.getBankCode()
  .then(data => console.log('Bank Codes:', data))
  .catch(error => {
    if (error.response) {
      console.error('HTTP Error:', error.response.status, error.response.data);
    } else if (error.code === 'ECONNABORTED') {
      console.error('Timeout Error: The request took too long to complete.');
    } else {
      console.error('Error:', error.message);
    }
  });

License