cancelCommerceSubscriptionItem method

Future<CommerceSubscriptionItem?> cancelCommerceSubscriptionItem(
  1. String subscriptionItemId, {
  2. bool? endNow,
})

Cancel a subscription item

Cancel a specific subscription item. The subscription item can be canceled immediately or at the end of the current billing period.

Parameters:

  • String subscriptionItemId (required): The ID of the subscription item to cancel

  • bool endNow: Whether to cancel the subscription immediately (true) or at the end of the current billing period (false, default)

Implementation

Future<CommerceSubscriptionItem?> cancelCommerceSubscriptionItem(
  String subscriptionItemId, {
  bool? endNow,
}) async {
  final response = await cancelCommerceSubscriptionItemWithHttpInfo(
    subscriptionItemId,
    endNow: endNow,
  );
  if (response.statusCode >= HttpStatus.badRequest) {
    throw ApiException(response.statusCode, await _decodeBodyBytes(response));
  }
  // When a remote server returns no body with a status of 204, we shall not decode it.
  // At the time of writing this, `dart:convert` will throw an "Unexpected end of input"
  // FormatException when trying to decode an empty string.
  if (response.body.isNotEmpty &&
      response.statusCode != HttpStatus.noContent) {
    return await apiClient.deserializeAsync(
      await _decodeBodyBytes(response),
      'CommerceSubscriptionItem',
    ) as CommerceSubscriptionItem;
  }
  return null;
}