Giter Club home page Giter Club logo

android-mpesa-api's Introduction

Android M-Pesa Daraja SDK

This is a simple Android M-PESA SDK to allow you to integrate Safaricom M-PESA API dubbed Daraja in your Android App with ease without knowing a thing. It’s easy. I promise. πŸš€

This version only offers the MPESA Express (STKPush) Support.

Download

Daraja available for download on mavenCentral()

Kotlin

dependencies {
    implementation("com.androidstudy.daraja:daraja:2.0.2")
}

Groovy

dependencies {
    implementation 'com.androidstudy.daraja:daraja:2.0.2'
}

Quick Start

WIP - need to be updated

Requirements

  • AndroidX
  • Min SDK 14+
  • Java 8+

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
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

android-mpesa-api's People

Contributors

andronicus-kim avatar dependabot[bot] avatar gilokimu avatar joelkanyi avatar jumaallan avatar kelvinpac avatar madonahs avatar muth0mi avatar orama254 avatar ronnieotieno avatar sefuzeph avatar wangerekaharun avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

android-mpesa-api's Issues

AccountReference character limit.

There is a 12 character limit for the account reference.

Funny thing is the response returned says request is being processed, however the actual push is not made to device. Was trying this out today on the Safaricom portal earlier, probably a bug on their end.

Authentication Request Failure rate

Hi Juma i noticed currently getting the Accesstoken from the library has a high failure rate and hence no stk push is shown can you help check

Kotlin Support

Add Kotlin Support and Examples to this project - Enhancements

Handle Callbacks using Firebase

Handle callbacks and push notifications to the device.
This is an enhancement to show how to handle server callbacks on successful response from Safaricom, and also show a nice way to push successful transactions back to a device

Use Firebase Cloud Functions and Cloud Messaging
Leverage on Firebase, as its easier to use on Android. This will be bundled in the example project, and not necessarily the only implementation that can be used

Lower MinSDK Support

We can do lower than API 16, to allow support on devices running old versions of Android

Error 2131427370

Every time I use this, the error is printed in the logcat. Nothing more that is helpful. What does it mean?

[Security] Is this library secure?

From what I can see, it requires the user inputting their callbacks, Passkeys, and even Business shortcodes.
This info cannot surely be mangled by anything whether proguard, or R8 or yGuard, which I presume some users
will even put the variables holding this info in static final Strings 🀣 making it easier for attackers.

If someone is to de-compile an app using this library what security is put into place to avoid leaking out the data stated on top.

EG:
A hacker decompiles, and just greps output for "https://" to get callback urls, and then begins sending dummy requests to it,
now if the user of this library has it that that callback is used to validate a purchase, a hacker can do unlimited purchases without paying a single coin.

This is just an example, I assume there are many more attack vectors.

Maybe users of the library can be adviced to not store those variables directly in their app but pull them from some REST Api in an encrypted format, decrypt on the device and use it?

Add Some Documentation on the code.

Is your feature request related to a problem? Please describe.

Not based on any problem but just some nice documentation of the code.

Describe the solution you'd like

The best approach is to comment on the code using Javadoc explaining what some of the methods do.

Describe alternatives you've considered
N/A

Additional context
N/A

Bad Request - Invalid BusinessShortCode

Describe the bug
I created a small demo and tried using the library but I keep getting this exception below. I went ahead and cloned this repo and executed it on my Android Studio but still the same exception. I then went ahead and replaced the credential with mine, but still the same error.

com.androidstudy.daraja.callback.DarajaException: 400.002.02 : Bad Request - Invalid BusinessShortCode

To Reproduce
Steps to reproduce the behavior:

  1. Run the demo once you clone this repo
  2. Input your phone number and amount
  3. Click on Pay Button
  4. The error will be toasted

ktLint is failing [Old dependencies maybe]

Describe the bug
We have a local bash script that runs analysis on the code, which fails

To Reproduce
Steps to reproduce the behavior:

  1. On your terminal, run ./codeAnalysis
  2. Check the error thrown on the console/emulator

Expected behavior
The task should run and complete successfully

Screenshots
If applicable, add screenshots to help explain your problem.

Ignore the .idea folder

