Giter Club home page Giter Club logo

hubtelpayment's Introduction

Hubtel Merchant Account integration for Node Js

Based on https://developers.hubtel.com/documentations/merchant-account-api

About

The hubtelpayment package allows you to accept and process payments using Hubtel Merchant Account API directly in your Node js application.

Features

  • Receive mobile money
  • Send mobile money
  • Check status of transaction
  • Online checkout

Installation and Configuration

Install using npm install hubtelpayment --save

const Hubtel =  require('hubtelpayment');

const MerchantAccount = Hubtel.MerchantAccount; 
const OnlineCheckout = Hubtel.OnlineCheckout; 

// you may store and fetch these sensitive details in a config file.
const config = {
    account_number:'<account number>', 
    client_id : '<client id >', 
    client_secret :'<client_secret>'
};

let ma = new MerchantAccount(config);

Using Online Checkout feature

Let's say you are using this feature from a checkout method, you can do it like so:

// online checkout request

// sample order
 const order = {
     total : 70.00,
     items : [
        {
            name : "Bathing soap",
            description : "Bathing soap",
            quantity : 1,
            price : 50.00,
        },
        {
            name : "Washing soap",
            description : "Washing soap",
            quantity : 1,
            price : 20.00,
        }
     ]
 }

 // Initiate online checkout
 ocRequest = new OnlineCheckout.Request();
 ocRequest.invoice.description = "Invoice description";
 ocRequest.invoice.total_amount = order.total;
 ocRequest.store.name = "My Shop";
 ocRequest.store.logo_url = 'https://cb.mysite.com/img/logo.png';
 ocRequest.store.phone = "0243XXXXXX";
 ocRequest.store.postal_address = "P. O. Box 123456";
 ocRequest.store.tagline = "Best online shop ever";
 ocRequest.store.website_url = 'https://cb.mysite.com';
 ocRequest.actions.cancel_url = 'https://cb.mysite.com/callback';
 ocRequest.actions.return_url = 'https://cb.mysite.com/callback';


 order.items.forEach((item) => {
     invoiceItem = new OnlineCheckout.Item();
     invoiceItem.name = item.name;
     invoiceItem.description = item.description;
     invoiceItem.quantity = item.quantity;
     invoiceItem.unit_price = item.price;
     invoiceItem.total_price = item.price * item.quantity;
     ocRequest.invoice.addItem(invoiceItem);
 });

 ma.onlineCheckout(ocRequest)
 .then( (res) => {
     // you can redirect the user from here
    console.log(res.data);
}).catch( error => {
    console.log(error.response.data , error.response.status);
});

//  check invoice status
ma.checkInvoiceStatus('4bb4393e394343ce')
.then( (res) => {
    console.log(res.data);
}).catch( error => {
    console.log(error.response.data , error.response.status);
});

Receive Mobile Money

Here is how you request mobile money payment from say a checkout method:

// receive money 
ma.receiveMobileMoney({
    CustomerName :"test" , 
    CustomerEmail: "n/a", 
    CustomerMsisdn : '23324XXXXXXX',
    Channel:'mtn-gh',
    Amount : 0.5,
    ClientReference:'',
    Description:'test debit',
    PrimaryCallbackUrl : 'https://cb.mysite.com/callback',
    SecondaryCallbackURL : 'https://cb.mysite.com/callback'
})
.then( (res) => {
    console.log(res.data);
}).catch( error => {
    console.log(error.response.data , error.response.status);
});

License

Released under the MIT License, see LICENSE.

hubtelpayment's People

Contributors

paulmajora avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.