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

# Saldo & facturering

> Controleer je kredietsaldo en koop opwaarderingen programmatisch.

Gebruik de eindpunten voor gebruikersfacturering om het kredietsaldo van je team te bekijken en opwaarderingen te kopen met een opgeslagen betaalmethode. Beide eindpunten vereisen authenticatie met je [API-sleutel](/get-started/authentication). Ongeldige sleutels geven **402** terug.

## Controleer kredietsaldo

`GET /user/credits/info` geeft het kredietsaldo van het geauthenticeerde team terug, een uitsplitsing per partij, details van het actieve abonnement en of gebruik is toegestaan.

Gebruik dit eindpunt om factureringswidgets, gebruiksdashboards of pre-flight checks voor grote taken te ondersteunen.

Voor API-details zie [Krijg kredietinformatie](/api-reference/billing/credits-info).

<CodeGroup>
  ```python Python theme={null}
  import requests

  response = requests.get(
      "https://api.olostep.com/user/credits/info",
      headers={"Authorization": "Bearer <API-TOKEN>"},
  )
  print(response.json())
  ```

  ```js Node theme={null}
  const res = await fetch("https://api.olostep.com/user/credits/info", {
    headers: { Authorization: "Bearer <API-TOKEN>" },
  })
  console.log(await res.json())
  ```

  ```bash cURL theme={null}
  curl -s "https://api.olostep.com/user/credits/info" \
    -H "Authorization: Bearer <API-TOKEN>"
  ```
</CodeGroup>

### Antwoord

```json theme={null}
{
  "credits": 12500,
  "breakdown": [
    {
      "purchase_kind": "Subscription",
      "allocated_units": 10000,
      "remaining_units": 8500,
      "expiry_date": 1735689600
    },
    {
      "purchase_kind": "Top-up",
      "allocated_units": 5000,
      "remaining_units": 4000,
      "expiry_date": 1743465600
    }
  ],
  "active_subscription": {
    "id": "SUB_PRO",
    "display_name": "Pro",
    "credits": 10000,
    "created_at": 1704067200
  },
  "allow_usage": true
}
```

| Veld                  | Beschrijving                                                            |
| --------------------- | ----------------------------------------------------------------------- |
| `credits`             | Totaal resterende credits over alle niet-verlopen partijen              |
| `breakdown`           | Detail per partij: type, toegewezen en resterende eenheden, vervaldatum |
| `active_subscription` | Huidig plan (valt terug op `SUB_BASE` als er geen actief is)            |
| `allow_usage`         | Of het team nog credits kan gebruiken                                   |

Elke partij in `breakdown` heeft een `purchase_kind` van `Subscription`, `Top-up`, `Manual`, `Setup` of `Pending`.

## Koop een opwaardering

`POST /user/purchase-topup` belast een opgeslagen kaart op Stripe en koopt credits in één stap. Er is geen Checkout-omleiding of ingebedde betalings-UI.

Geef het kredietbedrag door in de request body:

```json theme={null}
{ "credits": 10000 }
```

| Veld      | Beschrijving            |
| --------- | ----------------------- |
| `credits` | Aantal te kopen credits |

Ondersteunde waarden: **10,000**, **20,000**, **80,000**, en **100,000**.

Voor API-details zie [Koop opwaardering](/api-reference/billing/purchase-topup).

<CodeGroup>
  ```python Python theme={null}
  import requests

  response = requests.post(
      "https://api.olostep.com/user/purchase-topup",
      headers={
          "Authorization": "Bearer <API-TOKEN>",
          "Content-Type": "application/json",
      },
      json={"credits": 10000},
  )
  print(response.status_code)
  print(response.json())
  ```

  ```js Node theme={null}
  const res = await fetch("https://api.olostep.com/user/purchase-topup", {
    method: "POST",
    headers: {
      Authorization: "Bearer <API-TOKEN>",
      "Content-Type": "application/json",
    },
    body: JSON.stringify({ credits: 10000 }),
  })
  console.log(res.status)
  console.log(await res.json())
  ```

  ```bash cURL theme={null}
  curl -s -X POST "https://api.olostep.com/user/purchase-topup" \
    -H "Authorization: Bearer <API-TOKEN>" \
    -H "Content-Type: application/json" \
    -d '{"credits": 10000}'
  ```
</CodeGroup>

### Vereisten

* Het team moet een Stripe-klant hebben met ten minste één opgeslagen kaart.
* Slechts één aankooppoging is toegestaan elke **60 seconden** per team. Als je de cooldown raakt, is het antwoord **429** met een `Retry-After` header.

### Antwoorden

**200** — betaling geslaagd:

```json theme={null}
{
  "success": true,
  "payment_intent_id": "pi_xxx",
  "credits": 10000
}
```

**202** — betaling is nog in verwerking. Credits worden toegevoegd zodra Stripe de betaling bevestigt:

```json theme={null}
{
  "success": true,
  "status": "processing",
  "payment_intent_id": "pi_xxx",
  "message": "Betaling wordt verwerkt. Credits worden toegevoegd zodra de betaling is bevestigd.",
  "credits": 10000
}
```

<Note>
  Credits worden uitgegeven door de Stripe-webhook na betalingsbevestiging, niet direct vanuit het HTTP-antwoord. Behandel **200** als betalingssucces; poll `GET /user/credits/info` als je het bijgewerkte saldo moet bevestigen.
</Note>

### Veelvoorkomende fouten

| Status | Fout                      | Wanneer                                                         |
| ------ | ------------------------- | --------------------------------------------------------------- |
| 400    | `missing_topup_selector`  | `credits` was niet verzonden                                    |
| 400    | `invalid_credits`         | Kredietbedrag staat niet op de toegestane lijst                 |
| 400    | `no_stripe_customer`      | Team heeft geen Stripe-klant                                    |
| 400    | `no_payment_method`       | Geen opgeslagen kaart in bestand                                |
| 402    | `payment_failed`          | Geen opgeslagen kaart voltooide de betaling                     |
| 429    | `purchase_topup_cooldown` | Er is binnen 60 seconden een andere aankoop geprobeerd          |
| 503    | `payment_status_unknown`  | Onduidelijke Stripe-fout; wacht voordat je het opnieuw probeert |
