Skip to content

This library contains methods that make it easy to consume Mpesa Api.

License

Notifications You must be signed in to change notification settings

EddieKamau/dart_mpesa

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

41 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

dart_mpesa

Buy Me A Coffee

This library contains methods that make it easy to consume Mpesa Api. It's multi-platform, and supports CLI, server, mobile, desktop, and the browser.

Ready Methods/APIs include

  • LIPA NA MPESA
  • STKPUSH QUERY
  • C2BSIMULATE
  • B2B
  • B2C
  • C2B
  • TRANSACTION STATUS
  • ACCOUNT BALANCE
  • REVERSAL

Usage

Create an instance of Mpesa, then use its methods to consume the Api

import 'package:dart_mpesa/dart_mpesa.dart';

main() {
  var mpesa = Mpesa(
    shortCode: "",
    consumerKey: "",
    consumerSecret: "",
    initiatorName: "",
    securityCredential: "",
    passKey: "",
    identifierType: IdentifierType.OrganizationShortCode, // Type of organization, options, OrganizationShortCode, TillNumber, OrganizationShortCode
    applicationMode: ApplicationMode.test
  );
}

lipa na mpesa online

LIPA NA M-PESA ONLINE API also know as M-PESA express (STK Push) is a Merchant/Business initiated C2B (Customer to Business) Payment.

  MpesaResponse _res = await mpesa.lipanaMpesaOnline(
    phoneNumber: "",
    amount: 0,
    accountReference: "",
    transactionDesc: "",
    callBackURL: "", 
  );

  print(_res.statusCode);
  print(_res.rawResponse);
  print(_res.responseDescription);

B2B

The Business to Business (B2B) API is used to transfer money from one business to another business.

  _res = await mpesa.b2bTransaction(
    shortCode: "",
    amount: 0,
    remarks: "",
    accountReference: "", // optional
    resultURL: "", 
    queueTimeOutURL: "",
    identifierType: IdentifierType.OrganizationShortCode, // options, OrganizationShortCode, TillNumber, OrganizationShortCode
    commandID: BbCommandId.BusinessToBusinessTransfer, // options, BusinessToBusinessTransfer, BusinessPayBill, BusinessBuyGoods, DisburseFundsToBusiness, MerchantToMerchantTransfer
  );

B2B buy goods

A transfer of funds from one Organization's Working Account to another Organization's Merchant Account.

  _res = await mpesa.b2bBuyGoodsTransaction(
    shortCode: "",
    amount: 0,
    remarks: "",
    resultURL: "", 
    queueTimeOutURL: "",
  );

fetch token

  try{
    _res = await mpesa.fetchToken;
    print(_res['token'])
  }catch(e){
    print(e)
  }

See examples or docs for more

About

This library contains methods that make it easy to consume Mpesa Api.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages