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

# Session de paiement (checkout)

> Ce point de terminaison crée une session Stripe Checkout pour acheter des crédits.

## POST /credits/checkout

Crée une session Stripe Checkout afin d'acheter un pack de crédits. Nécessite une authentification par session (jeton d'accès JWT issu de la connexion).

<Note>
  **Pour les intégrations tierces :** utilisez `POST /credits/checkout/api` avec authentification par clé d'API.
</Note>

### Corps de la requête

<ParamField body="packageId" type="string" required>
  Identifiant du pack à acheter. Liste disponible via `/credits/packages`.
</ParamField>

<ParamField body="successUrl" type="string">
  URL de redirection après paiement réussi. Par défaut : tableau de bord avec indicateur de succès.
</ParamField>

<ParamField body="cancelUrl" type="string">
  URL de redirection en cas d'annulation. Par défaut : tableau de bord avec indicateur d'annulation.
</ParamField>

### Réponse

<ResponseField name="sessionId" type="string">
  Identifiant de la session Stripe Checkout.
</ResponseField>

<ResponseField name="url" type="string">
  URL de la page Stripe Checkout. Redirigez l'utilisateur ici pour finaliser l'achat.
</ResponseField>

<ResponseField name="package" type="object">
  Détails du pack sélectionné.

  <Expandable title="Propriétés du pack">
    <ResponseField name="id" type="string">
      Identifiant du pack.
    </ResponseField>

    <ResponseField name="name" type="string">
      Nom du pack.
    </ResponseField>

    <ResponseField name="credits" type="number">
      Nombre de crédits dans le pack.
    </ResponseField>

    <ResponseField name="priceCents" type="number">
      Prix en centimes.
    </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

Crée une session Stripe Checkout avec authentification par clé d'API. Adapté aux intégrations tierces et aux applications externes.

### Authentification

Authentification par clé d'API obligatoire. Indiquez votre clé dans l'en-tête `Authorization` :

```
Authorization: Bearer llmgen_your_api_key_here
```

### Corps de la requête

Identique à `/credits/checkout` ci-dessus.

### Réponse

Identique à `/credits/checkout` ci-dessus.

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