daraja-client
v1.0.1
Published
A modern, lightweight Node.js client for the M-Pesa Daraja API that simplifies authentication, STK Push, and payment integrations.
Downloads
247
Maintainers
Readme
daraja-client
A modern, lightweight Node.js/TypeScript client for the M-Pesa Daraja API that simplifies authentication, STK Push, and payment integrations with minimal boilerplate.
📦 Installation
npm install daraja-clientEnvironment Variables
Provide the environment variables with the naming style shown below
DARAJA_CONSUMER_KEY=xxx
DARAJA_CONSUMER_SECRET=xx
DARAJA_SHORTCODE=xxx
DARAJA_PASSKEY=xx
DARAJA_ENVIRONMENT=sandbox/production🚀 Quick Start
import { DarajaClient } from "daraja-client";
const client = new DarajaClient();
async function pay() {
const response = await client.stkPush({
phone: "2547XXXXXXXX",
amount: 100,
accountReference: "Order123",
transactionDesc: "Payment for order",
});
console.log(response);
}
pay();