I have integrated this plugin in my flutter app and when I first load up the app it works well, but on repeated trials it does not work. What I mean is that yes it launching the STK push for payment but when the payment is done, it's not redirecting safaricom to my callback url so that the response can be stored there. The only way repeated trials are working is when I change the account reference, save the app then run it again.
Here's the code`
// Create the lipaNaMpesa method here.
Future lipaNaMpesa({String type}) async {
dynamic transactionInitialisation;
try {
transactionInitialisation =
await MpesaFlutterPlugin.initializeMpesaSTKPush(
businessShortCode: '174379',
transactionType: TransactionType.CustomerPayBillOnline,
amount: 1.0,
partyA: phonenumber,
partyB: '174379',
callBackURL: Uri(
scheme: 'https',
host: globals.apiKey,
path: 'mpesacallbackURL',
),
transactionDesc: 'Parking pass',
accountReference: 'Parking Kenya Limited',
phoneNumber: phonenumber,
baseUri: Uri(scheme: "https", host: "sandbox.safaricom.co.ke"),
passKey:
'test passKey',
);
// Here I'm checking if the STK push launched successfully.
if (transactionInitialisation['ResponseCode'] == '0') {
// Here I'm waiting for the user to enter his pin before checking whether the response is in the database.
timer = new Timer(const Duration(seconds: 4), () async {
try {
// Check if the transaction is in the db
var response = await fetchTransaction();
// If the transaction is there...show success message.
} catch (err) {
// If it's not then...show error message.
}
});
}
return transactionInitialisation;
} catch (e) {
log("CAUGHT EXCEPTION: " + e.toString());
}
I have integrated this plugin in my flutter app and when I first load up the app it works well, but on repeated trials it does not work. What I mean is that yes it launching the STK push for payment but when the payment is done, it's not redirecting safaricom to my callback url so that the response can be stored there. The only way repeated trials are working is when I change the account reference, save the app then run it again. Here's the code` lipaNaMpesa({String type}) async {
dynamic transactionInitialisation;
// Create the lipaNaMpesa method here. Future
}`