# Billing and donations

> Start a plan or capacity pack checkout, the in-app purchase sync and eligibility routes, and the donation checkout and support figures.

API reference · Reference · https://wxalerts.org/docs/api/billing/

Base URL: `https://api.wxalerts.org`

How a plan is bought, how the apps check and refresh their purchases, and how a
donation starts. Plan prices and what each plan includes are on the
[pricing page](/pricing/) and, per account, in
[`GET /auth/entitlements`](/docs/api/sign-in/#get-authentitlements). Payments are taken by
Stripe on a Stripe page: no card number ever reaches this API.

Account routes (checkout, sync, eligibility) take a signed-in session or a
Bearer token and need the CSRF header for a cookie request that changes something.
See [Sessions, Bearer and CSRF](/docs/api/sign-in/#sessions-bearer-and-csrf).

Money amounts are integers in US cents. Stripe and RevenueCat each send events to
WxAlerts to say a payment or a store purchase happened; those endpoints are
internal and are not part of the public API.

## `POST /billing/checkout`

Starts checkout for the plan or for capacity packs. Session or Bearer. `Cache-Control: no-store`.
It never charges anything itself: it returns a Stripe Checkout URL to send the browser to.

Body (JSON):

| Field | Type | Required | Default | Bounds |
| --- | --- | --- | --- | --- |
| `plan` | string | yes | | `pro` (the Supporter plan) or `capacity_pack`. The business plans are retired and no longer sold |
| `interval` | string | no | `month` | `month` or `year`. Ignored for packs, which are monthly |
| `quantity` | integer | no | 1 | 1 to 100. Packs only; ignored for the plan |
| `resume` | string or null | no | `null` | at most 200 characters. A path on wxalerts.org to land on after Stripe. It must start with a single `/` and contain no backslash or line break, or it is dropped |

Response `200`:

| Field | Type | Description |
| --- | --- | --- |
| `checkout_url` | string or null | the Stripe page to redirect to. `null` means there is nothing to buy |
| `plan` | string | echoes the request |
| `interval` | string | echoes the request (`month` for packs) |
| `already_held` | boolean | `true` when the account already has the plan, from Stripe, a store, a complimentary grant or a better grandfathered tier. This is a success: send the person to the account page, not to a second charge |
| `reason` | string or null | why `checkout_url` is `null`, ready to show |

```json
{ "checkout_url": "https://checkout.stripe.com/c/pay/cs_live_...", "plan": "pro", "interval": "year", "already_held": false, "reason": null }
```

```json
{ "checkout_url": null, "plan": "pro", "interval": "month", "already_held": true, "reason": "You already have the plan through the App Store. Manage it there." }
```

A pack with no plan answers `200` with `checkout_url: null`, `already_held: false`
and the reason `A capacity pack adds to the plan. Start the plan first.`

| Status | Body | When |
| --- | --- | --- |
| `400` | `{"detail": "<plan> is not a plan that can be bought here."}` | an unknown or no longer sold `plan` |
| `403` | `{"detail": "Missing X-Requested-With header."}` | cookie request without the CSRF header |
| `422` | default list | `interval` not `month` or `year`, `quantity` out of range, `resume` too long |
| `503` | `{"detail": "Subscriptions are not available right now. Nothing has been charged. Please try again shortly."}` | billing is not available. Nothing is created and nobody is charged |
| `503` | `{"detail": "That plan cannot be bought right now. Nothing has been charged."}` | the plan has no product configured. For packs: `Capacity packs cannot be bought right now. Nothing has been charged.` |

## `POST /billing/store/sync`

Used by the apps right after a purchase or a restore: re-reads this account's App
Store and Google Play purchases from the purchase service now, so access is
immediate instead of waiting for the store notification. Session or Bearer. No body. Nothing the
app says about a purchase is trusted; the purchase service is asked.
`Cache-Control: no-store`.

Limit: 10 requests a minute per account (burst 5). Past that, `429` with
`Retry-After`.

| Field | Type | Description |
| --- | --- | --- |
| `app_user_id` | string | the account id as a string, which is what the app gave the purchase service |
| `plan` | object | `active` (boolean), and when active: `source` (`stripe`, `app_store`, `play_store` or `comp`), `status`, `product_id`, `expires_at`, `will_renew`, `in_trial` (boolean, `false` when not in a trial). Fields that do not apply are `null` |
| `capacity_packs` | integer | live packs from every source |
| `capacity_pack` | object | the pack offer: `eligible` (boolean), `reason`, `reason_code` (for example `needs_plan`), `held` (integer) and `held_product_ids` (array). The stores sell several pack products (`capacity_pack`, `capacity_pack_2`, and so on) because a store cannot sell one product twice at once; offer the first one not in `held_product_ids` |
| `subscriptions` | array | store purchases only: `entitlement` (`plan` or `capacity_pack`), `source`, `product_id`, `status`, `expires_at`, `will_renew`, `in_trial` |
| `limits` | object | `key`, `label`, `max_places`, `contacts_per_place`, `sms_per_month`, `voice_calls_per_month` |

```json
{
  "app_user_id": "12345",
  "plan": { "active": true, "source": "app_store", "status": "active", "product_id": "supporter_monthly", "expires_at": "2026-12-23T17:00:00Z", "will_renew": true, "in_trial": false },
  "capacity_packs": 0,
  "capacity_pack": { "eligible": true, "reason": null, "reason_code": null, "held": 0, "held_product_ids": [] },
  "subscriptions": [ { "entitlement": "plan", "source": "app_store", "product_id": "supporter_monthly", "status": "active", "expires_at": "2026-12-23T17:00:00Z", "will_renew": true, "in_trial": false } ],
  "limits": { "key": "pro", "label": "Supporter", "max_places": 5, "contacts_per_place": 5, "sms_per_month": 100, "voice_calls_per_month": 20 }
}
```

| Status | Body | When |
| --- | --- | --- |
| `429` | `{"detail": "Too many syncs. Try again in a minute."}` with `Retry-After` | over the limit |
| `502` | `{"detail": "Could not reach the purchase service. Your purchase is safe; try again."}` | the purchase service did not answer |
| `503` | `{"detail": "In-app purchases are not configured on this deployment."}` | not configured |

## `GET /billing/store/eligibility`

Asked by the app before it shows its paywall, as a guard against paying twice.
Session or Bearer. `Cache-Control: no-store`.

| Field | Type | Description |
| --- | --- | --- |
| `app_user_id` | string | the account id as a string |
| `eligible` | boolean | whether to offer the store plan. Same as `plan.eligible` |
| `reason`, `reason_code` | string or null | why not. Same as `plan` |
| `web_plan` | boolean | the account has the plan through wxalerts.org |
| `plan` | object | `eligible`, `reason`, `reason_code`. `reason_code` is `web_plan`, `store_plan`, `comp` (a complimentary grant) or `covered` (an existing tier already includes the plan) when not eligible |
| `capacity_pack` | object | as in sync. `reason_code` `needs_plan` when there is no plan to add to |
| `capacity_packs` | integer | packs held |
| `life_safety` | object | the locked alert set, as in [`GET /auth/entitlements`](/docs/api/sign-in/#get-authentitlements) |
| `life_safety_events` | array of string | the same set as NWS event names |

```json
{ "app_user_id": "12345", "eligible": false, "reason": "You already have the Supporter plan through wxalerts.org. Manage it in your account on the website.",
  "reason_code": "web_plan", "web_plan": true,
  "plan": { "eligible": false, "reason": "You already have the Supporter plan through wxalerts.org. Manage it in your account on the website.", "reason_code": "web_plan" },
  "capacity_pack": { "eligible": true, "reason": null, "reason_code": null, "held": 0, "held_product_ids": [] },
  "capacity_packs": 0, "life_safety": { "phenomena": ["TO", "SV", "FF"], "significance": "W", "emergencies": true, "events": ["Tornado Warning"], "reason": "Life-safety warnings are always on" },
  "life_safety_events": ["Tornado Warning"] }
```

A store purchase made anyway is honoured and the account simply holds two plans.

## `POST /donations/checkout`

Starts a donation. Anonymous: giving never requires an account. If the caller
happens to have a session cookie, the gift is tied to that account; an expired
or missing cookie just means it is not. There is no CSRF header requirement. No
route-specific rate limit. Returns a Stripe Checkout URL.

Body (JSON):

| Field | Type | Required | Default | Bounds |
| --- | --- | --- | --- | --- |
| `kind` | string | yes | | `once` or `monthly` |
| `amount_cents` | integer | yes | | whole cents. At least 100 ($1.00) and at most 1000000 ($10,000.00) |
| `cover_fee` | boolean | no | `false` | add Stripe's fee on top so the full gift arrives. Computed on the server; a total from the client is ignored |
| `email` | string or null | no | `null` | at most 320 characters. Prefills Checkout. It must contain an `@` that is not first or last; blank becomes `null` |

Response `200`:

| Field | Type | Description |
| --- | --- | --- |
| `checkout_url` | string | the Stripe page to redirect the donor to |
| `session_id` | string | the Stripe session id |
| `amount_cents` | integer | the gift |
| `fee_cents` | integer | fee cover added, 0 when `cover_fee` was false |
| `total_cents` | integer | what the card is charged |
| `tier` | string or null | the legacy donation tier name for that amount, or `null` |

```json
{ "checkout_url": "https://checkout.stripe.com/c/pay/cs_live_...", "session_id": "cs_live_a1b2", "amount_cents": 800, "fee_cents": 53, "total_cents": 853, "tier": null }
```

| Status | Body | When |
| --- | --- | --- |
| `422` | `{"detail": "Minimum donation is $1.00. Stripe rejects smaller charges."}` | below the minimum. Plain string |
| `422` | `{"detail": "Maximum donation through this form is $10,000.00. Get in touch for anything larger."}` | above the maximum |
| `422` | default list | wrong type, unknown `kind`, a bad `email` or `amount_cents` missing |
| `502` | `{"detail": "<Stripe's message>"}` | Stripe refused or could not be reached |
| `503` | `{"detail": "Donations are not configured on this deployment."}` | donations are off |

## `GET /donations/stats`

The figures behind the support page's progress bar. Anonymous.
`Cache-Control: public, max-age=300`. No parameters.

| Field | Type | Description |
| --- | --- | --- |
| `server_time` | string | database time of the answer |
| `active_supporters` | integer | recurring gifts in good standing |
| `goal_supporters` | integer | the supporter goal. 900 |
| `monthly_cents` | integer | recurring gifts per month, fee cover excluded |
| `monthly_cost_cents` | integer | what the infrastructure costs a month |
| `percent_covered` | number | `monthly_cents` as a percentage of `monthly_cost_cents`, to one decimal place, capped at 100 |
| `one_time_last_30d_cents` | integer | one-time gifts in the last 30 days, fee cover excluded. Reported apart because it is not recurring |

```json
{ "server_time": "2026-11-23T17:04:05Z", "active_supporters": 412, "goal_supporters": 900, "monthly_cents": 187400,
  "monthly_cost_cents": 202000, "percent_covered": 92.8, "one_time_last_30d_cents": 31500 }
```
