Lipa Na Mpesa Android Sample

This app demonstrates how to impeliment Lipa Na MPESA Online. Documentation on the API can be found on [Safaricom Developer Portal] (


Getting Safaricom Credentials

  1. Create an account on the [Safaricom Developer Portal] (
  2. Create a Lipa na MPESA Online App

Project Setup

  1. Rename file to then add you Consumer key and Consumer secret.
  2. Copy sample-google-services.json inside app directory and rename it to google-services.json. This will ensure your project build without an error.


sample-google-services.json is just a sample file to help you bypass build error due to a google-services.json missing.

Firebase Setup

In order to send push notifications to the user, you will need to setup [FCM - Firebase Cloud Messaging Service] ( AndroidHive has an awesome tutorial on this.


Add an item to the cart:

alt text

Add a customers phone number:

alt text

The STK push payment popup is sent to the customer phone:

alt text

MPESA confirmation message:

alt text

Payment confirmation from the API callback:

alt text

Libraries Used

  1. [Sweet alerts] (
  2. [Butterknife] (
  3. [Retrofit] (
  4. [GSON] (
  5. [FireBase] (
  6. [Okhttp] (
  7. [okio] (
  8. OkHttp Interceptors
  9. [Timber] (