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

mpesa-node-sdk

v1.0.0

Published

Mpesa sdk for nodejs developers to be able to access the Safarico[3~[3~[3~com mpesa services i.e paybill,lipa na mpesa and many more apis

Downloads

47

Readme

mpesa-node-sdk

Introduction

This is a Mpesa sdk for node.js developers to help javascript developers integrate Mpesa payment system into their web apps easily. The package uses REST API that is documented on safaricom site. You can access it on http://developer.safaricom.co.ke.

Installation

npm install mpesa-node-sdk

Configuration

At your project root, create a .env file and in it set the MPESA_KEY,MPESA_SECRET and MPESA_MODE (i.e live or sandbox) and put the keys you received when registering your application from the safaricom portal. You can Register for a developer account and get your client_id and secret at Safaricom Developer Portal. MPESA_KEY= [YOUR_API_CONSUMER_KEY] MPESA_SECRET=[YOUR_API_CONSUMER_SECRET] MPESA_MODE=[live or sandbox]

Callback Responses You should be able to register validation and confirmation urls where the callback responses will be sent.

Usage

  • Require 'mpesa-node-sdk' in your file.

    var mpesa = require('mpesa-node-sdk');

B2C Payment Request

  • This is used to initiate the transaction from business to customers

    const request_options= {
        "InitiatorName": " ",
        "SecurityCredential":" ",
        "CommandID": " ",
        "Amount": " ",
        "PartyA": " ",
        "PartyB": " ",
        "Remarks": " ",
        "QueueTimeOutURL": "http://your_timeout_url",
        "ResultURL": "http://your_result_url",
        "Occasion": " "
      };
    
      mpesa.b2c(request_options,function(data){
          console.log(data);
      })

Account Balance Request

  • This is used to enquire the balance on an M-Pesa BuyGoods (Till Number)

    const request_options={
            "Initiator":" ",
            "SecurityCredential":" ",
            "CommandID":"AccountBalance",
            "PartyA":" ",
            "IdentifierType":"4",
            "Remarks":" ",
            "QueueTimeOutURL":"https://ip_address:port/timeout_url",
            "ResultURL":"https://ip_address:port/result_url"
           };
    mpesa.accountBalance(request_options,function(data){
         console.log(data);
    })

Transaction Status Request

*This is used to check the status of transaction

const request_options={
       "Initiator":" ",
       "SecurityCredential":" ",
       "CommandID":"TransactionStatusQuery",
       "TransactionID":" ",
       "PartyA":" ",
       "IdentifierType":"1",
       "ResultURL":"https://ip_address:port/result_url",
       "QueueTimeOutURL":"https://ip_address:port/timeout_url",
       "Remarks":" ",
       "Occasion":" "
   };
mpesa.transactionStatus(request_options,function(data){
       console.log(data);
  })

B2B Payment Request

This is used to transfer funds between two companies.

const request_options= {
        "Initiator": " ",
        "SecurityCredential": " ",
        "CommandID": " ",
        "SenderIdentifierType": " ",
        "RecieverIdentifierType": " ",
        "Amount": " ",
        "PartyA": " ",
        "PartyB": " ",
        "AccountReference": " ",
        "Remarks": " ",
        "QueueTimeOutURL": "http://your_timeout_url",
        "ResultURL": "http://your_result_url"
      };
mpesa.b2b(request_options,function(data){
      console.log(data);
 })

C2B Payment Request

This is used to Simulate transfer of funds between a customer and business.

const request_options={
        "ShortCode":" ",
        "CommandID":"CustomerPayBillOnline",
        "Amount":" ",
        "Msisdn":" ",
        "BillRefNumber":" "
    };

  mpesa.c2b(request_options,function(data){
        console.log(data);
    })

Reversal This is used to initiate a reversal request

const request_options={
        "Initiator": "",
        "SecurityCredential": "",
        "CommandID":"TransactionReversal",
        "TransactionID": "",
        "Amount": "2000",
        "ReceiverParty": "",
        "RecieverIdentifierType":"4",
        "QueueTimeOutURL": "http://your_timeout_url",
        "ResultURL": "http://your_result_url",
        "Remarks": "wrong transaction",
        "Occasion": ""
    };

    mpesa.reversal(request_options,function(data){
        console.log(data);
    })

STK Push Simulation

This is used to initiate online payment on behalf of a customer.

const request_options={
         "BusinessShortCode": " ",
         "Password": " ",
         "Timestamp": " ",
         "TransactionType": "CustomerPayBillOnline",
         "Amount": " ",
         "PartyA": " ",
         "PartyB": " ",
         "PhoneNumber": " ",
         "CallBackURL": "https://ip_address:port/callback",
         "AccountReference": " ",
         "TransactionDesc": " "
     };

  mpesa.STKPushSimulation(request_options,function(data){
         console.log(data);
  })

STK Push Status Query

This is used to check the status of a Lipa Na M-Pesa Online Payment.

const request_options={
        "BusinessShortCode": " " ,
        "Password": " ",
        "Timestamp": " ",
        "CheckoutRequestID": " "
    };

    mpesa.STKPushQuery(request_options,function(data){
        console.log(data);
  })

Reference

[REST API Reference] (https://developer.safaricom.co.ke/docs)

Running Examples

Examples are located in the examples directory.