-
Notifications
You must be signed in to change notification settings - Fork 1
Home
Nana Kwame Zoe edited this page Oct 14, 2018
·
8 revisions
npm i --save hubtelmobilepayment
See Hubtel Documentation for data format. Hubtel Docs Setup Api Keys gotten from hubtel Account.Hubtel Docs
var hubtelpayment = require('hubtelmobilepayment');
var hubtel_pay = new hubtelpayment({
clientid: 'bxd34kou',
secretid: 'rfiz45dm',
merchantaccnumber: 'HM325170009'
})It is most advicable to put keys in environmental variables.
After initialization.
var receivedata = {
"CustomerName": "Customer Name",
"CustomerMsisdn": "233264545335",
"CustomerEmail": "customeremail@gmail.com",
"Channel": "airtel-gh",
"Amount": 0.8,
"PrimaryCallbackUrl": "https://hubtelpayment.herokuapp.com/api/v1/moneycallback", /////example callback
"Description": "T Shirt"
}
hubtel_pay.ReceiveMobileMoney(receivedata).then(function(data) {
console.log(data)
})
After initialization. Check Hubtel Docs For Meaning To Error Codes Error Codes
var sendmoneydata = {
"RecipientName": "Recipient Name",
"RecipientMsisdn": "233264545335",
"CustomerEmail": "recipientemail@gmail.com",
"Channel": "airtel-gh",
"Amount": 0.5,
"PrimaryCallbackUrl": "https://hubtelpayment.herokuapp.com/api/v1/moneycallback" , //////////example callback//////
"SecondaryCallbackUrl": "",
"Description": "2 boxes of biscuits",
"ClientReference": "10652132"
}
hubtel_pay.SendMobileMoney(sendmoneydata).then(res=>{
console.log(res)
})
After initialization. Refund money to your customers from your Hubtel Account
var refundmoneydata = {
"RecipientMsisdn":"0505334234",
"RecipientName": "Grace Nartey",
"PrimaryCallbackUrl":'https://fe329e48.ngrok.io/api/v2/moneycallback',
"Channel": "vodafone-gh",
"TransactionId": "e8erU8Y383Uilfwrnv333",
"Reason": "Over paid for the item",
"ClientReference": "39UyW83iu23",
"Description": "description here",
"Amount": 0.5,
"Full": true
}
hubtel_pay.RefundMoney(refundmoneydata).then(value=>{
console.log(value)
})
After initialization.
var checkoutdata = {
"invoice": {
"items":{
"item_0": {
"name": "T Shirt",
"quantity": 2,
"unit_price": "35.0",
"total_price": "70.0",
"description": "Order of 2 Shirts"
},
"item_1": {
"name": "Polo Shirt",
"quantity": 1,
"unit_price": "25.0",
"total_price": "0.0",
"description": "Order of 1 Polo Shirt"
},
"item_2": {
"name": "Old Navy Jeans",
"quantity": 1,
"unit_price": "25.0",
"total_price": "0.0",
"description": ""
}
},
"taxes": {
},
"total_amount": 120,
"description": "Description of the invoice here"
},
"store": {
"name": "T Shirt Company",
"tagline": "Tagline of the online store",
"postal_address": "Box 10770 Accra - Ghana",
"phone": "233244124660",
"logo_url": "http://www.freepngimg.com/download/free/9-2-free-free-download-png.png",
"website_url": "http://example.com"
},
"custom_data": {
},
"actions": {
"cancel_url": "http://example.com",
"return_url": "http://example.com"
}
}
hubtel_pay.Onlinecheckout(checkoutdata).then(value=>{
console.log(value)
})
hubtel_pay.Checkstatus('online-checkout-token').then(value=>{
console.log(value)
})
Library uses request for http requests and request promise for promisyfing responses and errors. Catch all errors like catching promise errors. Hubtel errors exist in err.error.
see our demo folder example
An unofficial library for Hubtel Payment services.