PesapalJS

Goal
Make it easy to integrate PesaPal into a website or mobile app AND most importantly allow one
to customize the payment user interface.
Core Features
-
paymentListener
: express
middleware that parses PesaPal payment notifications.
-
getPaymentStatus(options)
: Get status of a payment. options
should contain either a reference
alone or a reference
and transaction
together.
-
getPaymentDetails(options
): Get all information about a payment. options
should contain a reference
and a transaction
.
-
getPaymentURL(order, callbackURI)
: Get a signed URL to the PesaPal payment page.
-
makeOrder(order, paymentMethod)
: Prepare an order for payment on a custom UI.
-
payOrder(order, paymentDetails)
: After a successful call to makeOrder
, pay an order with details collected through a custom UI.
Usage
Install
$ npm install pesapaljs
Setup
var PesaPal = require('pesapaljs').init({
key: CONSUMER_KEY,
secret: CONSUMER_SECRET,
debug: true
});
When the debug
option is set, pesapaljs
will use the demo.pesapal.com/*
endpoints.
Listen for payment notifications
app.get('/ipn', PesaPal.paymentListener, function(req, res) {
var payment = req.payment;
});
Check Payment info
var options = {
reference: "42314123",
transaction: "175c6485-0948-4cb9-8d72-05a2c3f25be5"
};
PesaPal.getPaymentStatus(options)
.then(function(status){ })
.catch(function(error){ });
PesaPal.getPaymentDetails(options)
.then(function (payment) {
})
.catch(function (error) { });
Make a direct order
Make your customer pay on PesaPal's page:
var customer = new PesaPal.Customer("kariuki@pesapal.com");
var order = new PesaPal.Order("42314123", customer, "Ma ndazi", 1679.50, "KES", "MERCHANT");
var url = PesaPal.getPaymentURL(order, "http://mysite.co.ke/callback");
Or make your own awesome payment UI (web page, mobile app front-end, etc.):
var customer = new PesaPal.Customer("john@pesapal.com");
var order = new PesaPal.Order("WSDE0RFCC", customer, "Maziwa", 100, "KES", "MERCHANT");
PesaPal.makeOrder(order, method)
.then(function (processedOrder) {
return Promise.resolve({
order: processedOrder,
paymentDetails: new PesaPal.MobileMoney("254728988983","DEWEDWED")
});
}).then(function(collected) => {
return PesaPal.payOrder(collected.order, collected.paymentDetails)
})
.then(function(resp) {
})
.catch(function(error) {
});
Contributing
- Fork this repo and make changes in your own fork.
- Commit your changes and push to your fork
git push origin master
- Create a new pull request and submit it back to the project.
Bugs & Issues
To report bugs (or any other issues), use the issues page.