createCheckoutSession method

Future<String> createCheckoutSession({
  1. required String plan,
  2. required String interval,
  3. String? orgId,
  4. int? seats,
})

Request a Stripe Checkout URL for the given plan.

  • For team and enterprise, orgId is required and must be owned by the caller.
  • For professional on the web, omit orgId.
  • seats is only used for per-seat org plans; it defaults to the current seat count on the server side if omitted.

Implementation

Future<String> createCheckoutSession({
  required String plan,
  required String interval,
  String? orgId,
  int? seats,
}) async {
  final response = await _client.functions.invoke(
    'create-checkout-session',
    body: {
      'plan': plan,
      'interval': interval,
      'org_id': ?orgId,
      'seats': ?seats,
    },
  );

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