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

lipanampesa_simplified

v1.0.4

Published

Simple way to integrate lipa na mpesa to your app

Downloads

17

Readme

lipanampesa

simplifies lipa na mpesa integration to your javascript app

Inspiration

Following the docs for daraja api is challenging and overwhelming. I spent a whole day trying to figure out what the workflow. After overcoming the struggle, i felt like its something that can be simplified.

How it works

Safaricom documentation requires a couple of steps -format time -creates password required for the transaction

  • constructs auth url that is passed in Authorization headers -obtain access token required to initiate a transaction -finally initiates a transaction -

However, i have composed the whole workflow, meaning you only require 2 simple steps to get up and running

first import the package
const lnp = require('lipanampesa_simplified')

Required credentials

  • You can use the test shortcode and passkey obtained from this site - https://developer.safaricom.co.ke/test_credentials
  • consumer_key and consumer_secret are provided after you register your app in daraja api portal
  • AccountReference is name that appears on pop up alert on phone ('keep it to max of 12 characters)
  • TransactionDesc - Description of your transaction (max of 13 characters)
  • CallBackURL - This is a route you specify to receive transaction response from safaricom (like transaction was completed or incomplete transaction incase of failure, safaricom have good error response so it will be clear)

implementation

(You would probably put the credentials in .env file and import them)

credentials parameter
const credentials = {
  ShortCode: "174379",
  passkey: "bfb279f9aa9bdbcf158e97dd71a467cd2e0c893059b10f78e6b72ada1ed2c919",
  PartyB: "174379",
  CallBackURL: "https://9vlic.sse.codesandbox.io/api/mpesa-callback",
  AccountReference: "Easy Shop",
  TransactionDesc: "Products",
  consumer_key: "EoDJq6WpLOmDXxRgGRLcBtsJdguSE4vy",
  consumer_secret: "hDL7TyheQSxzrbox"
};
setup your credentials
const initiate_transaction = lnp.transact(credentials);

//fork method runs the transaction. -it requires two functions on left and right (both methods receive a response from safaricom api) - you can choose how to handle each case

  • on the left you handle error - this could be like display an error
  • on the right you handle success - this could be like send a success msg -(transaction loading)
provide phonenumber and amount of the client
initiate_transaction({ PhoneNumber: "254714415603", Amount: "1" })
.fork(
  console.log,
  console.log
);

Dependencies

moment - for date formatting node-fetch - for handling requests on nodejs

The package removes obvious code and gives you minimal and necessary input to achieve your goal I do not work at safaricom and may have missed something. Its open, you are welcome to contribute

Reach out to me https://twitter.com/billmwas2 or [email protected]

Have fun Hacking!!