curl --request PUT \
--url https://api.weve.cx/v1/clubs/{clubId}/billing/plan \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"plan": "plan_cotton"
}
'import requests
url = "https://api.weve.cx/v1/clubs/{clubId}/billing/plan"
payload = { "plan": "plan_cotton" }
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.put(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'PUT',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({plan: 'plan_cotton'})
};
fetch('https://api.weve.cx/v1/clubs/{clubId}/billing/plan', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.weve.cx/v1/clubs/{clubId}/billing/plan",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "PUT",
CURLOPT_POSTFIELDS => json_encode([
'plan' => 'plan_cotton'
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.weve.cx/v1/clubs/{clubId}/billing/plan"
payload := strings.NewReader("{\n \"plan\": \"plan_cotton\"\n}")
req, _ := http.NewRequest("PUT", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.put("https://api.weve.cx/v1/clubs/{clubId}/billing/plan")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"plan\": \"plan_cotton\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.weve.cx/v1/clubs/{clubId}/billing/plan")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Put.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"plan\": \"plan_cotton\"\n}"
response = http.request(request)
puts response.read_body{
"managed": true,
"portal_available": true,
"period_start": "2023-11-07T05:31:56Z",
"period_end": "2023-11-07T05:31:56Z",
"plan": {
"key": "plan_linen",
"name": "Linho"
},
"interval": "month",
"next_invoice_at": "2023-11-07T05:31:56Z",
"pending_plan": {
"plan": {
"key": "plan_linen",
"name": "Linho"
},
"interval": "month",
"effective_at": "2023-11-07T05:31:56Z"
},
"plan_options": [
{
"key": "plan_cotton",
"name": "Algodão",
"monthly_price_cents": 123,
"yearly_price_cents": 123
}
],
"addons": [
{
"key": "plan_linen",
"name": "Linho"
}
],
"available_addons": [
{
"key": "addon_lives",
"name": "Lives",
"monthly_price_cents": 123,
"setup_price_cents": 123,
"contracted": true,
"ends_at": "2023-11-07T05:31:56Z",
"removable": true,
"unavailable_reason": "not_in_plan",
"required_plans": [
"Linho"
]
}
],
"resources": [
{
"key": "campaign_sends",
"name": "Envios de campanha",
"kind": "flag",
"granted": true,
"unlimited": true,
"allowance": 123,
"balance": 123,
"used": 123,
"overage": 123,
"bills": true
}
]
}{
"error": {
"code": "<string>",
"message": "<string>"
}
}{
"error": {
"code": "<string>",
"message": "<string>"
}
}{
"error": {
"code": "<string>",
"message": "<string>"
}
}{
"error": {
"code": "<string>",
"message": "<string>"
}
}{
"error": {
"code": "<string>",
"message": "<string>"
}
}{
"error": {
"code": "<string>",
"message": "<string>"
}
}{
"error": {
"code": "<string>",
"message": "<string>"
}
}{
"error": {
"code": "<string>",
"message": "<string>"
}
}Trocar o plano
Sobe na hora, cobrando a diferença; desce na virada do ciclo pago.
curl --request PUT \
--url https://api.weve.cx/v1/clubs/{clubId}/billing/plan \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"plan": "plan_cotton"
}
'import requests
url = "https://api.weve.cx/v1/clubs/{clubId}/billing/plan"
payload = { "plan": "plan_cotton" }
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.put(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'PUT',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({plan: 'plan_cotton'})
};
fetch('https://api.weve.cx/v1/clubs/{clubId}/billing/plan', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.weve.cx/v1/clubs/{clubId}/billing/plan",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "PUT",
CURLOPT_POSTFIELDS => json_encode([
'plan' => 'plan_cotton'
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.weve.cx/v1/clubs/{clubId}/billing/plan"
payload := strings.NewReader("{\n \"plan\": \"plan_cotton\"\n}")
req, _ := http.NewRequest("PUT", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.put("https://api.weve.cx/v1/clubs/{clubId}/billing/plan")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"plan\": \"plan_cotton\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.weve.cx/v1/clubs/{clubId}/billing/plan")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Put.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"plan\": \"plan_cotton\"\n}"
response = http.request(request)
puts response.read_body{
"managed": true,
"portal_available": true,
"period_start": "2023-11-07T05:31:56Z",
"period_end": "2023-11-07T05:31:56Z",
"plan": {
"key": "plan_linen",
"name": "Linho"
},
"interval": "month",
"next_invoice_at": "2023-11-07T05:31:56Z",
"pending_plan": {
"plan": {
"key": "plan_linen",
"name": "Linho"
},
"interval": "month",
"effective_at": "2023-11-07T05:31:56Z"
},
"plan_options": [
{
"key": "plan_cotton",
"name": "Algodão",
"monthly_price_cents": 123,
"yearly_price_cents": 123
}
],
"addons": [
{
"key": "plan_linen",
"name": "Linho"
}
],
"available_addons": [
{
"key": "addon_lives",
"name": "Lives",
"monthly_price_cents": 123,
"setup_price_cents": 123,
"contracted": true,
"ends_at": "2023-11-07T05:31:56Z",
"removable": true,
"unavailable_reason": "not_in_plan",
"required_plans": [
"Linho"
]
}
],
"resources": [
{
"key": "campaign_sends",
"name": "Envios de campanha",
"kind": "flag",
"granted": true,
"unlimited": true,
"allowance": 123,
"balance": 123,
"used": 123,
"overage": 123,
"bills": true
}
]
}{
"error": {
"code": "<string>",
"message": "<string>"
}
}{
"error": {
"code": "<string>",
"message": "<string>"
}
}{
"error": {
"code": "<string>",
"message": "<string>"
}
}{
"error": {
"code": "<string>",
"message": "<string>"
}
}{
"error": {
"code": "<string>",
"message": "<string>"
}
}{
"error": {
"code": "<string>",
"message": "<string>"
}
}{
"error": {
"code": "<string>",
"message": "<string>"
}
}{
"error": {
"code": "<string>",
"message": "<string>"
}
}Authorizations
Token OPACO de sessão de quem administra, emitido por
/v1/auth/admin/sign-in e verificado contra a nossa tabela — o mesmo
desenho do studentSession, para a outra identidade.
É o esquema de quem ADMINISTRA — o dashboard. O aluno do classroom usa o
studentSession; uma rota consumida pelos dois declara os dois
esquemas, e o middleware aceita qualquer um deles. As duas credenciais
são opacas e chegam pelo mesmo cabeçalho: quem as separa é a tabela em
que cada uma existe.
O dashboard o guarda em cookie httpOnly, que o BFF troca pelo
Authorization a cada chamada.
Path Parameters
Id público da organização — o mesmo que GET /v1/me devolve em
organization_id.
Na URL o recurso se chama club; no contrato e no domínio, organization.
A divergência é deliberada: clubs é a palavra do produto, e a URL é o que
as pessoas leem.
É o identificador do provedor de autenticação, e é assim de propósito: o cliente precisa nomear a organização ao pedir o token, e o token é o que prova o escopo. Um id só nosso obrigaria a traduzir um no outro antes de ter um token — e a tradução exigiria uma chamada escopada, que é justamente a que ainda não dá para fazer.
O uuid interno da organização não aparece no contrato: ele é o que as chaves estrangeiras do domínio referenciam, e continua sendo nosso.
Body
Response
O plano e o uso, como ficaram
Se o club está sob limites. Falso é o club que ainda não tem plano.
Se a cobrança tem como responder — o ambiente tem a Stripe configurada. É o que decide se a tela oferece trocar de plano, contratar adicional e abrir o portal: um botão que só responderia 501 não é botão.
Show child attributes
Show child attributes
O intervalo do plano de agora.
month, year A próxima fatura — a virada do ciclo pago do plano na Stripe. Nulo no club sem assinatura (ainda não pagou nada). É a data que a tela diz ao cobrar, e o dia em que uma descida marcada passa a valer.
A descida marcada para a virada, se há uma.
Show child attributes
Show child attributes
Os planos à venda, com os preços que valem para este club.
Show child attributes
Show child attributes
Show child attributes
Show child attributes
Os adicionais do catálogo, para a tela oferecer. Vazio onde não há o que oferecer: club sem plano, ou ambiente sem a Stripe.
Show child attributes
Show child attributes
Show child attributes
Show child attributes