adjustLoyaltyPoints method

Future<LoyaltyEvent> adjustLoyaltyPoints({
  1. required String accountId,
  2. required AdjustLoyaltyPointRequest request,
  3. String? authToken,
})

Adds points to or subtracts points from a buyer's account.

Use this endpoint only when you need to manually adjust points. Otherwise, in your application flow, you call AccumulateLoyaltyPoints to add points when a buyer pays for the purchase.

Implementation

Future<LoyaltyEvent> adjustLoyaltyPoints({
  required String accountId,
  required AdjustLoyaltyPointRequest 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/accounts/$accountId/adjust");

  //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)).event!;
  }
  else {
    print (response.body);
    throw LoyaltyException(statusCode: response.statusCode, message: LoyaltyEventResponse.fromJson(jsonDecode(response.body)).errors?[0].detail?.toString());
  }
}