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