Assinaturas do Merchant
Gerencie as assinaturas de um Merchant a partir do Dashboard — inspecione o ciclo de vida e o dunning, pause ou retome, cancele e altere a oferta cobrada.
Uma assinatura é um acordo recorrente entre um cliente e um Merchant, cobrado contra uma oferta. Esses endpoints são a base da tela de assinaturas do Dashboard: listar e abrir assinaturas, percorrer seu histórico de transições, pausar e retomar, cancelar e mover uma para uma oferta diferente.
Toda mudança de estado é registrada como uma transição — o histórico somente-acréscimo que responde o que mudou, quando e por quê. O dunning faz parte desse ciclo de vida: uma renovação que falha move a assinatura para um estado de reprocessamento em vez de encerrá-la de imediato.
Esses endpoints alimentam a Tokeflow Dashboard UI. Eles são autenticados por sessão (JWT bearer) — o token vem do login no Dashboard, não de uma chave de API sk_/pk_. As solicitações também levam o header x-merchant-id que identifica o Merchant em contexto, e o usuário logado deve ser um membro com acesso a ele.
O objeto de assinatura
Retornado pelos endpoints de listagem e recuperação desta página.
| Field | Type | Description |
|---|---|---|
id | string | ID da assinatura. |
merchant_id | string | ID do Merchant. |
customer_id | string | ID do cliente. |
customer_name | string | null | Nome do cliente (resolvido). |
customer_email | string | null | E-mail do cliente (resolvido). |
current_offer_id | string | ID da oferta atual. |
offer_name | string | Nome da oferta (resolvido). |
product_id | string | ID do produto da oferta atual. |
product_name | string | Nome do produto (resolvido). |
product_family_id | string | ID da família de produtos. |
billing_cycle | string | Um de daily, biweekly, monthly, quarterly, half_yearly, yearly, custom, none. |
currency | string | Moeda ISO 4217. |
current_amount | number | Valor da cobrança atual em unidades menores. |
current_period_start | string | (ISO 8601 UTC). |
current_period_end | string | (ISO 8601 UTC). |
next_billing_at | string | null | (ISO 8601 UTC). |
billing_anchor_day | number | null | — |
trial_start | string | null | (ISO 8601 UTC). |
trial_end | string | null | (ISO 8601 UTC). |
dunning_started_at | string | null | (ISO 8601 UTC). |
dunning_attempt_count | number | — |
dunning_next_retry_at | string | null | (ISO 8601 UTC). |
cycles_completed | number | — |
cycle_limit | number | null | — |
status | string | Um de trialing, active, dunning, paused, cancelled, expired. |
cancel_at_period_end | boolean | — |
cancelled_at | string | null | (ISO 8601 UTC). |
cancellation_reason | string | null | — |
payment_instrument_id | string | — |
preferred_connector_id | string | null | — |
preferred_connector_name | string | Nome do conector preferido (resolvido). |
initial_network_transaction_id | string | null | — |
preferred_installments | number | — |
created_at | string | (ISO 8601 UTC). |
updated_at | string | (ISO 8601 UTC). |
Endpoints
GET/api/v1/merchant/subscriptions
Auth: Dashboard session (JWT bearer). É necessário ser membro do Merchant.
Lista as assinaturas do Merchant.
Parâmetros de consulta
| Field | Type | Required | Description |
|---|---|---|---|
page | number | Não | Número da página (indexado a partir de 1). Padrão 1, mín. 1. |
limit | number | Não | Número de itens por página. Padrão 20, mín. 1, máx. 100. |
customer_id | string | Não | Filtra por ID do cliente |
status | string | Não | Filtra por status da assinatura |
current_offer_id | string | Não | Filtra por ID da oferta atual |
product_family_id | string | Não | Filtra por ID da família de produtos |
Exemplo de solicitação
curl -G https://api.tokeflow.com/api/v1/merchant/subscriptions \
-H "Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9…" \
-H "x-merchant-id: mrc_8a3f12d9" \
--data-urlencode "page=1" \
--data-urlencode "limit=20" \
--data-urlencode "customer_id=cust_123" \
--data-urlencode "status=active"Exemplo de resposta — 200
{
"data": [
{
"id": "sub_123",
"merchant_id": "mrc_123",
"customer_id": "cust_123",
"customer_name": "Acme Store",
"customer_email": "jane@example.com",
"current_offer_id": "off_123",
"offer_name": "Acme Store",
"product_id": "prd_9b1e6c05",
"product_name": "Acme Store",
"product_family_id": "pfam_123",
"billing_cycle": "monthly",
"currency": "BRL",
"current_amount": 4990,
"current_period_start": "2026-05-25T00:00:00Z",
"current_period_end": "2026-06-25T00:00:00Z",
"next_billing_at": "2026-06-25T00:00:00Z",
"billing_anchor_day": 25,
"trial_start": "2026-05-25T00:00:00Z",
"trial_end": "2026-06-08T00:00:00Z",
"dunning_started_at": "2026-01-15T12:30:00.000Z",
"dunning_attempt_count": 0,
"dunning_next_retry_at": "2026-01-15T12:30:00.000Z",
"cycles_completed": 3,
"cycle_limit": 12,
"status": "active",
"cancel_at_period_end": false
}
],
"meta": {
"page": 1,
"limit": 20,
"total": 42,
"total_pages": 3,
"has_next": true,
"has_prev": false
}
}GET/api/v1/merchant/subscriptions/:id
Auth: Dashboard session (JWT bearer). É necessário ser membro do Merchant.
Recupera a assinatura pelo ID.
Parâmetros de caminho
| Field | Type | Required | Description |
|---|---|---|---|
id | string | Sim | — |
Exemplo de solicitação
curl https://api.tokeflow.com/api/v1/merchant/subscriptions/obj_1a2b3c4d \
-H "Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9…" \
-H "x-merchant-id: mrc_8a3f12d9"Exemplo de resposta — 200
{
"id": "sub_123",
"merchant_id": "mrc_123",
"customer_id": "cust_123",
"customer_name": "Acme Store",
"customer_email": "jane@example.com",
"current_offer_id": "off_123",
"offer_name": "Acme Store",
"product_id": "prd_9b1e6c05",
"product_name": "Acme Store",
"product_family_id": "pfam_123",
"billing_cycle": "monthly",
"currency": "BRL",
"current_amount": 4990,
"current_period_start": "2026-05-25T00:00:00Z",
"current_period_end": "2026-06-25T00:00:00Z",
"next_billing_at": "2026-06-25T00:00:00Z",
"billing_anchor_day": 25,
"trial_start": "2026-05-25T00:00:00Z",
"trial_end": "2026-06-08T00:00:00Z",
"dunning_started_at": "2026-01-15T12:30:00.000Z",
"dunning_attempt_count": 0,
"dunning_next_retry_at": "2026-01-15T12:30:00.000Z",
"cycles_completed": 3,
"cycle_limit": 12,
"status": "active",
"cancel_at_period_end": false
}POST/api/v1/merchant/subscriptions/:id/cancel
Auth: Dashboard session (JWT bearer). É necessário ser membro do Merchant.
Cancela a assinatura (atribuição de admin).
Parâmetros de caminho
| Field | Type | Required | Description |
|---|---|---|---|
id | string | Sim | — |
Campos da solicitação
| Field | Type | Required | Description |
|---|---|---|---|
at_period_end | boolean | Sim | Quando true, adia o cancelamento para a próxima renovação; false cancela imediatamente. |
reason | string | Não | Motivo opcional legível por humanos persistido na assinatura. |
Exemplo de solicitação
curl -X POST https://api.tokeflow.com/api/v1/merchant/subscriptions/obj_1a2b3c4d/cancel \
-H "Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9…" \
-H "x-merchant-id: mrc_8a3f12d9" \
-H "Content-Type: application/json" \
-d '{
"at_period_end": true,
"reason": "customer no longer needs the service"
}'Exemplo de resposta — 200
{
"id": "sub_123",
"merchant_id": "mrc_123",
"customer_id": "cust_123",
"customer_name": "Acme Store",
"customer_email": "jane@example.com",
"current_offer_id": "off_123",
"offer_name": "Acme Store",
"product_id": "prd_9b1e6c05",
"product_name": "Acme Store",
"product_family_id": "pfam_123",
"billing_cycle": "monthly",
"currency": "BRL",
"current_amount": 4990,
"current_period_start": "2026-05-25T00:00:00Z",
"current_period_end": "2026-06-25T00:00:00Z",
"next_billing_at": "2026-06-25T00:00:00Z",
"billing_anchor_day": 25,
"trial_start": "2026-05-25T00:00:00Z",
"trial_end": "2026-06-08T00:00:00Z",
"dunning_started_at": "2026-01-15T12:30:00.000Z",
"dunning_attempt_count": 0,
"dunning_next_retry_at": "2026-01-15T12:30:00.000Z",
"cycles_completed": 3,
"cycle_limit": 12,
"status": "active",
"cancel_at_period_end": false
}POST/api/v1/merchant/subscriptions/:id/change-offer
Auth: Dashboard session (JWT bearer). É necessário ser membro do Merchant.
Altera a oferta da assinatura.
Parâmetros de caminho
| Field | Type | Required | Description |
|---|---|---|---|
id | string | Sim | — |
Campos da solicitação
| Field | Type | Required | Description |
|---|---|---|---|
to_offer_id | string | Sim | ID da oferta de destino. Deve pertencer à mesma família de produtos que a oferta atual. |
Exemplo de solicitação
curl -X POST https://api.tokeflow.com/api/v1/merchant/subscriptions/obj_1a2b3c4d/change-offer \
-H "Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9…" \
-H "x-merchant-id: mrc_8a3f12d9" \
-H "Content-Type: application/json" \
-d '{
"to_offer_id": "off_premium_monthly"
}'Exemplo de resposta — 200
{
"id": "sub_123",
"merchant_id": "mrc_123",
"customer_id": "cust_123",
"customer_name": "Acme Store",
"customer_email": "jane@example.com",
"current_offer_id": "off_123",
"offer_name": "Acme Store",
"product_id": "prd_9b1e6c05",
"product_name": "Acme Store",
"product_family_id": "pfam_123",
"billing_cycle": "monthly",
"currency": "BRL",
"current_amount": 4990,
"current_period_start": "2026-05-25T00:00:00Z",
"current_period_end": "2026-06-25T00:00:00Z",
"next_billing_at": "2026-06-25T00:00:00Z",
"billing_anchor_day": 25,
"trial_start": "2026-05-25T00:00:00Z",
"trial_end": "2026-06-08T00:00:00Z",
"dunning_started_at": "2026-01-15T12:30:00.000Z",
"dunning_attempt_count": 0,
"dunning_next_retry_at": "2026-01-15T12:30:00.000Z",
"cycles_completed": 3,
"cycle_limit": 12,
"status": "active",
"cancel_at_period_end": false
}POST/api/v1/merchant/subscriptions/:id/change-payment-instrument
Auth: Dashboard session (JWT bearer). É necessário ser membro do Merchant.
Altera o instrumento de pagamento da assinatura.
Parâmetros de caminho
| Field | Type | Required | Description |
|---|---|---|---|
id | string | Sim | — |
Campos da solicitação
| Field | Type | Required | Description |
|---|---|---|---|
payment_instrument_id | string | Sim | ID do instrumento de pagamento a ser cobrado daqui em diante. |
Exemplo de solicitação
curl -X POST https://api.tokeflow.com/api/v1/merchant/subscriptions/obj_1a2b3c4d/change-payment-instrument \
-H "Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9…" \
-H "x-merchant-id: mrc_8a3f12d9" \
-H "Content-Type: application/json" \
-d '{
"payment_instrument_id": "pi_123"
}'Exemplo de resposta — 200
{
"id": "sub_123",
"merchant_id": "mrc_123",
"customer_id": "cust_123",
"customer_name": "Acme Store",
"customer_email": "jane@example.com",
"current_offer_id": "off_123",
"offer_name": "Acme Store",
"product_id": "prd_9b1e6c05",
"product_name": "Acme Store",
"product_family_id": "pfam_123",
"billing_cycle": "monthly",
"currency": "BRL",
"current_amount": 4990,
"current_period_start": "2026-05-25T00:00:00Z",
"current_period_end": "2026-06-25T00:00:00Z",
"next_billing_at": "2026-06-25T00:00:00Z",
"billing_anchor_day": 25,
"trial_start": "2026-05-25T00:00:00Z",
"trial_end": "2026-06-08T00:00:00Z",
"dunning_started_at": "2026-01-15T12:30:00.000Z",
"dunning_attempt_count": 0,
"dunning_next_retry_at": "2026-01-15T12:30:00.000Z",
"cycles_completed": 3,
"cycle_limit": 12,
"status": "active",
"cancel_at_period_end": false
}POST/api/v1/merchant/subscriptions/:id/pause
Auth: Dashboard session (JWT bearer). É necessário ser membro do Merchant.
Pausa a assinatura.
Parâmetros de caminho
| Field | Type | Required | Description |
|---|---|---|---|
id | string | Sim | — |
Campos da solicitação
| Field | Type | Required | Description |
|---|---|---|---|
reason | string | Não | Motivo opcional legível por humanos persistido na transição. |
Exemplo de solicitação
curl -X POST https://api.tokeflow.com/api/v1/merchant/subscriptions/obj_1a2b3c4d/pause \
-H "Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9…" \
-H "x-merchant-id: mrc_8a3f12d9" \
-H "Content-Type: application/json" \
-d '{
"reason": "customer travelling for 6 weeks"
}'Exemplo de resposta — 200
{
"id": "sub_123",
"merchant_id": "mrc_123",
"customer_id": "cust_123",
"customer_name": "Acme Store",
"customer_email": "jane@example.com",
"current_offer_id": "off_123",
"offer_name": "Acme Store",
"product_id": "prd_9b1e6c05",
"product_name": "Acme Store",
"product_family_id": "pfam_123",
"billing_cycle": "monthly",
"currency": "BRL",
"current_amount": 4990,
"current_period_start": "2026-05-25T00:00:00Z",
"current_period_end": "2026-06-25T00:00:00Z",
"next_billing_at": "2026-06-25T00:00:00Z",
"billing_anchor_day": 25,
"trial_start": "2026-05-25T00:00:00Z",
"trial_end": "2026-06-08T00:00:00Z",
"dunning_started_at": "2026-01-15T12:30:00.000Z",
"dunning_attempt_count": 0,
"dunning_next_retry_at": "2026-01-15T12:30:00.000Z",
"cycles_completed": 3,
"cycle_limit": 12,
"status": "active",
"cancel_at_period_end": false
}POST/api/v1/merchant/subscriptions/:id/resume
Auth: Dashboard session (JWT bearer). É necessário ser membro do Merchant.
Retoma a assinatura.
Parâmetros de caminho
| Field | Type | Required | Description |
|---|---|---|---|
id | string | Sim | — |
Exemplo de solicitação
curl -X POST https://api.tokeflow.com/api/v1/merchant/subscriptions/obj_1a2b3c4d/resume \
-H "Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9…" \
-H "x-merchant-id: mrc_8a3f12d9"Exemplo de resposta — 200
{
"id": "sub_123",
"merchant_id": "mrc_123",
"customer_id": "cust_123",
"customer_name": "Acme Store",
"customer_email": "jane@example.com",
"current_offer_id": "off_123",
"offer_name": "Acme Store",
"product_id": "prd_9b1e6c05",
"product_name": "Acme Store",
"product_family_id": "pfam_123",
"billing_cycle": "monthly",
"currency": "BRL",
"current_amount": 4990,
"current_period_start": "2026-05-25T00:00:00Z",
"current_period_end": "2026-06-25T00:00:00Z",
"next_billing_at": "2026-06-25T00:00:00Z",
"billing_anchor_day": 25,
"trial_start": "2026-05-25T00:00:00Z",
"trial_end": "2026-06-08T00:00:00Z",
"dunning_started_at": "2026-01-15T12:30:00.000Z",
"dunning_attempt_count": 0,
"dunning_next_retry_at": "2026-01-15T12:30:00.000Z",
"cycles_completed": 3,
"cycle_limit": 12,
"status": "active",
"cancel_at_period_end": false
}POST/api/v1/merchant/subscriptions/:id/reactivate
Auth: Dashboard session (JWT bearer). É necessário ser membro do Merchant.
Suspende um cancelamento agendado e mantém a assinatura no plano atual. A reativação define cancel_at_period_end de volta para false e registra uma transição reactivation; não altera a oferta, o valor nem as datas de cobrança. Disponível para uma assinatura viva (active, trialing ou dunning); uma assinatura paused deve ser retomada (resume), e uma terminal é recusada (409).
Parâmetros de caminho
| Field | Type | Required | Description |
|---|---|---|---|
id | string | Yes | — |
Exemplo de requisição
curl -X POST https://api.tokeflow.com/api/v1/merchant/subscriptions/obj_1a2b3c4d/reactivate \
-H "Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9…" \
-H "x-merchant-id: mrc_8a3f12d9"Exemplo de resposta — 200
{
"id": "sub_123",
"merchant_id": "mrc_123",
"customer_id": "cust_123",
"customer_name": "Acme Store",
"customer_email": "jane@example.com",
"current_offer_id": "off_123",
"offer_name": "Acme Store",
"product_id": "prd_9b1e6c05",
"product_name": "Acme Store",
"product_family_id": "pfam_123",
"billing_cycle": "monthly",
"currency": "BRL",
"current_amount": 4990,
"current_period_start": "2026-05-25T00:00:00Z",
"current_period_end": "2026-06-25T00:00:00Z",
"next_billing_at": "2026-06-25T00:00:00Z",
"billing_anchor_day": 25,
"trial_start": "2026-05-25T00:00:00Z",
"trial_end": "2026-06-08T00:00:00Z",
"dunning_started_at": "2026-01-15T12:30:00.000Z",
"dunning_attempt_count": 0,
"dunning_next_retry_at": "2026-01-15T12:30:00.000Z",
"cycles_completed": 3,
"cycle_limit": 12,
"status": "active",
"cancel_at_period_end": false
}GET/api/v1/merchant/subscriptions/:id/transitions
Auth: Dashboard session (JWT bearer). É necessário ser membro do Merchant.
Lista o histórico de transições da assinatura.
Parâmetros de caminho
| Field | Type | Required | Description |
|---|---|---|---|
id | string | Sim | — |
Exemplo de solicitação
curl https://api.tokeflow.com/api/v1/merchant/subscriptions/obj_1a2b3c4d/transitions \
-H "Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9…" \
-H "x-merchant-id: mrc_8a3f12d9"Exemplo de resposta — 200
{
"data": [
{
"id": "sbt_123",
"subscription_id": "sub_123",
"transition_type": "creation",
"from_offer_id": "off_basic_monthly",
"to_offer_id": "off_premium_monthly",
"from_status": "trialing",
"to_status": "trialing",
"triggered_by": "customer",
"order_id": "ord_123",
"reason": "requested_by_customer",
"metadata": {},
"created_at": "2026-01-15T12:30:00.000Z"
}
]
}Erros
Os erros usam o envelope padrão. Os casos mais comuns aqui:
| HTTP | Significado |
|---|---|
400 | Parâmetros inválidos ou um estado que não permite esta operação. |
401 | Token de sessão do Dashboard ausente, expirado ou inválido. |
403 | Autenticado, mas o usuário logado não tem acesso a esta entidade. |
404 | O registro não existe ou não é visível para esta entidade. |