payWithAccount method

Future<ChargeResponse> payWithAccount(
  1. BankAccountPaymentRequest bankAccountRequest,
  2. Client client
)

Initiates payments via Bank Account Available for only payments with NGN currency returns an instance of ChargeResponse or throws an error

Implementation

Future<ChargeResponse> payWithAccount(
    BankAccountPaymentRequest bankAccountRequest, http.Client client) async {
  final stopWatch = Stopwatch();
  final requestBody = bankAccountRequest.toJson();

  final url = FlutterwaveURLS.getBaseUrl(this.isDebugMode) +
      FlutterwaveURLS.PAY_WITH_ACCOUNT;
  final uri = Uri.parse(url);
  try {
    final http.Response response = await client.post(uri,
        headers: {
          HttpHeaders.authorizationHeader: this.publicKey,
          HttpHeaders.contentTypeHeader: "application/json"
        },
        body: jsonEncode(requestBody));

    MetricManager.logMetric(
        client,
        publicKey,
        MetricManager.INITIATE_ACCOUNT_CHARGE,
        "${stopWatch.elapsedMilliseconds}ms");

    ChargeResponse bankTransferResponse =
        ChargeResponse.fromJson(json.decode(response.body));

    return bankTransferResponse;
  } catch (error) {

    MetricManager.logMetric(
        client,
        publicKey,
        MetricManager.INITIATE_ACCOUNT_CHARGE_ERROR,
        "${stopWatch.elapsedMilliseconds}ms");
    throw (FlutterError(error.toString()));
  }
}