mpesa-daraja-plugin-flutter-dart
dart wrapper for mpesa daraja api by safaricom
Features
- [Done]Lipa na mpesa [x]
- [inprogress] C2B
- [inprogress] B2B
- [inprogress] C2B
- [inprogress] B2C
- [inprogress] TRANSACTION STATUS
- [inprogress] ACCOUNT BALANCE
- [inprogress] REVERSAL
Getting started
You Will need a few things from Safaricom before development.
- Consumer Key
- Consumer Secret
- 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
andConsumer 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
- Add dependancy in pubspec.yaml
dependencies:
mpesadaraja: ^0.1.2
Lipa Na MPesa Online
- creat
MpesaDaraja
object and pass the following parameters:
MpesaDaraja stkpush = MpesaDaraja(
consumerKey:<>
consumerSecret:<>
passKey:<>
)
or make it a final
as shown below:
final stkpush = MpesaDaraja(
consumerKey:<>
consumerSecret:<>
passKey:<>
)
- cosumerKey:
- consumerSecret
- passKey
-
The keys are generated when you create an app at [Daraja 2.0] website Click here to create your keys
-
The keys are a secret, so be sure to use them as environment variables in production code
- Use the object created to call
lipaNaMpesaStk()
function to initialize the process- if the function is inside anaother be sure to use a
Future
withawait
when caloing the function - pass the required parameters in the function as shwon below
- if the function is inside anaother be sure to use a
await stk.lipaNaMpesaStk(
<BusinnessShortCode>,
<Amount>,
<PartyA>,
<PartB>,
<PhoneNumber>,
<CallBackUrl>,
<AccountReference>,
<TransactionDescription>,
);
Parameters passed in lipaNaMpesaStk() function
BusinessShortCode
Amount
PartyA
PartyB
PhoneNUmber
CallBackUrl
AccountReference
TransactionDescription
Future<void> main() async {
final stk = MpesaDaraja(
consumerKey: 'Dm4oJgziMyOT7WTmJzQfEZS6jjzg1Frd',
consumerSecret: 'RGRvsUGkO4jc3NuW',
passKey: 'bfb279f9aa9bdbcf158e97dd71a467cd2e0c893059b10f78e6b72ada1ed2c919',
);
await stk.lipaNaMpesaStk(
"174379",
1,
"254798071520",
"174379",
"254798071520",
"https://mydomain.com/path",
"accountReference",
"transactionDesc",
);
}
Demo
- coming soon ....