Currently everything in the .idea folder is checked into VCS but some files are unique to each environment e.g. build_file_checksums. This causes issues when merging changes. It would really help if the folder can be ignored.

Streamlined API

I believe the API could be streamlined to support the common use cause of a business that wants to start receiving payments.
ie

//Final implementation
Daraja daraja = new Daraja.Builder() //could be injected or single instanced
                 .setConsumerKey("")
                  .setConsumerSecrtet("")
                    .setCallbackUrl("")
                    .setBusinessShortCode("")
                    .setAccountType(TransactionType.CustomerBuyGoodsOnline)
                    .setParty(""); //not sure if partyA or partyB

//simpler API requests that returns the DarajaListener
daraja.pay("phone", "amount", "description"); //creates an LNMExpress class from Daraja and does api request

Currently, LNMExpress class holds to much scope, some of which should be held in the Daraja class.

I am willing to create a PR to demonstrate the same

Update to androidX

Describe the bug
Add support for androidx

To Reproduce
Steps to reproduce the behavior:

  1. Build the app

Expected behavior
The given artifact contains a string literal with a package reference 'android.support.v4.content' that cannot be safely rewritten. Libraries using reflection such as annotation processors need to be updated manually to add support for androidx.

Error after stk push.

I am getting this error.
Failed. MPESA cannot complete this operation. The parameter is incorrect No till is found for CustomerPayMerchant.

Update README

The readme appears to have a broken badge, that needs to be removed and update it after the library overhaul.

  • Remove the contributing section -> maybe add a contributions.md file to outline best ways to accept contributions
  • Remove the license section -> since we have the license file on code
  • Remove DI specific samples (not everyone is using Dagger)
  • Update screenshots with a gif maybe - better visual representation

Migrate to mavenCentral()

Is your feature request related to a problem? Please describe.
jCenter() has been shut down, meaning we need to do the next release on mavenCentral() to keep this library alive πŸ˜„

Describe the solution you'd like
Setting up a way to publish the artifact to mavenCentral() directly, maybe starting the version 2.0.0

Can't resolve imports, or use current implementation in README

updated to v1.0.2

  • Can't resolve Daraja.Builder
  • Can't import Environment.SANDBOX previously from Env.SANDBOX
@Provides
    @Singleton
    Daraja providesDaraja() {
        return Daraja.Builder(Config.CONSUMER_KEY, Config.CONSUMER_SECRET)
                .setBusinessShortCode(Config.BUSINESS_SHORTCODE)
                .setPassKey(AppUtils.getPassKey())
                .setTransactionType(Config.ACCOUNT_TYPE)
                .setCallbackUrl(Config.CALLBACK_URL)
                .setEnvironment(Environment.SANDBOX)
                .build();
    }

Unknown error during handshake

I setup all the credentials as per the details provided on my daraja API account. I keep on getting the above named error in the console log. I am farely new to Daraja API so any assistance would be highly appreciated. Did I miss something? nothing happens when after I input the phone number and press 'Request MpesaExpress'

`//TODO :: REPLACE WITH YOUR OWN CREDENTIALS :: THIS IS SANDBOX DEMO
daraja = Daraja.with("[I set my own from daraja api]", "[same here", new DarajaListener() {
@OverRide
public void onResult(@nonnull AccessToken accessToken) {
Log.i(MPESAExpressActivity.this.getClass().getSimpleName(), accessToken.getAccess_token());
Toast.makeText(MPESAExpressActivity.this, "TOKEN : " + accessToken.getAccess_token(), Toast.LENGTH_SHORT).show();
}

        @Override
        public void onError(String error) {
            Log.e(MPESAExpressActivity.this.getClass().getSimpleName(), error);
        }
    });`

Set as well:

//TODO :: REPLACE WITH YOUR OWN CREDENTIALS :: THIS IS SANDBOX DEMO LNMExpress lnmExpress = new LNMExpress( "600616", "[set]", //https://developer.safaricom.co.ke/test_credentials TransactionType.CustomerBuyGoodsOnline, // TransactionType.CustomerPayBillOnline <- Apply any of these two "10", "254708374149", "174379", phoneNumber, "http://mycallbackurl.com/checkout.php", "001ABC", "Goods Payment" );

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.