createDebit method

Future<ECheck> createDebit({
  1. required String requestId,
  2. required ECheck echeck,
  3. String? realmId,
  4. String? authToken,
})

To process an E-check, you create a new debit object.

Implementation

Future<ECheck> createDebit({
  required String requestId,
  required ECheck echeck,
  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/echecks");

  //print(endpoint.toString());

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

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