> ## 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.

# 결제 세션 검증

> 완료된 Checkout 세션을 검증하고 크레딧이 반영되었는지 확인합니다.

## 개요

결제가 끝난 뒤 이 엔드포인트로 결제 처리 여부와 계정 크레딧 반영을 확인합니다. 웹훅이 처리되지 않은 경우 등의 대안으로 유용합니다.

<Note>
  크레딧은 일반적으로 Stripe 웹훅으로 자동 반영됩니다. 이 엔드포인트는 예외적인 경우나 클라이언트 측 확인을 위한 수동 검증 옵션입니다.
</Note>

<Note>
  **서드파티 연동:** API 키 인증을 사용할 때는 대신 `GET /credits/verify-session/{sessionId}/api`를 사용하세요.
</Note>

## 인증

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

## 경로 매개변수

<ParamField path="sessionId" type="string" required>
  `/credits/checkout`에서 반환된 Stripe Checkout 세션 ID입니다.
</ParamField>

<RequestExample>
  ```bash cURL theme={null}
  curl -X GET https://api.llmgenerator.com/api/v1/credits/verify-session/cs_test_a1b2c3d4e5f6 \
    -H "Authorization: Bearer YOUR_ACCESS_TOKEN"
  ```

  ```javascript JavaScript theme={null}
  const sessionId = 'cs_test_a1b2c3d4e5f6';
  const response = await fetch(
    `https://api.llmgenerator.com/api/v1/credits/verify-session/${sessionId}`,
    {
      headers: {
        'Authorization': 'Bearer YOUR_ACCESS_TOKEN'
      }
    }
  );

  const data = await response.json();
  if (data.success) {
    console.log(`Added ${data.credits} credits`);
  }
  ```

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

  session_id = 'cs_test_a1b2c3d4e5f6'
  response = requests.get(
      f'https://api.llmgenerator.com/api/v1/credits/verify-session/{session_id}',
      headers={'Authorization': 'Bearer YOUR_ACCESS_TOKEN'}
  )
  data = response.json()
  print(f"Verified: {data['credits']} credits")
  ```
</RequestExample>

<ResponseExample>
  ```json Success theme={null}
  {
    "success": true,
    "credits": 500,
    "sessionId": "cs_test_a1b2c3d4e5f6"
  }
  ```

  ```json Payment Not Completed theme={null}
  {
    "success": false,
    "message": "Payment not completed"
  }
  ```
</ResponseExample>

## 응답 필드

<ResponseField name="success" type="boolean">
  세션 검증 성공 여부입니다.
</ResponseField>

<ResponseField name="credits" type="integer">
  구매에서 얻은 크레딧 수입니다.
</ResponseField>

<ResponseField name="sessionId" type="string">
  검증한 세션 ID입니다.
</ResponseField>

## 오류 응답

<ResponseField name="400">
  잘못된 요청 — 결제가 완료되지 않았거나 세션 메타데이터가 잘못되었습니다.
</ResponseField>

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

<ResponseField name="403">
  접근 거부 — 세션이 현재 인증된 사용자에게 속하지 않습니다.
</ResponseField>

## 멱등성

이 엔드포인트는 멱등합니다. 크레딧이 이미(웹훅 등으로) 반영된 경우 추가로 두 번 더하지 않고, 성공과 크레딧 금액을 반환합니다.

## 일반적인 흐름

1. 사용자가 Stripe에서 결제를 마칩니다
2. Stripe가 `successUrl`로 리디렉션합니다
3. 이 엔드포인트를 호출해 크레딧 반영을 검증합니다
4. 사용자에게 확인 화면을 보여 줍니다
5. UI에서 크레딧 잔액을 새로고칩니다

<Tip>
  이 엔드포인트를 사용할 수 있지만, 권장 흐름은 Stripe 웹훅을 수신하고 UI는 `/credits/balance`로 갱신하는 것입니다.
</Tip>

***

## GET /credits/verify-session/{sessionId}/api

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

### 인증

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

```
Authorization: Bearer llmgen_your_api_key_here
```

### 경로 매개변수

위와 동일합니다.

### 응답

위와 동일합니다.

<RequestExample>
  ```bash cURL theme={null}
  curl -X GET https://api.llmgenerator.com/api/v1/credits/verify-session/cs_test_a1b2c3d4e5f6/api \
    -H "Authorization: Bearer llmgen_your_api_key_here"
  ```

  ```javascript JavaScript theme={null}
  const sessionId = 'cs_test_a1b2c3d4e5f6';
  const response = await fetch(
    `https://api.llmgenerator.com/api/v1/credits/verify-session/${sessionId}/api`,
    {
      headers: {
        'Authorization': 'Bearer llmgen_your_api_key_here'
      }
    }
  );

  const data = await response.json();
  if (data.success) {
    console.log(`Added ${data.credits} credits`);
  }
  ```

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

  session_id = 'cs_test_a1b2c3d4e5f6'
  response = requests.get(
      f'https://api.llmgenerator.com/api/v1/credits/verify-session/{session_id}/api',
      headers={'Authorization': 'Bearer llmgen_your_api_key_here'}
  )
  data = response.json()
  print(f"Verified: {data['credits']} credits")
  ```
</RequestExample>
