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

# 구독 결제 세션 생성

> 플랜 구독을 위한 Stripe Checkout 세션을 만듭니다.

## 개요

플랜 구독용 Stripe Checkout 세션을 생성합니다. 사용자를 결제를 완료할 URL로 보내면 됩니다. 세션 기반 인증(JWT 액세스 토큰)이 필요합니다.

<Note>
  **서드파티 연동:** API 키 인증을 사용할 때는 대신 `POST /subscriptions/checkout/api`를 사용하세요.
</Note>

## 인증

<ParamField header="Authorization" type="string" required>
  JWT 액세스 토큰입니다. 형식: `Bearer YOUR_ACCESS_TOKEN`
</ParamField>

## 요청 본문

<ParamField body="planId" type="string" required>
  구독할 플랜 식별자입니다. `starter`, `professional`, `business`, `agency` 중 하나여야 합니다.
</ParamField>

<ParamField body="billingCycle" type="string" default="monthly">
  과금 주기입니다. 옵션: `monthly` 또는 `yearly`입니다.
</ParamField>

<ParamField body="successUrl" type="string">
  결제 성공 후 리디렉션할 URL입니다. 기본값은 앱 대시보드입니다.
</ParamField>

<ParamField body="cancelUrl" type="string">
  사용자가 결제를 취소했을 때 리디렉션할 URL입니다. 기본값은 요금 페이지입니다.
</ParamField>

<RequestExample>
  ```bash cURL theme={null}
  curl -X POST https://api.llmgenerator.com/api/v1/subscriptions/checkout \
    -H "Authorization: Bearer YOUR_ACCESS_TOKEN" \
    -H "Content-Type: application/json" \
    -d '{
      "planId": "professional",
      "successUrl": "https://yourapp.com/subscription/success",
      "cancelUrl": "https://yourapp.com/pricing"
    }'
  ```

  ```javascript JavaScript theme={null}
  const response = await fetch('https://api.llmgenerator.com/api/v1/subscriptions/checkout', {
    method: 'POST',
    headers: {
      'Authorization': 'Bearer YOUR_ACCESS_TOKEN',
      'Content-Type': 'application/json'
    },
    body: JSON.stringify({
      planId: 'professional',
      successUrl: 'https://yourapp.com/subscription/success',
      cancelUrl: 'https://yourapp.com/pricing'
    })
  });

  const data = await response.json();
  // Redirect user to Stripe checkout
  window.location.href = data.url;
  ```

  ```python Python theme={null}
  import requests

  response = requests.post(
      'https://api.llmgenerator.com/api/v1/subscriptions/checkout',
      headers={
          'Authorization': 'Bearer YOUR_ACCESS_TOKEN',
          'Content-Type': 'application/json'
      },
      json={
          'planId': 'professional',
          'successUrl': 'https://yourapp.com/subscription/success',
          'cancelUrl': 'https://yourapp.com/pricing'
      }
  )
  data = response.json()
  print(f"Redirect to: {data['url']}")
  ```
</RequestExample>

<ResponseExample>
  ```json Response theme={null}
  {
    "sessionId": "cs_test_a1b2c3d4e5f6g7h8i9j0",
    "url": "https://checkout.stripe.com/c/pay/cs_test_a1b2c3d4...",
    "plan": {
      "id": "professional",
      "name": "Professional",
      "monthlyCredits": 3000,
      "priceCents": 1299
    }
  }
  ```
</ResponseExample>

## 응답 필드

<ResponseField name="sessionId" type="string">
  Stripe Checkout 세션 ID입니다. 이후 세션 검증 등에 사용할 수 있습니다.
</ResponseField>

<ResponseField name="url" type="string">
  사용자를 보낼 결제 페이지 URL입니다. Stripe에서 호스트하는 결제 페이지입니다.
</ResponseField>

<ResponseField name="plan" type="object">
  선택된 플랜 상세 정보입니다.
</ResponseField>

## 결제 흐름

1. **세션 생성**: 원하는 플랜으로 이 엔드포인트를 호출합니다
2. **사용자 리디렉션**: 반환된 `url`로 사용자를 이동시킵니다
3. **결제 처리**: 사용자가 Stripe에서 결제를 완료합니다
4. **웹훅**: Stripe가 웹훅 엔드포인트에 알립니다
5. **성공 리디렉션**: 사용자가 `successUrl`로 돌아옵니다
6. **검증(선택)**: `/subscriptions/current`로 구독 상태를 확인합니다

## 오류 응답

<ResponseField name="400">
  잘못된 요청 — 잘못된 플랜 ID 또는 이미 활성 구독이 있는 경우입니다.
</ResponseField>

<ResponseField name="401">
  인증 실패 — 토큰이 없거나 유효하지 않습니다.
</ResponseField>

<Note>
  이미 활성 구독이 있는 사용자는 플랜 변경을 위해 결제 대신 청구 포털(`/subscriptions/portal`)을 사용해야 합니다.
</Note>

***

## POST /subscriptions/checkout/api

API 키 인증으로 Stripe Checkout 세션을 생성합니다. 서드파티 연동에 적합합니다.

### 인증

API 키 인증이 필요합니다. `Authorization` 헤더에 API 키를 넣습니다:

```
Authorization: Bearer llmgen_your_api_key_here
```

### 요청 본문

`/subscriptions/checkout`와 동일합니다.

### 응답

`/subscriptions/checkout`와 동일합니다.

<RequestExample>
  ```bash cURL theme={null}
  curl -X POST https://api.llmgenerator.com/api/v1/subscriptions/checkout/api \
    -H "Authorization: Bearer llmgen_your_api_key_here" \
    -H "Content-Type: application/json" \
    -d '{
      "planId": "professional",
      "successUrl": "https://yourapp.com/subscription/success",
      "cancelUrl": "https://yourapp.com/pricing"
    }'
  ```

  ```javascript JavaScript theme={null}
  const response = await fetch('https://api.llmgenerator.com/api/v1/subscriptions/checkout/api', {
    method: 'POST',
    headers: {
      'Authorization': 'Bearer llmgen_your_api_key_here',
      'Content-Type': 'application/json'
    },
    body: JSON.stringify({
      planId: 'professional',
      successUrl: 'https://yourapp.com/subscription/success',
      cancelUrl: 'https://yourapp.com/pricing'
    })
  });

  const data = await response.json();
  // Redirect user to Stripe checkout
  window.location.href = data.url;
  ```

  ```python Python theme={null}
  import requests

  response = requests.post(
      'https://api.llmgenerator.com/api/v1/subscriptions/checkout/api',
      headers={
          'Authorization': 'Bearer llmgen_your_api_key_here',
          'Content-Type': 'application/json'
      },
      json={
          'planId': 'professional',
          'successUrl': 'https://yourapp.com/subscription/success',
          'cancelUrl': 'https://yourapp.com/pricing'
      }
  )
  data = response.json()
  print(f"Redirect to: {data['url']}")
  ```
</RequestExample>
