---
agent:
  instructions: "Use this search API to find relevant content across this site with keywords or natural-language queries, instead of crawling individual pages. Results are returned in Markdown."
  endpoint: "https://truto.one/.well-known/search?q={query}"
  method: "GET"
  documentation: "https://developers.cloudflare.com/ai-search/how-to/search-for-agents/"
---

# Create Stripe Checkout session to turn an add-on on

> Source: https://truto.one/docs/api-reference/admin/billing/create-checkout-add-on-session/

`POST /billing/checkout-add-on-session`

Resource: **Billing**

**Turns an add-on on for a team with no card, in one payment.** The Checkout takes the same amount `POST /billing/add-on` charges a saved card (the rest of the month, by days) and saves the payment method for the add-on's renewals; it becomes the customer's default. The add-on turns on when Stripe's webhook says the payment succeeded, not when the browser returns. The charge is claimed first, so a double click or a second tab pays one Checkout, and a card charge for the same add-on closes it first.

- Already on, or this month already paid (turned off after paying): `checkout` is `null` and nothing is charged; the add-on is on.
- A charge already sent to Stripe that waits on the card (authentication): `402` with `hosted_invoice_url`, as `POST /billing/add-on`.

## Request body

- **`team_id`** _(string)_
- **`add_on`** _(string)_
  `pro`, `partner` or `unified:<unified API name>`.
- **`ui_mode`** _(string)_
  `hosted` returns `url`, Stripe's own page. `elements` returns `client_secret`, `publishable_key` and `consent_text`, for the app to show Stripe's Payment and Express Checkout Elements itself (Stripe.js `initCheckoutElementsSdk`) and confirm in place; it leaves the app only for a payment method that must redirect, to `return_url`.
  Allowed: `hosted`, `elements`
- **`success_url`** _(string)_
  `hosted` only. Must be on the app origin. Defaults to the Billing settings page.
- **`cancel_url`** _(string)_
  `hosted` only. Must be on the app origin. Defaults to the Billing settings page.
- **`return_url`** _(string)_
  `elements` only. Must be on the app origin. Defaults to the Billing settings page.

## Response body

- **`add_on`** _(object)_
  The add-on as `GET /billing/add-on` lists it.
- **`checkout`** _(object)_
  The Checkout to pay; `null` when the add-on is on already.
  - **`url`** _(string)_
    Stripe's hosted page (`ui_mode` `hosted`); `null` for `elements`.
  - **`client_secret`** _(string)_
    Starts Stripe's Elements (`ui_mode` `elements`, Stripe.js `initCheckoutElementsSdk`); `null` when hosted.
  - **`publishable_key`** _(string)_
    The Stripe publishable key to start Stripe.js with; `null` when hosted.
  - **`consent_text`** _(string)_
    What the payer agrees to. Stripe shows it on its hosted page; with `elements` the app must show it by its Pay button.
  - **`session_id`** _(string)_
  - **`amount_cents`** _(integer)_
    What the Checkout charges, in cents.

## Errors

| Status | Description |
| :----- | :---------- |
| `400` | Unknown add-on, one the plan does not offer, a team that cannot be billed for add-ons, or a redirect URL not on the app origin or for the other `ui_mode` |
| `402` | A charge for this add-on is waiting on the card; pay at `hosted_invoice_url` |
| `403` | Forbidden if the caller is not an admin of the team |
| `409` | The add-on is being charged right now, or a payment for it is still being confirmed; try again later |
| `503` | Billing is not configured on this deployment (`STRIPE_SECRET_KEY` unset), or `ui_mode` `elements` was asked for and `STRIPE_PUBLISHABLE_KEY` is unset |

## Code examples

### curl

```bash
curl -X POST 'https://api.truto.one/billing/checkout-add-on-session' \
  -H 'Authorization: Bearer <your_api_token>' \
  -H 'Content-Type: application/json' \
  -d '{
  "team_id": "your_team_id",
  "add_on": "pro",
  "ui_mode": "hosted",
  "success_url": "your_success_url",
  "cancel_url": "your_cancel_url",
  "return_url": "your_return_url"
}'
```

### JavaScript

```javascript
const body = {
  "team_id": "your_team_id",
  "add_on": "pro",
  "ui_mode": "hosted",
  "success_url": "your_success_url",
  "cancel_url": "your_cancel_url",
  "return_url": "your_return_url"
};

const response = await fetch('https://api.truto.one/billing/checkout-add-on-session', {
  method: 'POST',
  headers: {
    'Authorization': 'Bearer <your_api_token>',
    'Content-Type': 'application/json',
  },
  body: JSON.stringify(body),
});

const data = await response.json();
console.log(data);
```

### Python

```python
import requests

url = "https://api.truto.one/billing/checkout-add-on-session"
headers = {
    "Authorization": "Bearer <your_api_token>",
    "Content-Type": "application/json",
}
params = {
}
payload = {
    "team_id": "your_team_id",
    "add_on": "pro",
    "ui_mode": "hosted",
    "success_url": "your_success_url",
    "cancel_url": "your_cancel_url",
    "return_url": "your_return_url"
}

response = requests.post(url, headers=headers, params=params, json=payload)
print(response.json())
```
