listCustomer method
Lists customer profiles associated with a Square account.
Under normal operating conditions, newly created or updated customer profiles become available for the listing operation in well under 30 seconds. Occasionally, propagation of the new or updated profiles can take closer to one minute or longer, especially during network incidents and outages.
Implementation
Future<List<Customer>> listCustomer({
required ListCustomerRequest request,
String? authToken,
}) async {
authToken ??= authenticationService.getCachedToken()?.accessToken;
Map<String, String> headers = {
"Authorization": "Bearer ${authToken ?? ""}",
'Content-Type': 'application/json; charset=UTF-8',
'Accept': 'application/json',
};
Uri endpoint = Uri.https(
baseUrl, "/v2/customers", request.toJson().toQueryParam());
//print (endpoint.toString());
var response = await
http.get(endpoint, headers: headers);
if (response.statusCode == 200) {
print (jsonDecode(response.body));
return CustomerResponse.fromJson(jsonDecode(response.body)).customers!;
}
else {
print (response.body);
throw CustomerException(statusCode: response.statusCode, message: CustomerResponse.fromJson(jsonDecode(response.body)).errors?[0].detail?.toString());
}
}