createCard method
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);
}
}