verifyPayment static method

Future<ChargeResponse> verifyPayment(
  1. String flwRef,
  2. Client client,
  3. String publicKey,
  4. bool isDebugMode, [
  5. String feature = "",
])

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()));
  }
}