# Create Stripe Checkout session to add a payment method

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

`POST /billing/checkout-setup-session`

Resource: **Billing**

**Returns a Stripe Checkout URL in `setup` mode** to save a card for automatic payment of future invoices. Redirect the browser to `url`; on completion Stripe returns to `success_url` and Truto marks the card as the customer's default payment method.

## Request body

- **`team_id`** _(string)_
- **`success_url`** _(string)_
  Must be on the app origin. Defaults to the Billing settings page.
- **`cancel_url`** _(string)_
  Must be on the app origin. Defaults to the Billing settings page.

## Response body

- **`url`** _(string)_
- **`session_id`** _(string)_

## Errors

| Status | Description |
| :----- | :---------- |
| `400` | A redirect URL is not on the app origin |
| `403` | Forbidden if the caller is not an admin of the team |
| `404` | The team has no Stripe customer yet |
| `503` | Billing is not configured on this deployment (`STRIPE_SECRET_KEY` unset) |

## Code examples

### curl

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

### JavaScript

```javascript
const body = {
  "team_id": "your_team_id",
  "success_url": "your_success_url",
  "cancel_url": "your_cancel_url"
};

const response = await fetch('https://api.truto.one/billing/checkout-setup-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-setup-session"
headers = {
    "Authorization": "Bearer <your_api_token>",
    "Content-Type": "application/json",
}
params = {
}
payload = {
    "team_id": "your_team_id",
    "success_url": "your_success_url",
    "cancel_url": "your_cancel_url"
}

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