getUserBillingSubscription method

Future<CommerceSubscription?> getUserBillingSubscription(
  1. String userId
)

Retrieve a user's billing subscription

Retrieves the billing subscription for the specified user. This includes subscription details, active plans, billing information, and payment status. The subscription contains subscription items which represent the individual plans the user is subscribed to.

Parameters:

  • String userId (required): The ID of the user whose subscription to retrieve

Implementation

Future<CommerceSubscription?> getUserBillingSubscription(
  String userId,
) async {
  final response = await getUserBillingSubscriptionWithHttpInfo(
    userId,
  );
  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),
      'CommerceSubscription',
    ) as CommerceSubscription;
  }
  return null;
}