Integrate PesaPal into your Node application
Make it easy to integrate PesaPal into a website or mobile app AND most importantly allow one to customize the payment user interface.
paymentListener
: express
middleware that parses PesaPal payment notifications.
getPaymentStatus(options, callback)
: Get status of a payment. options
should contain either a reference
alone or a reference
and transaction
together.
getPaymentDetails(options, callback
): 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, callback)
: Prepare an order for payment on a custom UI.
payOrder(order, paymentDetails, callback)
: After a call to makeOrder
, pay an order with details collected through a custom UI.
var PesaPal = require('pesapaljs').init({
key: CONSUMER_KEY,
secret: CONSUMER_SECRET,
debug: true // false in production!
});
When the debug
option is set, pesapaljs
will use the demo.pesapal.com/*
endpoints.
// Listen for IPNs (With an express app)
app.get('/ipn', PesaPal.paymentListener, function(req, res) {
var payment = req.payment;
// do shit with payment {transaction, method, status, reference}
// DO NOT res.send()
});
var options = {
reference: "42314123", // Send this
transaction: "175c6485-0948-4cb9-8d72-05a2c3f25be5" // or both.
};
PesaPal.getPaymentStatus(options, function(error, status}{
// do shit
});
PesaPal.getPaymentDetails(options, function (error, payment) {
//payment -> {transaction, method, status, reference}
//do shit
});
Make your customer pay on PesaPal's page:
var customer = new PesaPal.Customer("[email protected]");
var order = new PesaPal.Order("42314123", customer, "Ma ndazi", 1679.50, "KES", "MERCHANT");
// Redirect user to PesaPal
var url = PesaPal.getPaymentURL(order, "http://mysite.co.ke/callback");
// send it to an iframe ?
Or make your own awesome payment UI (web page, mobile app front-end, etc.):
var customer = new PesaPal.Customer("[email protected]");
var order = new PesaPal.Order("WSDE0RFCC", customer, "Maziwa", 100, "KES", "MERCHANT");
// place order directly with your own UI
PesaPal.makeOrder(order, PesaPal.PaymentMethod.Airtel, function(error, order) {
// Get payment details from user, DB - like their credit card info ;) or whatever
// ...
PesaPal.payOrder(order, new PesaPal.MobileMoney("254728988983","DEWEDWED"), function (error, reference, transactionId) {
// do shit
});
});
git push origin master
To report bugs (or any other issues), use the issues page.