> ## Documentation Index
> Fetch the complete documentation index at: https://docs.crovver.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Create Checkout Session

> Create a payment provider checkout session for a tenant.

Creates a checkout session with the configured payment provider (Stripe, Khalti, eSewa) and returns a URL to redirect the user to.

## Request Body

<ParamField body="planId" type="string" required>
  The Crovver plan ID to subscribe to
</ParamField>

<ParamField body="externalUserId" type="string">
  The user ID from your application. Required for D2C orgs — becomes the tenant identity.
</ParamField>

<ParamField body="externalTenantId" type="string">
  The workspace/tenant ID. Required for B2B orgs.
</ParamField>

<ParamField body="provider" type="string">
  Payment provider name (`stripe`, `khalti`, `esewa`). Defaults to the org's configured provider.
</ParamField>

<ParamField body="currency" type="string">
  3-letter ISO currency code (e.g. `USD`, `NPR`). Defaults to the plan's first active price currency.
</ParamField>

<ParamField body="totalCapcityUnits" type="integer">
  Number of seats to purchase. Required for seat-based plans.
</ParamField>

<ParamField body="userEmail" type="string">
  Pre-fills the payment provider's checkout form with this email.
</ParamField>

<ParamField body="userName" type="string">
  Pre-fills the payment provider's checkout form with this name.
</ParamField>

<ParamField body="successUrl" type="string">
  URL to redirect to after successful payment. Defaults to the org's configured success URL.
</ParamField>

<ParamField body="cancelUrl" type="string">
  URL to redirect to if the user cancels checkout. Defaults to the org's configured cancel URL.
</ParamField>

<ParamField body="metadata" type="object">
  Arbitrary key-value pairs passed through to the payment provider.
</ParamField>

## Authentication

Requires a **secret key** (`Authorization: Bearer sk_live_...`) or **service key** (`x-service-key` + `?orgId=`).

<RequestExample>
  ```bash cURL (D2C) theme={null}
  curl -X POST "https://app.crovver.com/api/public/checkout" \
    -H "Authorization: Bearer sk_live_..." \
    -H "Content-Type: application/json" \
    -d '{
      "externalUserId": "user_123",
      "planId": "7b79a62c-e82e-405f-9719-7314f3d6e7f2",
      "provider": "stripe",
      "successUrl": "https://app.com/welcome",
      "cancelUrl": "https://app.com/pricing"
    }'
  ```

  ```bash cURL (B2B) theme={null}
  curl -X POST "https://app.crovver.com/api/public/checkout" \
    -H "Authorization: Bearer sk_live_..." \
    -H "Content-Type: application/json" \
    -d '{
      "externalTenantId": "company_acme_123",
      "externalUserId": "user_admin_456",
      "planId": "7b79a62c-e82e-405f-9719-7314f3d6e7f2",
      "provider": "stripe",
      "successUrl": "https://app.com/welcome",
      "cancelUrl": "https://app.com/pricing"
    }'
  ```
</RequestExample>

<ResponseExample>
  ```json 201 theme={null}
  {
    "success": true,
    "data": {
      "checkoutUrl": "https://checkout.stripe.com/pay/cs_test_...",
      "sessionId": "cs_test_...",
      "subscriptionId": "sub_crovver_abc"
    }
  }
  ```
</ResponseExample>
