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
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 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);
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
);
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: "",
);
try{
_res = await mpesa.fetchToken;
print(_res['token'])
}catch(e){
print(e)
}
See examples or docs for more