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

@bigboblittle/hubtelmomo

v1.0.7

Published

Receive hubtel payments on all networks

Downloads

5

Readme

RecieveHubtelMobileMoney version

This is a handy unofficial nodejs package for Hubtel's Recieve Money API. This package will help you to Recieve Mobile Money payments from Users of all networks (mtn,voda,tigo,airtel)gh into your app/system.

Note: Kindly note that, this package does not work for any other hubtel payment service except Recieving Money from Users of your app. In short, this package will take care of sending a mobile money prompt to the users phone.

Installation

`npm i --save @bigboblittle/hubtelmomo`

Setup

Please follow the official Hubtel docs to get your API Keys, API secret and merchant Account Number

Required Fields

**fullname** -- fullname on user's mobile money wallet  
**phonenumber** -- mobile money account phonenumber // must be a string of 10 digits  
**amount** -- Amount of money to be deducted from users wallet  
**merchantNumber** -- Your hubtel merchant number  
**PrimaryCallbackUrl** Your primary callback url

Needed, but not required
ClientReference
a unique code on your end to identify each transaction. i've used shortid to auto generate a unique code. you can leave it or replace this field with your own unique key to identify transaction description
A brief description of the transaction

const RecieveMobileMoney = require('../index').RecieveMobileMoney;

  const hubtelConfig = {
    apiKey: "Your-Api-Key",
    apiSecret: "Replace-With-Api-Secret",
    PrimaryCallbackUrl: "set your callback url, ",
    FeesOnCustomer: false , //i've set to false
    merchantNumber: "HM..........",
    description: "Description of request", //not required
   ClientReference: "Your-client-request" //i've used a package by name shortid to auto generate reference, u can override it here
}

Please copy the above code and replace it with your own keys, it's a good practice to load them from your .env files

usage

`RecieveMobileMoney(fullname,phonenumber,amount, hubtelConfig);`

Example using express js

const app = require('express')();
const RecieveMobileMoney = require('../index').RecieveMobileMoney;   *//<-- require ('packagename').RecieveMobileMoney
const ErrorCodes = require('../index').mobileMoneyErorrCodesAndResponse;  *//<---- i will talk about this later


  const hubtelConfig = {
    apiKey: "Your-Api-Key",
    apiSecret: "Replace-With-Api-Secret",
    PrimaryCallbackUrl: "set your callback url, ",
    FeesOnCustomer: false , //i've set to false
    merchantNumber: "HM..........",
    description: "Description of request", //not required
   ClientReference: "Your-client-request" //i've used a package by name shortid to auto generate reference, u can override it here
}

fullname= "Big Bob Little";
phonenumber = "0541234567",  *//always make sure the phonenumber is a 10 digit string
amount = "1";


app.post('/test1', async(req,res,next) => {

    try {
        let test  = await RecieveMobileMoney(fullname,phonenumber,amount, hubtelConfig);
        console.log(test); // you'll get the response from hubtel here
       
    } catch (error) {
        console.log(error);

    }
})

Handling Errors and ResponseCode

Hubtel provides a ResponseCode to identify the status of each transaction whether successful or not with a message. The response codes are plenty, depending on which of their payment services you're using. i've taken care of all response codes starting with 2xxx and few of 3xxx You may be interested in passing back those responses to your users. In such case, you can add

`const ErrorCodes = require('../index').mobileMoneyErorrCodesAndResponse;`  //<---- i promised to talk about 

Each hubtel response after every transaction has a ResponseCode attached to it, so you can do something like this

app.post('/test1', async(req,res,next) => {

    try {
        let test  = await RecieveMobileMoney(fullname,phonenumber,amount, hubtelConfig);
        console.log(test); // you'll get the response from hubtel here
         
         let errorCodes = ErrorCodes(test.ResponseCode); *//<------- like this *
        res.json(errorCodes)                              *//<----- this will give you the a msg explaining the error code* 
       
    } catch (error) {
        console.log(error);

    }
})

Custom Errors

In order to differentiate the errors of this package from other development errors, i preceeded all errors return from this package with
BOBLITTLE-RecieveMobileMoney:::
followed by the error itself
BOBLITTLE-RecieveMobileMoney:::\n Please provide all params {fullname,phonenumber,amount and config}