# Billing

Cards, yearly prices, the monthly sending allowance, overage and the hard stop.

Calls go to https://address.seleya.ai/api. Errors are `{"error": {"code", "message"}}` with the HTTP status: https://address.seleya.ai/docs/reference/errors.md

## Billing

`GET /v1/billing`, called with a key or a person signed in

The owner's payment status, plan and price, card, the month's sending allowance (with overage and the hard stop), and the next charge.

| Parameter | Type | | |
| --- | --- | --- | --- |
| `owner` | string, in query | optional | Who pays. Defaults to you. |

```bash
curl https://address.seleya.ai/api/v1/billing \
  -H "Authorization: Bearer $SELEYA_KEY"
```

```python
import os, requests

r = requests.get(
    "https://address.seleya.ai/api/v1/billing",
    headers={"Authorization": f"Bearer {os.environ['SELEYA_KEY']}"},
)
print(r.status_code, r.json())
```

```typescript
const r = await fetch("https://address.seleya.ai/api/v1/billing", {
  method: "GET",
  headers: { Authorization: `Bearer ${process.env.SELEYA_KEY}` },
});
console.log(r.status, await r.json());
```

Answers:

- 200: Done
- 401: No valid key, session or token
- 403: Not allowed for this caller
- 404: Not found, or not yours to see
- 503: Payments are not open here yet

| Field (200) | Type | | |
| --- | --- | --- | --- |
| `status` | string | required | none, checking, ready_to_pay, payment_required, active, past_due, cancelled, refused or review. First-payment failure never activates mail. |
| `reason` | string, or null | optional | Why the status is what it is, when it isn't active. |
| `plan` | string | optional | company or person. |
| `price` | object | optional | What this owner pays. |
| `allowance` | object, or null | optional | This month's sending: 1,000 sends for each paid-for address, pooled. |
| `next` | object, or null | optional | The next charge, when a subscription runs. |
| `card` | object | optional | The card that pays: brand, last four digits, funding, country and the 3-D Secure result. |
| `receive_only` | boolean | optional | A prepaid card pays, so the addresses receive but don't send. |
| `billable` | integer | optional | The addresses paid for: the owner's active ones. |
| `customer` | object | optional | The Stripe customer id. |
| `owner` | object | optional | Whose billing this is: id, name and kind. |
| `capabilities` | Capabilities | optional |  |
| `card_state` | string, or null | optional |  |
| `card_pending` | boolean | optional |  |
| `purchase` | object, or null | optional |  |
| `payment` | object, or null | optional |  |
| `invoices` | array of objects | optional |  |

```json
{
  "allowance": {
    "hard_stop": false,
    "included": 1000,
    "included_used": 0,
    "overage": 0
  },
  "billable": 1,
  "card": null,
  "customer": "cus_VU7sXsMd8VZkDA",
  "next": null,
  "owner": {
    "id": "7f3c9a2e-0000-4000-8000-000000000020",
    "kind": "company",
    "name": "Pay Co 10220001"
  },
  "plan": "company",
  "price": {
    "cents_per_address_year": 1800,
    "overage_cents_per_1000_sends": 100
  },
  "reason": null,
  "receive_only": false,
  "status": "none"
}
```

## Save a card

`POST /v1/billing/checkout`, called with a key or a person signed in

Saves a card and requests 3-D Secure. Eligibility checks run before payment. Saving a card does not create a subscription; a person reviews the price and confirms purchase separately.

| Field | Type | | |
| --- | --- | --- | --- |
| `owner` | string | optional | Who pays: a company's owner id or your own. Defaults to yours. |

```bash
curl -X POST https://address.seleya.ai/api/v1/billing/checkout \
  -H "Authorization: Bearer $SELEYA_KEY" \
  -H "Content-Type: application/json" \
  -d '{}'
```

```python
import os, requests

r = requests.post(
    "https://address.seleya.ai/api/v1/billing/checkout",
    headers={"Authorization": f"Bearer {os.environ['SELEYA_KEY']}"},
    json={},
)
print(r.status_code, r.json())
```

```typescript
const r = await fetch("https://address.seleya.ai/api/v1/billing/checkout", {
  method: "POST",
  headers: { Authorization: `Bearer ${process.env.SELEYA_KEY}`, "Content-Type": "application/json" },
  body: JSON.stringify({}),
});
console.log(r.status, await r.json());
```

Answers:

- 201: Made
- 401: No valid key, session or token
- 403: Not allowed for this caller
- 409: Conflicts with the current state
- 503: Payments are not open here yet

| Field (201) | Type | | |
| --- | --- | --- | --- |
| `url` | string | required |  |

