mpesa 1.0.0

  • Readme
  • Changelog
  • Example
  • Installing
  • 72

mpesa #

A dart wrapper around mpesa daraja api.

Ready Methods/APIs

  • [ ] B2B
  • [ ] C2B
  • [ ] B2C
  • [ ] REVERSAL

Requisites #

You Will need a few things from Safaricom before development.

  1. Consumer Key
  2. Consumer Secret
  3. Test Credentials for Development/Sanbox environment
  • Login or Register as a Safaricom developer here if you haven't.
  • Add a new App here
  • You will be issued with a Consumer Key and Consumer Secret. You will use these to initiate an Mpesa Instance.
  • Obtain Test Credentials here.
    • The Test Credentials Obtained Are only valid in Sandbox/Development environment. Take note of them.
    • To run in Production Environment you will need real Credentials.
      • To go Live and be issued with real credentials,please refer to this guide

Getting Started #

Add dependency in pubspec.yaml


Import in your Flutter app or plain dart app.

import 'package:mpesa/mpesa.dart';

class MYClass {

    Mpesa mpesa = Mpesa(
        clientKey: "YOUR_CONSUMER_KEY_HERE",
        clientSecret: "YOUR_CONSUMER_SECRET_HERE",
        passKey: "YOUR_LNM_PASS_KEY_HERE",
        initiatorPassword: "YOUR_SECURITY_CREDENTIAL_HERE",
        environment: "sandbox",


For the initiator_password, use the security credential from the test credentials. You'll also find passkey on the same page.

Environment should be either sandbox or production

Methods and Api Calls #

Lipa Na Mpesa Online (LNMO) #

Lipa na M-Pesa Online Payment API is used to initiate a M-Pesa transaction on behalf of a customer using STK Push. This is the same technique mySafaricom App uses whenever the app is used to make payments.

import 'package:mpesa/mpesa.dart';

class MYClass {

                phoneNumber: "",
                amount: 1,
                businessShortCode: "",
                callbackUrl: "",
            .then((result) {})
            .catchError((error) {});
  1. businessShortCode - The organization shortcode used to receive the transaction.
  2. amount - The amount to be transacted.
  3. phoneNumber - The MSISDN sending the funds.
  4. callbackUrl - The url to where responses from M-Pesa will be sent to.

Features and bugs #

Please file feature requests and bugs at the issue tracker.

Recording #


Contributing #


  1. Fork the project then clone the forked project
  2. Create your feature branch: git checkout -b my-new-feature
  3. Make your changes and add name to Contributors list below and in authors in pubspec.yaml
  4. Commit your changes: git commit -m 'Add some feature'
  5. Push to the branch: git push origin my-new-feature
  6. Submit a pull request.

Credits #

| Contributors | #

| Newton Munene |

For help getting started with Flutter, view their online documentation, which offers tutorials, samples, guidance on mobile development, and a full API reference.

mpesa #

Any entries below v1.0.0 will not be useful 😅😅

[0.0.1] - 14/8/2019

  • Init to win it

[0.0.2] - 14/8/2019

  • Added barebones Lipa na Mpesa method

[0.0.3] - 14/8/2019

  • Some tweaking.

[0.0.4-dev.1] - 29/8/2019

  • Rewrite to support plain dart without flutter

[1.0.0] - 29/8/2019

  • Stable release
  • Shipped Lipa Na Mpesa method
  • Improved docs


import 'package:mpesa/mpesa.dart';

void main() {
  var mpesa = Mpesa(
    clientKey: "YOUR_CONSUMER_KEY_HERE",
    clientSecret: "YOUR_CONSUMER_SECRET_HERE",
    passKey: "YOUR_LNM_PASS_KEY_HERE",
    initiatorPassword: "YOUR_SECURITY_CREDENTIAL_HERE",
    environment: "sandbox",

        phoneNumber: "",
        amount: 1,
        businessShortCode: "",
        callbackUrl: "",
      .then((result) {})
      .catchError((error) {});

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:

  mpesa: ^1.0.0

2. Install it

You can install packages from the command line:

with pub:

$ pub get

with Flutter:

$ flutter pub get

Alternatively, your editor might support pub get or flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:

import 'package:mpesa/mpesa.dart';
Describes how popular the package is relative to other packages. [more]
Code health derived from static analysis. [more]
Reflects how tidy and up-to-date the package is. [more]
Weighted score of the above. [more]
Learn more about scoring.

We analyzed this package on Oct 21, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.5.1
  • pana: 0.12.21


Detected platforms: Flutter, other

Primary library: package:mpesa/mpesa.dart with components: io.

Health suggestions

Fix lib/src/mpesa_base.dart. (-2.48 points)

Analysis of lib/src/mpesa_base.dart reported 5 hints:

line 2 col 8: Unused import: 'dart:io'.

line 19 col 16: The value of the field '_clientKey' isn't used.

line 20 col 16: The value of the field '_clientSecret' isn't used.

line 21 col 16: The value of the field '_environment' isn't used.

line 24 col 10: The value of the field '_securityCredential' isn't used.


Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.4.0 <3.0.0
http ^0.12.0+2 0.12.0+2
meta ^1.1.6 1.1.7
Transitive dependencies
async 2.4.0
charcode 1.1.2
collection 1.14.12
http_parser 3.1.3
path 1.6.4
source_span 1.5.5
string_scanner 1.0.5
term_glyph 1.1.0
typed_data 1.1.6
Dev dependencies
pedantic ^1.7.0 1.8.0+1
test ^1.6.0