1.0.0 • Published 5 years ago

nativescript-mpesa v1.0.0

Weekly downloads
2
License
Apache-2.0
Repository
github
Last release
5 years ago

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

NameDescriptionParameter TypePossible Values
BusinessShortCodeThe organization shortcode used to receive the transactionNumericShortcode (6 digits)
PasskeyLipa Na Mpesa Online PassKeyAlpha-Numeric
AmountThe amount to be transactedNumeric100
PartyAThe entity sending the fundsNumericMSISDN (12 digits)
PartyBThe organization receiving the fundsNumericShortcode (6 digits)
PhoneNumberThe MSISDN sending the fundsNumericMSISDN (12 digits)
CallBackURLCall Back URLURLhttps://ip or domain:port/path
AccountReferenceAccount ReferenceAlpha-NumericAny combinations of letters and numbers
TransactionDescDescription of the transactionStringany 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