payWithCard method
Initiates Card Request
Implementation
Future<dynamic> payWithCard(final http.Client client,
final ChargeCardRequest chargeCardRequest) async {
this.chargeCardRequest = chargeCardRequest;
if (this.cardPaymentListener == null) {
this.cardPaymentListener!.onError("No CardPaymentListener Attached.");
return;
}
_stopwatch.start();
Map<String, String> encryptedPayload;
try {
encryptedPayload = this._prepareRequest(chargeCardRequest);
} catch(error, stacktrace) {
print(stacktrace);
this
.cardPaymentListener
?.onError("Unable to encrypt request. Please try again");
return;
}
try {
final url = FlutterwaveURLS.getBaseUrl(this.isDebugMode) +
FlutterwaveURLS.CHARGE_CARD_URL;
final uri = Uri.parse(url);
final http.Response response = await client.post(uri,
headers: {
HttpHeaders.authorizationHeader: this.publicKey,
HttpHeaders.contentTypeHeader: "application/json"
},
body: jsonEncode(encryptedPayload));
this._handleResponse(response);
} catch (error, stacktrace) {
print(stacktrace);
this
.cardPaymentListener
?.onError("Unable to initiate card transaction.");
return;
} finally {
_stopwatch.stop();
}
}