dart_mpesa
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
- [x] lipa na mpesa
- [x] stkpush query
- [x] c2bsimulate
- [x] b2b
- [x] b2c
- [x] c2b
- [x] transaction status
- [x] account balance
- [x] 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
Comments are closed.