Daraja Client
A light weight NodeJS library for Safaricom's Daraja API
Installation
Install @daraja/client
with npm
npm install @daraja/client
or with Yarn
yarn add @daraja/client
Quick Start
import { DarajaClient } from '@daraja/client';
const client = new DarajaClient({
businessShortcode: '123456',
consumerKey: 'consumerKey',
consumerSecret: 'consumerSecret',
lnmPasskey: 'lnmPasskey',
scopes: ['lipa-na-mpesa-online'],
});
client
.lipaNaMpesaOnlinePayment({
accountReference: 'CompanyXLTD',
amount: 1,
callbackURL: 'http://mydomain.com/lnmCallback',
partyA: '254701234567',
transactionDescription: 'Payment of X',
transactionType: 'CustomerPayBillOnline',
})
.then((res) => {
// SUCCESS
// do something with the response
})
.catch((err) => {
// FAIL
// handle the error
});
// you can also use the async-await syntax to perform a similar operation
const transact = async () => {
try {
const response = await client.lipaNaMpesaOnlinePayment({
accountReference: 'CompanyXLTD',
amount: 1,
callbackURL: 'http://mydomain.com/lnmCallback',
partyA: '254701234567',
transactionDescription: 'Payment of X',
transactionType: 'CustomerPayBillOnline',
});
// do something with the response
} catch (error) {
// handle the error
}
};
transact()
API Reference
Daraja Client's full documentation is online at Daraja Client documentation.
Features
- Lipa na Mpesa Online Payment
Roadmap
- Lipa na Mpesa Online Query
- C2B Register URLs
- C2B Simulate Transaction
- B2C Payment
- Transaction Status Query
- Account Balance Query
- Transaction Reversal
Tech Stack
NodeJS, TypeScript
License
Contributing
Contributions are always welcome!
See CONTRIBUTING.md for ways to get started.
Please adhere to this project's Code of Conduct.
Feedback
If you have any feedback, please reach out to me at austinewuncler@gmail.com