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

nativescript-mpesa

v1.0.0

Published

Nativescript plugin to make payment with mpesa.

Downloads

22

Readme

NativeScript Mpesa

Nativescript-Mpesa provides a wrapper that incorporate payments using Mpesa from within your {N} applications. The integration is achieved using the Android M-Pesa Daraja SDK libraries. Hence, has full support for Android.

Usage

Setup

First import package into the main-page's model or app.component as the case may be for either {N} Core or {N} w/ Angular

    import { Mpesa } from "nativescript-mpesa";

Then create an instance of Mpesa.

     const mpesa = new Mpesa();

Initialize the instance with the CustomerKey,CustomerSecret gotten from Safaricom and Env

Note Env could be SANDBOX or PRODUCTION

    mpesa.initialize(CONSUMER_KEY, CONSUMER_SECRET, Env)

Making Payment

    const mpesa = new Mpesa();

    const lnmExpress = {
                        BusinessShortCode: "174379",
                        PassKey: "bfb279f9aa9bdbcf158e97dd71a467cd2e0c893059b10f78e6b72ada1ed2c919",
                        Type: "CustomerPayBillOnline",
                        Amount: "100",
                        PartyA: "254708374149",
                        PartyB: "174379",
                        PhoneNumber: "254708374149",
                        CallBackURL: "http://mycallbackurl.com/checkout.php",
                        AccountReference: "001ABC",
                        TransactionDesc: "Goods Payment"
                      };
    mpesa.initialize("dRSvS4nnTGU8vf1V8jUHfu9BW6AAxl83","WQFHurC4OsVBYJQt","SANDBOX").
            then(res => {
              console.log("access token", res);
              this.mpesa.requestMPESAExpress(lnmExpress).then(
                res => {
                  console.log("lnmResult", res);
                },
                err => {
                  console.log(err);
                }
              );
            }, err => {
              console.log("error", err);
            });
  }

Lipa na M-Pesa Online Payment API

The following table highlights the requirements needed by Daraja, as described in the Safaricom Developer API Page

| Name | Description | Parameter Type | Possible Values | | ------------- |:--------------------: | ----------------: | ---------------:| | BusinessShortCode | The organization shortcode used to receive the transaction | Numeric | Shortcode (6 digits) | | Passkey | Lipa Na Mpesa Online PassKey | Alpha-Numeric | | | Amount | The amount to be transacted | Numeric | 100 | | PartyA | The entity sending the funds | Numeric | MSISDN (12 digits) | | PartyB | The organization receiving the funds | Numeric | Shortcode (6 digits) | | PhoneNumber | The MSISDN sending the funds | Numeric | MSISDN (12 digits) | | CallBackURL | Call Back URL | URL | https://ip or domain:port/path | | AccountReference | Account Reference | Alpha-Numeric | Any combinations of letters and numbers | | TransactionDesc | Description of the transaction | String | any string of less then 20 characters |

Get the Pass Key Here : https://developer.safaricom.co.ke/test_credentials

Response Signature

Success Response

   export interface LNMResult {
    MerchantRequestID: string;
    CheckoutRequestID: string;
    ResponseCode: string;
    ResponseDescription: string;
    CustomerMessage: string;
}

License

Apache License Version 2.0, January 2004