@saverious/daraja
v1.1.1
Published
A nodejs library to simplify the integration of safaricom's daraja api
Maintainers
Readme
@saverious/daraja
About
@saverious/daraja module was designed to simplify integration of daraja api endpoints by reducing not only the
syntax complexity of the raw api, but also the number of required arguments
Limitations
As of the current date, the module supports only the M-Pesa Express API (stk-push)
Supported endpoints
- M-Pesa Express
Install
npm i @saverious/darajaUsage
require('dotenv').config();
const Daraja = require('@saverious/daraja');
const { CONSUMER_KEY, CONSUMER_SECRET, PHONE, CALLBACK } = process.env;
async function payViaMpesa() {
try{
const daraja = new Daraja({
consumer_key : CONSUMER_KEY,
consumer_secret : CONSUMER_SECRET,
environment : 'development'
});
const response = await daraja.stkPush({
sender_phone : PHONE,
payBillOrTillNumber : '174379',
amount : '1',
callback_url : CALLBACK
});
console.log('safaricom response : ', response);
}catch(e){
console.log('payment error : ', e);
}
}
payViaMpesa();API
new Daraja(options)
options<object> Set of configurable options to set on the class. Can have the following fields:consumer_key<string> Your consumer key from the safaricom portalconsumer_secret<string> Your consumer secret from the safaricom portalenvironment<string> The current project environment. One of eitherdevelopmentorproduction
All the three key/value pairs in options object are required
daraja.stkPush(options)
options<object> Options containing payment details. Can have the following fields:sender_phone<string> The sender's phone number.required : truepayBillOrTillNumber<string> The account number (Paybill number or Till number) to which funds should be sent.required : trueamount<string> The amount to be sent.required : truecallback_url<string> The URL to which the response from safaricom should be sent.required : truepasskey<string> The passkey from safaricom.required : trueonly ifenvironment === production, otherwiserequired : falseaccount_reference<string> An Identifier of the transaction for the CustomerPayBillOnline transaction type.required : falsetransaction_desc<string> Any additional information/comment that can be sent along with the request from your system.required : false
Returns<Promise>
