captureCharge method

Future<Charge> captureCharge({
  1. required String requestId,
  2. required String chargeId,
  3. required String amount,
  4. String? description,
  5. PaymentContext? context,
  6. String? realmId,
  7. String? authToken,
})

Capture charge funds

Implementation

Future<Charge> captureCharge({
  required String requestId,
  required String chargeId,
  required String amount,
  String? description,
  PaymentContext? context,
  String? realmId,
  String? authToken,
}) async {
  authToken ??= authenticationService.getCachedToken()?.access_token;
  realmId ??= authenticationService.getCachedRealmId();

  Map<String, String> headers = {
    "Request-ID": requestId,
    "Authorization": "Bearer ${authToken ?? ""}",
    'Content-Type': 'application/json',
    //'Accept': 'application/json',
  };

  Uri endpoint =
      Uri.https(baseUrl, "/quickbooks/v4/payments/charges/$chargeId/capture");

  //print(endpoint.toString());

  var charge = Charge(
      amount: amount,
      context: context,
      description: description);

  var response = await http.post(endpoint,
      headers: headers, body: jsonEncode(charge.toJson()));

  if (response.statusCode == 200 || response.statusCode == 201) {
    //print (response.body);
    return Charge.fromJson(jsonDecode(response.body));
  } else {
    throw ChargeException(
        statusCode: response.statusCode, message: response.body);
  }
}