createCard method

Future<Card> createCard({
  1. required String requestId,
  2. required String customerId,
  3. required Card card,
  4. String? realmId,
  5. String? authToken,
})

This operation allows you to store a new card object. Note that this card is only accessible via the Payments API. It will not appear in QuickBooks Online.

Implementation

Future<Card> createCard({
  required String requestId,
  required String customerId,
  required Card card,
  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/customers/$customerId/cards");

  //print (endpoint.toString());

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

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