@saverious/daraja

1.0.1 • Public • Published

@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/daraja

Usage

const Daraja = require('@saverious/daraja');

async function payViaMpesa() {
    try{
        const daraja = new Daraja({
            consumer_key : 'your consumer key',
            consumer_secret : 'your consumer secret',
            environment : 'development' 
        });
        
        const response = await daraja.stkPush({
            sender_phone : '0767456201',
            payBillOrTillNumber : '174379',
            amount : '1',
            callback_url : 'https://ac10-102-135-169-116.ngrok-free.app'
        });
        
        console.log('safaricom response : ', response);
    }catch(error){
        console.log('payment error : ', error);
    }
}

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 portal
    • consumer_secret <string> Your consumer secret from the safaricom portal
    • environment <string> The current project environment. One of either development or production

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 : true
    • payBillOrTillNumber <string> The account number (Paybill number or Till number) to which funds should be sent. required : true
    • amount <string> The amount to be sent. required : true
    • callback_url <string> The URL to which the response from safaricom should be sent. required : true
    • passkey <string> The passkey from safaricom. required : true only if environment === production, otherwise required : false
    • account_reference <string> An Identifier of the transaction for the CustomerPayBillOnline transaction type. required : false
    • transaction_desc <string> Any additional information/comment that can be sent along with the request from your system. required : false
  • Returns <Promise>

Package Sidebar

Install

npm i @saverious/daraja

Weekly Downloads

10

Version

1.0.1

License

MIT

Unpacked Size

9.42 kB

Total Files

8

Last publish

Collaborators

  • saverious