I will no longer be maintaining this library. I suggest using mpesa-node instead.
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.
- Generate OAuth access token
- Lipa Na Mpesa online
- C2B
- Balance
- Transaction status
- Reversal
- B2B
- B2C
yarn add pesa-lib
// 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)
This is an unofficial package, not made by Safaricom.