```json
{
  "customer": "cus_VU7sXsMd8VZkDA",
  "session": "cs_test_…",
  "url": "https://checkout.stripe.com/c/pay/cs_…"
}
```

## Invoices and card

`POST /v1/billing/portal`, called with a person signed in

A person opens the Address-specific cancellation portal. Card verification, payment retries and invoice PDFs are at address.seleya.ai.

Called by the console's own page, signed in; not for agents.

| Field | Type | | |
| --- | --- | --- | --- |
| `owner` | string | optional | Who pays. Defaults to yours. |

Answers:

- 201: Made
- 401: No valid key, session or token
- 403: Not allowed for this caller
- 409: Conflicts with the current state
- 503: Payments are not open here yet

| Field (201) | Type | | |
| --- | --- | --- | --- |
| `url` | string | required |  |

## Set the hard stop

`POST /v1/billing/hard-stop`, called with a key or a person signed in

Switches the hard stop at the month's sending allowance on or off. With it on, sending stops once the month's included sends are used; with it off, sends beyond them cost $1 per 1,000, added to the next charge. Anyone who can see the owner's billing may switch it on. Switching it off lets sends cost money, so for a key or an app it becomes an ask: the call answers 202 and the owner's admins get a link to approve it.

| Field | Type | | |
| --- | --- | --- | --- |
| `owner` | string | optional | Whose billing. Defaults to yours. |
| `on` | boolean | required | true to stop at the allowance; false to let sends beyond it go on as overage. |

```bash
curl -X POST https://address.seleya.ai/api/v1/billing/hard-stop \
  -H "Authorization: Bearer $SELEYA_KEY" \
  -H "Content-Type: application/json" \
  -d '{
  "on": true
}'
```

```python
import os, requests

r = requests.post(
    "https://address.seleya.ai/api/v1/billing/hard-stop",
    headers={"Authorization": f"Bearer {os.environ['SELEYA_KEY']}"},
    json={
      "on": True
    },
)
print(r.status_code, r.json())
```

```typescript
const r = await fetch("https://address.seleya.ai/api/v1/billing/hard-stop", {
  method: "POST",
  headers: { Authorization: `Bearer ${process.env.SELEYA_KEY}`, "Content-Type": "application/json" },
  body: JSON.stringify({
    "on": true
  }),
});
console.log(r.status, await r.json());
```

Answers:

- 200: Done
- 202: Waiting for a person to approve switching it off
- 401: No valid key, session or token
- 403: Not allowed for this caller
- 404: No such owner for this caller
- 409: This owner has no billing yet
- 422: A value is refused; the message says which
- 503: Payments are not open here yet

| Field (200) | Type | | |
| --- | --- | --- | --- |
| `hard_stop` | boolean | required | Whether the hard stop is now on. |

```json
{
  "hard_stop": true
}
```

## Your own address

`POST /v1/me/address`, called with a key or a person signed in

A person (or their app) makes their own address on the people's domain, seleya.me. It works once they pay.

| Field | Type | | |
| --- | --- | --- | --- |
| `name` | string | required | Your full name, as on your card. It is screened against sanctions lists. |
| `country` | string | required | Where you live, as a two-letter code such as ZA. |
| `local` | string | required | The name before @seleya.me: 1 to 64 of a-z, 0-9, dot, dash and underscore. |
| `display_name` | string | optional | The name people see. It must say it is an agent. Defaults to "<your name>'s agent". |

```bash
curl -X POST https://address.seleya.ai/api/v1/me/address \
  -H "Authorization: Bearer $SELEYA_KEY" \
  -H "Content-Type: application/json" \
  -d '{
  "name": "Ada Lovelace",
  "country": "GB",
  "local": "ada"
}'
```

```python
import os, requests

r = requests.post(
    "https://address.seleya.ai/api/v1/me/address",
    headers={"Authorization": f"Bearer {os.environ['SELEYA_KEY']}"},
    json={
      "name": "Ada Lovelace",
      "country": "GB",
      "local": "ada"
    },
)
print(r.status_code, r.json())
```

```typescript
const r = await fetch("https://address.seleya.ai/api/v1/me/address", {
  method: "POST",
  headers: { Authorization: `Bearer ${process.env.SELEYA_KEY}`, "Content-Type": "application/json" },
  body: JSON.stringify({
    "name": "Ada Lovelace",
    "country": "GB",
    "local": "ada"
  }),
});
console.log(r.status, await r.json());
```

Answers:

- 201: Made
- 401: No valid key, session or token
- 403: Not allowed for this caller
- 409: Conflicts with the current state
- 422: A value is refused; the message says which

