Logo Lanfrica

Carrieukie/android_mpesa_stk

Domain:

digital infrastructure

Record type:

software
Creator:
Car
Host:
Android Mpesa library to initiate stk push android_mpesa_stk Android Mpesa library to initiate stk push MPESA just unveiled their new API, Daraja 2.0. It has been hailed as the height of developer heaven with its crisp clear structure, solid security and great syntax. So this library is a wrapper around the API to help you intiate MPESA STK push easily on your Android apps. ## Download ### Gradle Add the codes below to your root `build.gradle` file: ```gradle allprojects { repositories { ... maven { url 'jitpack.io' } } } ``` And add the dependency below to your **module**'s `build.gradle` file: ```gradle dependencies { implementation 'com.github.Carrieukie:android_mpesa_stk:Tag' } ``` ## Usage Create and Instance of `DarajaDriver` class passing in your credentials and specify your enviroment. ``` Kotlin private val darajaDriver = DarajaDriver( consumerKey = BuildConfig.CONSUMER_KEY, consumerSecret = BuildConfig.CONSUMER_SECRET, environment = Environment.SandBox() ) ``` > Get the test credentials from Here : developer.safaricom.co.ke Create an instance of `STKPushRequest` ``` Kotlin private val stkPushRequest = STKPushRequest( businessShortCode = BUSINESS_SHORT_CODE, password = getPassword(BUSINESS_SHORT_CODE, PASS_KEY, timestamp), timestamp = timestamp, mpesaTransactionType = TransactionType.CustomerPayBillOnline(), amount = amount, partyA = sanitizePhoneNumber(phoneNumber), partyB = BUSINESS_SHORT_CODE, phoneNumber = sanitizePhoneNumber(phoneNumber), callBackURL = CALLBACKURL, accountReference = "Dlight", // Account reference transactionDesc = "Dlight STK PUSH" // Transaction description ) ``` * `businessShortCode` - This is organizations shortcode (Paybill or Buygoods - A 5 to 7 digit account number) used to identify an organization and receive the transaction. * `password` - This is the password used for encrypting the request sent: A base64 encoded string. (The base64 string is a combination of Shortcode+Passkey+Timestamp). For sandbox, get the pas …

Languages

Licenses