> ## 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 세션을 만드는 엔드포인트입니다.

## POST /credits/checkout

사용자가 크레딧 패키지를 결제할 수 있도록 Stripe Checkout 세션을 생성합니다. 세션 기반 인증(로그인으로 받은 JWT 액세스 토큰)이 필요합니다.

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

### 요청 본문

<ParamField body="packageId" type="string" required>
  구매할 크레딧 패키지 ID입니다. 가능한 패키지는 `/credits/packages`에서 확인합니다.
</ParamField>

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

<ParamField body="cancelUrl" type="string">
  결제 취소 시 리디렉션할 URL입니다. 기본값은 대시보드의 취소 표시 페이지입니다.
</ParamField>

### 응답

<ResponseField name="sessionId" type="string">
  Stripe Checkout 세션 ID입니다.
</ResponseField>

<ResponseField name="url" type="string">
  Stripe 결제 페이지 URL입니다. 사용자를 이 주소로 보내 결제를 완료하게 합니다.
</ResponseField>

<ResponseField name="package" type="object">
  선택한 패키지 정보입니다.

  <Expandable title="패키지 속성">
    <ResponseField name="id" type="string">
      패키지 식별자입니다.
    </ResponseField>

    <ResponseField name="name" type="string">
      패키지 이름입니다.
    </ResponseField>

    <ResponseField name="credits" type="number">
      패키지에 포함된 크레딧 수입니다.
    </ResponseField>

    <ResponseField name="priceCents" type="number">
      가격(센트)입니다.
    </ResponseField>
  </Expandable>
</ResponseField>

<RequestExample>
  ```bash cURL theme={null}
  curl -X POST https://api.llmgenerator.com/api/v1/credits/checkout \
    -H "Authorization: Bearer YOUR_ACCESS_TOKEN" \
    -H "Content-Type: application/json" \
    -d '{
          "packageId": "pkg_pro",
          "successUrl": "https://example.com/success?session_id={CHECKOUT_SESSION_ID}",
          "cancelUrl": "https://example.com/cancel"
        }'
  ```

  ```javascript Node.js theme={null}
  const response = await fetch('https://api.llmgenerator.com/api/v1/credits/checkout', {
    method: 'POST',
    headers: {
      'Authorization': 'Bearer YOUR_ACCESS_TOKEN',
      'Content-Type': 'application/json'
    },
    body: JSON.stringify({
      packageId: 'pkg_pro'
    })
  });

  const data = await response.json();
  // Redirect user to data.url
  window.location.href = data.url;
  ```
</RequestExample>

<ResponseExample>
  ```json Success (200) theme={null}
  {
    "sessionId": "cs_test_a1b2c3d4e5f6g7h8i9j0",
    "url": "https://checkout.stripe.com/c/pay/cs_test_a1b2c3d4e5f6g7h8i9j0",
    "package": {
      "id": "pkg_pro",
      "name": "Pro Pack",
      "credits": 500,
      "priceCents": 1999
    }
  }
  ```

  ```json Package Not Found (404) theme={null}
  {
    "message": "Credit package not found"
  }
  ```
</ResponseExample>

***

## POST /credits/checkout/api

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

### 인증

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

```
Authorization: Bearer llmgen_your_api_key_here
```

### 요청 본문

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

### 응답

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

<RequestExample>
  ```bash cURL theme={null}
  curl -X POST https://api.llmgenerator.com/api/v1/credits/checkout/api \
    -H "Authorization: Bearer llmgen_your_api_key_here" \
    -H "Content-Type: application/json" \
    -d '{
          "packageId": "pkg_pro",
          "successUrl": "https://yourapp.com/success?session_id={CHECKOUT_SESSION_ID}",
          "cancelUrl": "https://yourapp.com/cancel"
        }'
  ```

  ```javascript Node.js theme={null}
  const response = await fetch('https://api.llmgenerator.com/api/v1/credits/checkout/api', {
    method: 'POST',
    headers: {
      'Authorization': 'Bearer llmgen_your_api_key_here',
      'Content-Type': 'application/json'
    },
    body: JSON.stringify({
      packageId: 'pkg_pro',
      successUrl: 'https://yourapp.com/success?session_id={CHECKOUT_SESSION_ID}',
      cancelUrl: 'https://yourapp.com/cancel'
    })
  });

  const data = await response.json();
  // Redirect user to data.url in your app
  ```

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

  response = requests.post(
      'https://api.llmgenerator.com/api/v1/credits/checkout/api',
      headers={
          'Authorization': 'Bearer llmgen_your_api_key_here',
          'Content-Type': 'application/json'
      },
      json={
          'packageId': 'pkg_pro',
          'successUrl': 'https://yourapp.com/success',
          'cancelUrl': 'https://yourapp.com/cancel'
      }
  )

  data = response.json()
  ```
</RequestExample>
