Skip to content
This repository has been archived by the owner on Dec 9, 2018. It is now read-only.

MarkNjunge/PesaLib

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

27 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Notice

I will no longer be maintaining this library. I suggest using mpesa-node instead.

Pesa Lib

NPM

An Node.js package for Mpesa.

Before using this package, create an account on the Safaricom Developer Portal to receive a Consumer Key and Consumer Secret.
Business short code and pass key can be found at the Test credentials page.

Features

Installation

yarn add pesa-lib

Usage

  • All methods return a promise.
  • See Sample.ts
  • See the wiki for more documentation.

Initialization

// For Javascript use
// const PesaLib = require("pesa-lib").default;
import PesaLib from "pesa-lib";

const pesalib = new PesaLib(
  consumerKey,
  consumerSecret,
  businessShortCode,
  passKey,
  false // Use 'true' to change to live url.
);

Use this API to generate an OAuth access token to access other APIs.
Other methods with use do this automatically so it's not needed.

pesaLib.oAuth()

Use this API to initiate online payment on behalf of a customer.
Phone number should begin with 254.

pesalib.lnmProcess(amount, phoneNumber,callbackUrl, accountRef, transactionDesc)

Use this API to check the status of a Lipa Na M-Pesa Online Payment.

pesalib.lnmQuery(checkoutRequestId)

Use this API to register validation and confirmation URLs on M-Pesa

pesalib.c2bRegister(confirmationUrl, validationUrl)

Use this API to simulate a C2B transaction

pesalib.c2bSimulate(amount, phoneNumber, billingRef, commandId)

Encrypt credentials using a certificate file.

pesalib.security(credential, pathToCert)

Enquire the balance on an M-Pesa

pesalib.balance(securityCredential, initiator, partyA, idType, remarks, queueTimeoutUrl, resultUrl)

Use this api to check the transaction status.

pesa.transactionStatus(identifierType, remarks, initiator, securityCredential, queueTimeoutUrl, resultTimeoutUrl, transactionId, occassion)

Disclaimer

This is an unofficial package, not made by Safaricom.