Code Monkey home page Code Monkey logo

mpesastkpush's Introduction

MpesaSTKPush

Lipa na Mpesa STK Push library Android.

Setup

In your build.gradle file add the following dependency;

dependencies {
   implementation 'com.revosleap:mpesapush:1.0.0'
}

In your gradle.properties file, add the consumer and consumer secret keys given from Safaricom developer site. Add as shown below;

DARAJA_CONSUMER_KEY="xxxxxxxxx"
DARAJA_CONSUMER_SECRET="xxxxxxxxx"

Then add internet permission in your manifest as:

<uses-permission android:name="android.permission.INTERNET"/>

Usage

This is pretty simple. After a successful setup, there are two ways to use the library.

Method 1

MpesaPay.sendPush(...)

Sample

MpesaPay.sendPush("07xxxxxxxx", //number to send push to
                "100", //amount of cash
                "174379", //the paybill number
                "174379", //Receiving number
                "APPLES3", //Account number
                "fruits", //Description
                "bfb279f9aa9bdbcf158e97dd71a467cd2e0c893059b10f78e6b72ada1ed2c919", //passkey, provided by safaricom
                "https://spurquoteapp.ga/pusher/pusher.php?title=stk_push&message=result&push_type=individual&regId="// Your callback url

            )

Method 2

Use the a given model class named TransactionDetails

Kotlin

MpesaPay.sendPush(TransactionDetails(....))

Sample

val details= TransactionDetails(
                "07xxxxxxxx", //number to send push to
                "bfb279f9aa9bdbcf158e97dd71a467cd2e0c893059b10f78e6b72ada1ed2c919", //passkey, provided by safaricom
                "120", //amount of cash
                "174379", //the paybill number
                "APPLES3", //Account number
                "https://spurquoteapp.ga/pusher/pusher.php?title=stk_push&message=result&push_type=individual&regId=",
                "174379", //Sending number
                "174379", //Receiving number
                "fruits",
                "CustomerPayBillOnline" //Transaction type
            )

Java

MpesaPay.sendPush(new TransactionDetails(....))

Sample

TransactionDetails details= new TransactionDetails(
              "07xxxxxxxx", //number to send push to
              "bfb279f9aa9bdbcf158e97dd71a467cd2e0c893059b10f78e6b72ada1ed2c919", //passkey, provided by safaricom
              "120", //amount of cash
              "174379", //the paybill number
              "APPLES3", //Account number
              "https://spurquoteapp.ga/pusher/pusher.php?title=stk_push&message=result&push_type=individual&regId=",
              "174379", //Sending number
              "174379", //Receiving number
              "fruits",
              "CustomerPayBillOnline" //Transaction type
          );
          
 MpesaPay.sendPush(details)

and you are good to go.

Visit Safaricom Documentation for more information about the given parameters.

Credits

Thanks to LNMOnlineAndroidSample for the inspiration to come up with this library.

Libraries used

  • Retrofit
  • Retrofit converter Gson
  • okhttp3 Logging interceptor

Contributions

Feel free to fork and create pull requests

Coded with ๐Ÿ’™ by revosleap.

mpesastkpush's People

Contributors

carloscj6 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.