validatePayment static method
Validates payments with OTP returns an instance of ChargeResponse or throws an error
Implementation
static Future<ChargeResponse> validatePayment(
String otp,
String flwRef,
http.Client client,
final bool isDebugMode,
final String publicKey,
final isBankAccount,
[String feature = ""]) async {
final stopWatch = Stopwatch();
final url = FlutterwaveURLS.getBaseUrl(isDebugMode) +
FlutterwaveURLS.VALIDATE_CHARGE;
final uri = Uri.parse(url);
final ValidateChargeRequest chargeRequest =
ValidateChargeRequest(otp, flwRef, isBankAccount);
final payload = chargeRequest.toJson();
try {
final http.Response response = await client.post(uri,
headers: {HttpHeaders.authorizationHeader: publicKey}, body: payload);
if (feature.isNotEmpty) {
MetricManager.logMetric(
client, publicKey, feature, "${stopWatch.elapsedMilliseconds}ms");
}
final ChargeResponse cardResponse =
ChargeResponse.fromJson(jsonDecode(response.body));
return cardResponse;
} catch (error) {
if (feature.isNotEmpty) {
MetricManager.logMetric(client, publicKey, "{$feature}_ERROR",
"${stopWatch.elapsedMilliseconds}ms");
}
throw (FlutterWaveError(error.toString()));
}
}