mpesajs-lib
v1.0.1
Published
A JavaScript/TypeScript library to simplify Mpesa payment integration using Safaricom Daraja API.
Downloads
9
Maintainers
Readme
🧾 mpesajs-lib
A lightweight JavaScript/TypeScript library for simplifying Mpesa payment integration via the Safaricom Daraja API.
🚀 Features
- Easy-to-use interface for initiating STK Push
- Built with modern ES modules
- Works with JavaScript and TypeScript
- Designed for Node.js
- Lightweight and dependency-free
📦 Installation
npm install mpesajs-lib🛠️ Usage
import { initiateStkPush } from 'mpesajs-lib';
const response = await initiateStkPush({
amount: 100,
phoneNumber: '254712345678',
accountReference: 'Order123',
transactionDesc: 'Payment for Order #123',
consumerKey: process.env.MPESA_CONSUMER_KEY,
consumerSecret: process.env.MPESA_CONSUMER_SECRET,
passKey: process.env.MPESA_PASSKEY,
shortCode: process.env.MPESA_SHORTCODE,
callbackUrl: 'https://yourdomain.com/mpesa-callback'
});
console.log(response);🔐 Make sure to store your credentials securely using
.env.
🔧 Configuration
To use this library, you need:
- Safaricom Daraja App Credentials
- Consumer Key
- Consumer Secret
- Pass Key
- Shortcode
- Registered Callback URL
You can get these at: https://developer.safaricom.co.ke
🧪 Running Tests
npm run test(You can update the test.js file with your own tests or integrate Jest/Mocha later.)
🤝 Contributing
Contributions are welcome! Follow these steps:
- Fork the repository
- Create a new branch (
git checkout -b feature/your-feature) - Make your changes
- Commit your changes (
git commit -m 'add your feature') - Push to the branch (
git push origin feature/your-feature) - Open a Pull Request
Please ensure your code is clean, documented, and tested.
📄 License
MIT © Oscar Madegwa
