readCharge method

Future<Charge> readCharge({
  1. required String chargeId,
  2. String? realmId,
  3. String? authToken,
})

Retrieves the details of a charge that has been previously created. Supply the id as returned in the charges response body from the previous create operation.

Implementation

Future<Charge> readCharge({
  required String chargeId,
  String? realmId,
  String? authToken,
}) async {
  authToken ??= authenticationService.getCachedToken()?.access_token;
  realmId ??= authenticationService.getCachedRealmId();

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

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

  //print(endpoint.toString());

  var response = await http.get(
    endpoint,
    headers: headers,
  );

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