npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

ch-pesapaljs

v1.0.3

Published

Integrate PesaPal into your Node application

Downloads

25

Readme

ch-pesapaljs (MAINTAINED)

NPM

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 i ch-pesapaljs
Setup

var PesaPal = require('ch-pesapaljs').init({
    key: CONSUMER_KEY,
    secret: CONSUMER_SECRET,
    debug: true // false in production!
});

When the debug option is set, ch-pesapaljs will use the demo.pesapal.com/* endpoints.

Listen for payment notifications

// Listen for IPNs (With an express app)
// Use localtunnel or similar tools to test IPN when running on localhost
app.get('/ipn', PesaPal.paymentListener, function(req, res) { 
    var payment = req.payment;
    // do stuff with payment {transaction, method, status, reference}
    
    // DO NOT res.send()
});
Check Payment info

var options = {
    reference: "42314123", // Send this
    transaction: "175c6485-0948-4cb9-8d72-05a2c3f25be5" // or both.
};
PesaPal.getPaymentStatus(options)
        .then(function(status){ /* do stuff*/ })
        .catch(function(error){ /* do stuff*/ });

PesaPal.getPaymentDetails(options)
        .then(function (payment) {
            //payment -> {transaction, method, status, reference}
            //do stuff
        })
        .catch(function (error) { /* do stuff*/  });
Make a direct order

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, method) // First make the order

    .then(function (processedOrder) { // then collect payment details from user
        // Get payment details from user, DB - like their credit card info ;) or whatever
        // ...
        
        return Promise.resolve({
            order: processedOrder, 
            paymentDetails: new PesaPal.MobileMoney("254728988983","DEWEDWED")
        });
        
    }).then(function(collected) => { // then send payment request
        return PesaPal.payOrder(collected.order, collected.paymentDetails)
    })
    .then(function(resp) { // finally, receive a transaction id
        // resp.reference Your order, reference (42314123)
        // resp.transaction Payment transaction ID from PesaPal
        
    })
    .catch(function(error) {
        // Yo something went horribly wrong!
    });

Contributing

  1. Fork this repo and make changes in your own fork.
  2. Commit your changes and push to your fork git push origin master
  3. 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.