searchLoyaltyEvents method

Future<LoyaltyEventResponse> searchLoyaltyEvents({
  1. required SearchLoyaltyEventsRequest request,
  2. String? authToken,
})

Searches for loyalty events.

A Square loyalty program maintains a ledger of events that occur during the lifetime of a buyer's loyalty account. Each change in the point balance (for example, points earned, points redeemed, and points expired) is recorded in the ledger. Using this endpoint, you can search the ledger for events.

Implementation

Future<LoyaltyEventResponse> searchLoyaltyEvents({
  required SearchLoyaltyEventsRequest 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/loyalty/events/search");

  //print (endpoint.toString());

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

  if (response.statusCode == 200) {
    print (jsonDecode(response.body));
    return LoyaltyEventResponse.fromJson(jsonDecode(response.body));
  }
  else {
    print (response.body);
    throw LoyaltyException(statusCode: response.statusCode, message: LoyaltyEventResponse.fromJson(jsonDecode(response.body)).errors?[0].detail?.toString());
  }
}