POST /v1/teams/{teamId}/billing/subscription/upgrade
Upgrade/downgrade OU criação com trial anti-farming
- Access: Team admin
- Service:
https://api-billing.axuz.net
Accepted authentication
sessionCookie— Sessão plena Axuz (cookie de sessão da casa). Sessão restrita é 403 enrollment_required.bearerSession— JWT de acesso da sessão em `Authorization: Bearer`.
Responde POST /teams/{teamId}/billing/ subscription/upgrade.
AUTORIZAÇÃO (G-030): owner/admin do time. Apesar do nome, a rota é a troca de plano do lado do cliente nos DOIS sentidos — passa qualquer plano para ApplyProration, inclusive um mais barato —, então é ela que atende "upgrade/downgrade dentro do app sem sair pro gateway". Membro comum recebe 403.
Dois modos: (1) já existe subscription → change-plan com proração (ApplyProration); (2) primeira vez → INSERT nova subscription (trial se aplicável e nunca teve; senão active). Trial anti-farming: só concede se a equipe nunca teve subscription (EXISTS). Efeitos: leituras + UPDATE ou INSERT em subscriptions.
Parameters
| Name | In | Type | Required | Description |
|---|---|---|---|---|
teamId | path | string | yes |
Request body
application/json · Required
| Name | Type | Required | Description |
|---|---|---|---|
plan_id | string<uuid> | yes | |
billing_cycle | string | no | enum: |
{
"plan_id": "00000000-0000-0000-0000-000000000000",
"billing_cycle": "monthly"
}Responses
200
upgrade aplicado
| Name | Type | Required | Description |
|---|---|---|---|
ok | boolean | no | |
id | string<uuid> | no | |
mode | string | no | enum: |
proration | BillingProrationResult | no | |
proration.change_kind | string | no | enum: |
proration.credit_cents | integer | no | |
proration.charge_cents | integer | no | |
proration.net_cents | integer | no | |
proration.invoice_id | string<uuid> | null | no | |
proration.proration_item_id | string<uuid> | no |
201
nova subscription criada
| Name | Type | Required | Description |
|---|---|---|---|
ok | boolean | no | |
id | string<uuid> | no | |
mode | string | no | enum: |
400
input inválido
| Name | Type | Required | Description |
|---|---|---|---|
error | string | yes |
401
Sem credencial valida
| Name | Type | Required | Description |
|---|---|---|---|
error | string | yes |
403
Sem permissao (nao e owner/admin; token sem escopo; token de integracao em rota nao permitida)
| Name | Type | Required | Description |
|---|---|---|---|
error | string | yes |
429
Limite de requisições excedido.
| Name | Type | Required | Description |
|---|---|---|---|
error | string | yes |
500
erro interno
| Name | Type | Required | Description |
|---|---|---|---|
error | string | yes |
Examples
"Try it" is turned off in this reference. Use the examples with your test credential.
curl
curl -sS -X POST 'https://api-billing.axuz.net/v1/teams/TEAM_ID/billing/subscription/upgrade' \
-H "Authorization: Bearer $AXUZ_TOKEN" \
-H "Content-Type: application/json" \
-d '{"plan_id":"00000000-0000-0000-0000-000000000000","billing_cycle":"monthly"}'Node.js
const res = await fetch("https://api-billing.axuz.net/v1/teams/TEAM_ID/billing/subscription/upgrade", {
method: 'POST',
headers: {
Authorization: `Bearer ${process.env.AXUZ_TOKEN}`,
'Content-Type': 'application/json',
},
body: JSON.stringify({
"plan_id": "00000000-0000-0000-0000-000000000000",
"billing_cycle": "monthly"
}),
});
if (!res.ok) throw new Error(`HTTP ${res.status}: ${await res.text()}`);
console.log(await res.json());Python
import os
import requests
res = requests.request(
"POST",
"https://api-billing.axuz.net/v1/teams/TEAM_ID/billing/subscription/upgrade",
headers={
"Authorization": f"Bearer {os.environ['AXUZ_TOKEN']}",
},
json={
"plan_id": "00000000-0000-0000-0000-000000000000",
"billing_cycle": "monthly",
},
timeout=30,
)
res.raise_for_status()
print(res.json())