Node.js library for the M-Pesa Mozambique API
# mpesa-mz-nodejs-lib
A Node.js library for the M-Pesa Mozambique API
Initially, a port of mpesa-php-api to Node.js
Read documentation here
## Version 0.7.11
Currently in beta version. Stable but not production-ready (v1.0.0)
## Features
- Simple syntax
- Promise-based
- Agnostic library. Treats config and transaction details as data, rather than dependencies
- Validation of transaction parameters to ensure only valid requests get sent to the MPesa API
## Status
- [x] C2B Transaction
- [x] B2C Transaction
- [x] Transaction status query
- [x] Transaction reversal
## Roadmap
- [x] Unit tests passing for all features (v0.4.x)
- [x] Continuous Integration (v0.5.x)
- [x] Documentation (code coverage, features) (v0.6.x)
- [x] Linting, code quality (v0.7.x)
- [ ] Code refactoring (entire codebase) (v0.8.x)
- [ ] Rename library (v0.9.x)
- [ ] All tests passing, functionalities stable (v1.0.0)
## Installation
```
npm install mpesa-mz-nodejs-lib
```
## Examples
All parameters used in the examples correspond to the parameters required by the MPesa API. See the documentation on the MPesa Developer Portal for more information.
### Customer to Business (C2B) transaction
```javascript
// include the library
Transaction = require('mpesa-mz-nodejs-lib')
// create the config object
var config = {
public_key: ' ',
api_host: 'api.sandbox.vm.co.mz',
api_key: ' ',
origin: ' ',
service_provider_code: ' ',
initiator_identifier: ' ',
security_credential: ' '
}
// instantiate the Transaction object, initializing it with valid config
transaction = new Transaction(config)
// initiate a promise-based C2B transaction
transaction.c2b({
amount: ,
msisdn: ' ',
reference: ' ',
third_party_reference: ' '
})
// handle success
.then(function(response){
console.log(response)
})
// handle error
.catch(function(error){
console.log(error)
})
```
### Querying status of an existing transaction
```javascript
// ... Assuming an initialized Transaction object
// query the status o …