feat: confirm an agency plan switch only from the price and billing period its preview was made for, let a switch Stripe already holds be previewed and completed, hold keyed requests on agency routes to the agency's staff before any answer is recorded or replayed, and bound the switch locks

This commit is contained in:
Matthew Meszaros
2026-11-11 09:18:27 +01:00
parent a170997c17
commit 72c0777c33
14 changed files with 148 additions and 26 deletions
+2 -2
View File
@@ -929,8 +929,8 @@ A key passes the recent-confirmation check the session routes ask for, since it
| GET | `/agency/:agencyId/inbox/thread` | Staff with inbox access in that client: `organization_id` and `thread_id`, the conversation's messages as `GET /unibox/thread` returns them, read-only |
| GET | `/agency/:agencyId/inbox/messages/:messageId` | Staff with inbox access in that client: `organization_id`, one message with its body as `GET /unibox/:id` returns it, left unread |
| POST | `/agency/:agencyId/billing/checkout` | Owner, admin: `plan_id` and `interval` (`month` or `year`) |
| GET | `/agency/:agencyId/billing/change/preview` | Owner, admin: `plan_id` and `interval` (`month` or `year`) in the query. What switching the agency's subscription to that plan and period would bill: `proration_cents` (negative is a credit), `amount_due_cents` on the next invoice, `currency`, and the `proration_date` the amounts were calculated at. Changes nothing |
| POST | `/agency/:agencyId/billing/change` | Owner, admin: `plan_id` and `interval`, and optionally the preview's `proration_date` so the switch bills exactly what the preview showed (valid for 30 minutes). Moves the agency's subscription to another agency plan or billing period, prorated; every client workspace has the new plan at once. Answers the agency. A switch Stripe already holds but the agency does not yet show is completed, not refused |
| GET | `/agency/:agencyId/billing/change/preview` | Owner, admin: `plan_id` and `interval` (`month` or `year`) in the query. What switching the agency's subscription to that plan and period would bill: `proration_cents` (negative is a credit), `amount_due_cents` on the next invoice, `currency`, the `proration_date` the amounts were calculated at and the `from_price_id` the subscription was on. Changes nothing |
| POST | `/agency/:agencyId/billing/change` | Owner, admin: `plan_id` and `interval`, and optionally the preview's `proration_date` and `from_price_id` so the switch bills exactly what the preview showed (valid for 30 minutes, within the same billing period and from the same price). Moves the agency's subscription to another agency plan or billing period, prorated; every client workspace has the new plan at once. Answers the agency. A switch Stripe already holds but the agency does not yet show is completed, not refused |
| POST | `/agency/:agencyId/billing/topup` | Owner, admin: one 50,000-send pack |
| POST | `/agency/:agencyId/billing/ai-topup` | Owner, admin: `amount_usd` ($5 to $5,000) added to the agency's AI balance through checkout. Answers `checkout_url` |
| POST | `/agency/:agencyId/billing/portal` | Owner, admin |
+1 -1
View File
@@ -713,7 +713,7 @@ The [agency](/guides/agencies/) routes answer these codes.
| `agency_client_has_subscription` | 409 | The workspace pays for its own plan. Cancel it in the workspace's billing first |
| `agency_already_subscribed` | 409 | The agency already has a plan; switch it with `POST /agency/:agencyId/billing/change` |
| `agency_plan_unchanged` | 409 | A plan switch to the plan and billing period the agency is already on |
| `agency_plan_preview_expired` | 409 | `proration_date` on a plan switch is more than 30 minutes old or in the future. Preview the switch again |
| `agency_plan_preview_expired` | 409 | The preview a plan switch was confirmed from no longer holds: `proration_date` is more than 30 minutes old, in the future or before the current billing period, or the subscription is no longer on `from_price_id`. Preview the switch again |
| `agency_pool_exceeds_plan` | 409 | A switch to a plan whose send pool, with this period's top-ups, is smaller than what the period has already used. Switch after the period renews |
| `agency_billed` | 409 | `POST /subscription/checkout` on a client workspace, whose plan comes from its agency |
| `agency_leave_agency_owner` | 409 | `POST /organization/agency/leave` on a workspace whose owner also owns the agency. Detach it with `DELETE /agency/:agencyId/clients/:orgId` instead |