Logo Lanfrica

daraja-sdks/daraja.js

Domain:

digital infrastructure

Record type:

software
Creator:
dar
Host:
A node.js wrapper for seamless integration with Mpesa's Daraja API # Daraja.js A node.js wrapper for seamless integration with Mpesa's Daraja API. This library provides a builder-style interface to enhance the ease of use. Visit daraja-sdks.github.io to find implementations in other languages and more documentation. ## Integrated APIs: - ✅ Mpesa Customer to Business (C2B) - ✅ Mpesa Express/Lipa na Mpesa Online/STK Push - ✅ Lipa na Mpesa Query - ✅ Mpesa Business to Customer (B2C) - ✅ Mpesa Transaction Status query - ✅ Mpesa Account Balance query - ✅ Mpesa Reversals ## Documentation More In-depth documentation on library usage can be found here. Also, full-blown examples on library usage can be found at the daraja-sdks github repos. ## Creating an app instance To get started, create an instance of the `Mpesa` class: ```js // with es-modules syntax import { Mpesa } from "daraja.js" // with common-modules syntax const Mpesa = require("daraja.js").Mpesa // create an app instance const app = new Mpesa({ consumerKey: process.env.APP_KEY, // required consumerSecret: process.env.APP_SECRET, // required initiatorPassword: "Safaricom999!*!", // required only in production organizationShortCode: 174379, // optional certificatePath: "some/path", // optional securityCredential: "someSecureCredential" // optional }) ``` ## STK Push / Lipa na Mpesa Online / Mpesa Express API: ```js // ... const res = await app .stkPush() .amount(1) .callbackURL("example.com") .phoneNumber(254708374149) .lipaNaMpesaPassKey(process.env.LNM_PASSKEY) .send(); console.log(res.isOkay()); ``` ## STK Query API: ```js // ... const res = await app .stkPush() .shortCode("174379") .checkoutRequestID("ws_CO_DMZ_123212312_2342347678234") .lipaNaMpesaPassKey(process.env.LNM_PASSKEY) .queryStatus(); // sends the query request ``` ## Customer to business(C2B) simulate API: ```js // ... const res = await app .c2b() .shortCode("600998") .accountNumber("Bill payment") .amount(1) .phoneNumber(254708374149) .simulate(); ``` ## Customer to b …