payWithMpesa method
Initiates payments via Mpesa Available for only payments with KES currency returns an instance of ChargeResponse or throws an error
Implementation
Future<ChargeResponse> payWithMpesa(
MpesaRequest payload, http.Client client) async {
final url = FlutterwaveURLS.getBaseUrl(this.isDebugMode) +
FlutterwaveURLS.PAY_WITH_MPESA;
final uri = Uri.parse(url);
try {
final http.Response response = await client.post(uri,
headers: {
HttpHeaders.authorizationHeader: this.publicKey,
HttpHeaders.contentTypeHeader:'application/json'
},
body: json.encode(payload.toJson()));
ChargeResponse chargeResponse =
ChargeResponse.fromJson(json.decode(response.body));
return chargeResponse;
} catch (error) {
throw (FlutterError(error.toString()));
} finally {
client.close();
}
}