https://github.com/developerwilliams/mini-daraja
Mini-Daraja is a lightweight Node.js library for seamless integration with the Safaricom Daraja API. It simplifies handling M-Pesa operations like STK Push, B2C, C2B, transaction status, and balance inquiries, with modern ES6 module support and robust error handling
https://github.com/developerwilliams/mini-daraja
Last synced: 10 months ago
JSON representation
Mini-Daraja is a lightweight Node.js library for seamless integration with the Safaricom Daraja API. It simplifies handling M-Pesa operations like STK Push, B2C, C2B, transaction status, and balance inquiries, with modern ES6 module support and robust error handling
- Host: GitHub
- URL: https://github.com/developerwilliams/mini-daraja
- Owner: DeveloperWilliams
- License: mit
- Created: 2024-12-16T10:21:38.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2025-01-25T22:15:53.000Z (12 months ago)
- Last Synced: 2025-02-14T19:53:35.336Z (11 months ago)
- Language: TypeScript
- Size: 26.4 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: Readme.md
- License: LICENSE
Awesome Lists containing this project
README
# **Mini-Daraja**
**Seamless M-Pesa Integration for Node.js**
Mini-Daraja is the most popular and widely used Node.js library for seamless integration with the Safaricom Daraja API. It simplifies handling M-Pesa operations like STK Push, B2C, C2B, transaction status, and balance inquiries, with modern ES6 module support and robust error handling.
---
## **Features**
- 🚀 Simple and clean API to integrate M-Pesa operations
- 🔒 Modern ES6+ module support
- ⚙️ Handles STK Push, B2C, C2B, Transaction Status, and Balance Inquiries
- 🛡️ Robust error handling with clear error messages
---
## Installation
To install, run:
```bash
npm install mini-daraja
```
---
## Usage
##### Usage example for Initialize Daraja API instance with credentials
```javascript
import mpesa from 'mini-daraja';
// Initialize Daraja API instance with credentials
const daraja = mpesa({
consumerKey: 'your_consumer_key', // Replace with your Consumer Key
consumerSecret: 'your_consumer_secret', // Replace with your Consumer Secret
shortCode: '174379', // Replace with your M-Pesa Shortcode
passKey: 'your_pass_key_here', // Replace with your PassKey
callbackUrl: 'https://example.com/callback', // Replace with your Callback URL
});
```
##### STK Push Example
```javascript
// Function to perform STK Push
async function stkPush() {
try {
const response = await daraja.stkPush({
phoneNumber: '254708966189', // Customer's phone number (E.164 format)
amount: 100, // Transaction amount
accountReference: 'Invoice123', // Custom account reference
transactionDescription: 'Test Payment', // Transaction description
});
console.log('✅ STK Push Response:', response);
} catch (error) {
console.error('❌ STK Push Error:', error.message);
}
}
```
## Contact
Designed by *William Achuchi Wanyama*
- Email: [archywilliams2@gmail.com](mailto:archywilliams2@gmail.com)
- X: [@dev_williee](https://x.com/dev_williee)
- LinkedIn: [William Achuchi Wanyama](https://linkedin.com/in/achuchi)