Pular para o conteúdo principal
POST
Create a Subscription

Pré-requisitos

  1. Crie o cliente com POST /v2/customers — a resposta inclui o customer_id (UUID) que você passa abaixo.
  2. Numa assinatura com cartão, tokenize o cartão pelo fluxo seguro do Payment Element — isso retorna um token de pagamento pgct_ de uso único. Uma assinatura com Pix Automático não usa token.
Assinaturas não criam clientes automaticamente a partir do corpo da requisição; um customer_id desconhecido retorna 404.

Comportamento

customer_id é o identificador público (UUID) do cliente retornado por POST /v2/customers. Numa assinatura com cartão, token precisa ser um token pgct_ de uso único. Numa assinatura com cartão, quando trial_end é informado, podemos cobrar um valor pequeno e estorná-lo para validar o meio de pagamento, e a assinatura é criada com status trialing até o teste expirar. Sem trial_end, a assinatura é criada com status active após o primeiro charge bem-sucedido. Com payment_method: "pix_automatic", não envie token. A assinatura é criada com status incomplete e um QR code em authorization para o pagador. Ela passa para active quando o pagador autoriza e o primeiro débito é pago, ou para trialing quando há trial_end e a autorização é aprovada. Veja Assinaturas com Pix Automático. amount está em centavos e é usado também para cobrar cada ciclo de renovação.

Autorizações

Authorization
string
header
obrigatório

Bearer authentication header of the form Bearer <token>, where <token> is your auth token.

Corpo

application/json
customer_id
string
obrigatório

Public customer id (UUID) returned by POST /v2/customers.

Minimum string length: 1
token
string
obrigatório
Minimum string length: 6
interval
enum<string>

Required without product_id.

Opções disponíveis:
day,
week,
month
interval_count
integer

Defaults to 1 without product_id.

Intervalo obrigatório: 1 <= x <= 365
failure_policy
enum<string>
padrão:retry_then_cancel
Opções disponíveis:
immediate_cancel,
retry_then_cancel,
retry_then_unpaid
retry_offsets_days
integer[]
Required array length: 1 - 10 elements
Intervalo obrigatório: 1 <= x <= 30
amount
integer

Billing amount in cents (max 100,000,000). Required without product_id.

Intervalo obrigatório: 0 < x <= 100000000
currency
enum<string>

Defaults to BRL without product_id.

Opções disponíveis:
BRL,
MXN,
COP,
CLP,
ARS,
PEN,
USD,
GTQ,
CRC,
NIO,
PYG,
UYU,
BOB,
PHP,
RUB,
INR,
SAR,
AED,
KWD,
QAR,
OMR,
KHR,
SGD,
IDR,
KRW,
THB,
MYR,
HKD,
CNY,
EGP,
EUR,
GBP,
BHD,
MAD,
AUD,
CAD,
CHF,
NZD,
PLN,
KZT,
UZS,
JPY,
GLC
metadata
object | null
informations
object[]

Custom key/value metadata to attach to the subscription and echo on its webhooks.

Maximum array length: 50
idempotency_key
string | null
Required string length: 1 - 255
products
object[]
Maximum array length: 100
payment_method
enum<string>
padrão:credit_card
Opções disponíveis:
credit_card
product_id
string<uuid>

Public id of a recurring catalog product. The plan sets amount, interval, interval_count, currency and max_cycles; sending one of them with a different value returns 422 PLAN_TERMS_MISMATCH.

Pattern: ^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)$
quantity
integer

Quantity of the plan. Requires product_id; defaults to 1.

Intervalo obrigatório: 1 <= x <= 999999
ip_address

Public IPv4 or IPv6 address of the buyer, recorded on the first charge.

Pattern: ^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])$
Exemplo:

"8.8.8.8"

trial_end
string<date-time> | null

Trial end timestamp (ISO 8601). Must be in the future.

Pattern: ^(?:(?:\d\d[2468][048]|\d\d[13579][26]|\d\d0[48]|[02468][048]00|[13579][26]00)-02-29|\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\d|30)|(?:02)-(?:0[1-9]|1\d|2[0-8])))T(?:(?:[01]\d|2[0-3]):[0-5]\d:[0-5]\d(?:\.\d+)?(?:Z|([+-](?:[01]\d|2[0-3]):[0-5]\d)))$
max_cycles
integer | null

Number of paid charges after which the subscription ends. Requires a monthly interval, no trial and a failure policy other than retry_then_unpaid. Omit for a subscription with no end.

Intervalo obrigatório: 2 <= x <= 120

Resposta

HTTP 201 response

success
boolean
obrigatório
requestId
string
obrigatório
data
object
obrigatório