createAccount method

Future<BankAccount> createAccount({
  1. required String requestId,
  2. required String customerId,
  3. required BankAccount account,
  4. String? realmId,
  5. String? authToken,
})

Creates a bank account

Implementation

Future<BankAccount> createAccount({
  required String requestId,
  required String customerId,
  required BankAccount account,
  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',
  };


  //v4/customers/2/bank-accounts
  Uri endpoint = Uri.https(
      baseUrl, "/quickbooks/v4/customers/$customerId/bank-accounts");

  //print (endpoint.toString());

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

  if (response.statusCode == 200 || response.statusCode == 201) {
      return BankAccount.fromJson(jsonDecode(response.body));
  }
  else {
    throw BankAccountException(statusCode: response.statusCode, message: response.body);
  }
}