createPortalSession method

Future<String> createPortalSession({
  1. String? orgId,
})

Request a Stripe Billing Portal URL for managing the subscription.

Pass orgId for org subscriptions, or omit for the caller's solo sub.

Implementation

Future<String> createPortalSession({String? orgId}) async {
  final response = await _client.functions.invoke(
    'create-portal-session',
    body: {'org_id': ?orgId},
  );

  if (response.status != 200) {
    throw StateError(
      'createPortalSession failed (${response.status}): ${response.data}',
    );
  }
  final url = response.data?['url'] as String?;
  if (url == null) throw StateError('createPortalSession returned no url');
  return url;
}