| Field (201) | Type | | |
| --- | --- | --- | --- |
| `id` | string | required |  |
| `address` | string | required |  |
| `owner_id` | string | required |  |
| `display_name` | string | required |  |
| `status` | active \| retired | required |  |
| `holder_emails` | array of strings | optional |  |
| `holder_person_id` | string, or null | optional |  |
| `screening` | map of string | optional |  |
| `capabilities` | Capabilities | optional |  |
| `approvals` | off \| unknown_recipients \| everything | optional |  |

```json
{
  "address": "own@seleya.me",
  "display_name": "Test's agent",
  "holder_emails": [
    "own@acme.com"
  ],
  "holder_person_id": "7f3c9a2e-0000-4000-8000-00000000002d",
  "id": "7f3c9a2e-0000-4000-8000-00000000002e",
  "owner": {
    "id": "7f3c9a2e-0000-4000-8000-00000000002f",
    "status": "authorised_unpaid"
  },
  "owner_id": "7f3c9a2e-0000-4000-8000-00000000002f",
  "screening": {},
  "status": "active"
}
```

## Stripe's events

`POST /v1/webhooks/stripe`, called with 

For Stripe only, signed with the endpoint's secret.

Answers:

- 200: Done
- 400: The request is malformed
- 401: No valid key, session or token

## Review an annual price and optional discount after card verification

`POST /v1/billing/review`, called with a person signed in



Called by the console's own page, signed in; not for agents.

| Field | Type | | |
| --- | --- | --- | --- |
| `owner` | string | optional | An owner the signed-in person administers. |
| `code` | string | optional |  |

Answers:

- 200: Done
- 403: The error explains how to continue.
- 409: The error explains how to continue.
- 422: The error explains how to continue.

| Field (200) | Type | | |
| --- | --- | --- | --- |
| `purchase` | string | required |  |
| `quantity` | integer | required |  |
| `total_cents` | integer | required |  |
| `currency` | string | required |  |
| `subtotal_cents` | integer | optional |  |
| `annual_cents_before_discount` | integer | optional |  |
| `discount` | object, or null | optional |  |
| `card` | object | optional |  |
| `terms_version` | string | required |  |

## Confirm a reviewed purchase using only its verified card

`POST /v1/billing/purchase`, called with a person signed in



Called by the console's own page, signed in; not for agents.

| Field | Type | | |
| --- | --- | --- | --- |
| `owner` | string | optional | An owner the signed-in person administers. |
| `purchase` | string | required |  |
| `accept_terms` | true | required |  |

Answers:

- 200: Done
- 403: The error explains how to continue.
- 409: The error explains how to continue.
- 422: The error explains how to continue.

| Field (200) | Type | | |
| --- | --- | --- | --- |
| `status` | string | required | none, checking, ready_to_pay, payment_required, active, past_due, cancelled, refused or review. First-payment failure never activates mail. |
| `reason` | string, or null | optional | Why the status is what it is, when it isn't active. |
| `plan` | string | optional | company or person. |
| `price` | object | optional | What this owner pays. |
| `allowance` | object, or null | optional | This month's sending: 1,000 sends for each paid-for address, pooled. |
| `next` | object, or null | optional | The next charge, when a subscription runs. |
| `card` | object | optional | The card that pays: brand, last four digits, funding, country and the 3-D Secure result. |
| `receive_only` | boolean | optional | A prepaid card pays, so the addresses receive but don't send. |
| `billable` | integer | optional | The addresses paid for: the owner's active ones. |
| `customer` | object | optional | The Stripe customer id. |
| `owner` | object | optional | Whose billing this is: id, name and kind. |
| `capabilities` | Capabilities | optional |  |
| `card_state` | string, or null | optional |  |
| `card_pending` | boolean | optional |  |
| `purchase` | object, or null | optional |  |
| `payment` | object, or null | optional |  |
| `invoices` | array of objects | optional |  |

## Pay an existing invoice using the verified card; may return a bank confirmation URL

`POST /v1/billing/payment`, called with a person signed in



Called by the console's own page, signed in; not for agents.

| Field | Type | | |
| --- | --- | --- | --- |
| `owner` | string | optional | An owner the signed-in person administers. |
| `invoice` | string | required |  |
| `total_cents` | integer | required |  |

Answers:

- 200: Done
- 403: The error explains how to continue.
- 409: The error explains how to continue.
- 422: The error explains how to continue.

| Field (200) | Type | | |
| --- | --- | --- | --- |
| `paid` | boolean | optional |  |
| `processing` | boolean | optional |  |
| `url` | string | optional |  |

