Skip to content

Change a subscription's plan (upgrade or downgrade)

POST
/v1/subscriptions/{id}/change_plan
curl --request POST \
--url https://pay.example.com/v1/subscriptions/2489E9AD-2EE2-8E00-8EC9-32D5F69181C0/change_plan \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--header 'Idempotency-Key: example' \
--data '{ "plan_id": "8a1c2e40-7d3b-4b8f-a0e6-5f9d3c2b1a07" }'

“Cancel the old subscription, create a new one from the next period” (DESIGN.md §6.3.1): on-chain terms are immutable, so the payer authorizes the new plan at the returned subscription’s checkout_url. Its first period starts at the old subscription’s next period boundary at least 30 minutes ahead (plan_change.effective_at) and is not charged in the subscribe transaction; the old subscription keeps its current period, and nothing is prorated (bill a difference as a one-time order). From the request on, the old subscription charges no period from the boundary (subscription.plan_change_pending on it). The link expires at the latest 15 minutes before the boundary (expires_in is capped); unanswered, the change expires 10 minutes after the link (subscription.plan_change_expired, the new subscription canceled with cancel_source: expired) and the old subscription goes on unchanged. Once the new on-chain subscription is confirmed: subscription.plan_changed (instead of subscription.activated) for the new one, and the old one ends (canceled, cancel_source: plan_changed) as soon as its current period is charged or over, then is canceled on chain; its event is subscription.replaced (replaced_by, effective_at), not subscription.canceled, since the customer’s service goes on with the new subscription. A new request supersedes a pending change whose payer has not subscribed yet (subscription.plan_change_canceled, reason: superseded); canceling either subscription withdraws it (reason: subscription_ended / canceled). Only trialing / active subscriptions confirmed on chain change plan (a trial is not granted again: the new plan starts where the trial ends). The new subscription carries over the customer, receipt email, locale, metadata and return URL (the request’s override them); its splits are the request’s, else the new plan’s default rule, else the old subscription’s. The payer confirms with the wallet paying the old subscription. Idempotent (see the introduction). Requires subscriptions:write.

id
required
string format: uuid

A UUID (400 invalid_request, params.field: id, otherwise).

Idempotency-Key
required
string
>= 1 characters <= 255 characters

Any unique string per logical request (a UUID); see the introduction.

Media typeapplication/json
object
plan_id
required

An active plan other than the current one.

string format: uuid
split_rule_id
string format: uuid
splits
Array<object>
>= 1 items <= 10 items

A split member: {payee_ref | payee_id, kind: ratio, bps} or {payee_ref | payee_id, kind: fixed, fixed_amount}, naming a payee registered in the console (the split whitelist).

With the split whitelist switched off in the console, a member may name its recipient by address (with an optional name) instead of payee_id / payee_ref. The address is checked as at registration (checksum, not zero, not a system address: 400 invalid_request, params.field splits[i].address) and screened on every enabled chain of its family that could pay (risk lists, sanctions, token blocklists, account type); a hit refuses the request (422 payee_blocked). The first member of a list with an address is the main payee (payTo[0], which takes the remainder and bears refunds) and must be a ratio member (400 main_payee_first) naming a registered payee (400 main_payee_not_registered). The address appears in splits[] of the order or subscription as a payee whose payee_ref is <family>:<address> (e.g. evm:0xab…). With the whitelist on, address answers 400 split_address_not_allowed.

object
payee_id
string format: uuid
payee_ref

The payee’s reference (alternative to payee_id). The payee must be active.

string
address

The recipient’s address (the split whitelist off), not with payee_id / payee_ref: EVM 0x + 40 hex digits (EIP-55 checked when mixed case), TRON T… (Base58Check) or a Solana Base58 public key.

string
name

With address: the recipient’s name, shown in the console and statements (default: the address; a later name replaces it).

string
<= 80 characters
kind
required
string
Allowed values: ratio fixed
bps

For ratio: share of what the fixed members leave, in basis points; the ratio members sum to 10000.

integer
<= 10000
fixed_amount

For fixed: an amount in the order’s currency (the plan’s for subscriptions).

string
/^\d+(\.\d+)?$/
tokens

Accepted token symbols (default: the new plan’s).

Array<string>
chains
Array<integer>
return_url

Default: the old subscription’s.

string format: uri
<= 2048 characters
locale

Default: the old subscription’s.

string
Allowed values: zh-CN en
metadata

Default: the old subscription’s.

expires_in

Seconds the link stays usable; never past 15 minutes before effective_at.

integer
default: 604800 >= 60 <= 2592000
Example
{
"plan_id": "8a1c2e40-7d3b-4b8f-a0e6-5f9d3c2b1a07"
}

The new subscription (incomplete, replaces the old one) with plan_change

Media typeapplication/json

A subscription. API answers add checkout_url (and the change_plan answer plan_change); subscription events (data of subscription.*) add the fields their type describes (see the properties marked “Events:”).

object
id
required
string format: uuid
livemode
required

false for a test subscription (created with a test key).

boolean
plan_id
required
string format: uuid
plan_name
required
string
customer_ref
required
string | null
status
required

incomplete (link sent, nothing on chain) → trialing | active once the on-chain subscription is confirmed → past_due after a failed charge (retried) → unpaid or canceled when the grace period runs out; paused; canceled; completed after the last period.

string
Allowed values: incomplete trialing active past_due unpaid paused canceled completed
checkout_url

API answers only: the subscription link (<public_url>/pay/sub/{id}).

string format: uri
chain_id
required

The network paid on (null while incomplete).

integer | null
chain
required
One of:

The chain a record is on: its id (chain_id as well, unchanged), CAIP-2 identifier and family.

object
id
required
integer
caip2
required

eip155:<id>, tron:0x2b6653dc, solana:<genesis hash prefix>.

string
family
required

Chain family: decides the address and transaction id forms, and the wallets that can pay.

string
Allowed values: evm tron solana
token
required

Token symbol.

string | null
payer
required
One of:
Any of:

An account address in its chain family’s own form: EVM 0x + 40 hex digits (orders, subscriptions and tickets give it in lowercase hex; the risk list EIP-55 checksummed), TRON Base58Check (T…, 34 characters), Solana Base58 (32 bytes, 32-44 characters). Requests accept any of the three.

string
/^0x[0-9a-fA-F]{40}$/
sub_id
required
One of:

32-byte hash of this system’s own (order hash, on-chain subscription id), lowercase hex.

string
/^0x[0-9a-f]{64}$/
amount_per_period
required

Token base units.

string | null
/^\d+$/
period_seconds
required
integer
max_periods
required
integer
trial_seconds
required
integer
start_at
required

Start of period 0 (after the trial).

string | null format: date-time
trial_end_at
required
string | null format: date-time
next_charge_at
required
string | null format: date-time
charges_made
required
integer
last_charged_index
required

0-based index of the last period charged.

integer | null
past_due_since
required
string | null format: date-time
last_error
required

Of the last failed charge: balance, allowance, or the revert reason.

string | null
cancel_source
required

payer (“my subscriptions”, an on-chain cancel by the payer, or a revoked allowance), merchant (this API or the console), chain (canceled on chain by someone else), unpaid (the grace period ran out on a cancel plan), plan_changed (the old subscription of an applied plan change), expired (the new subscription of a change the payer did not confirm in time).

string | null
Allowed values: payer merchant chain unpaid plan_changed expired
splits
required

Resolved on the paid chain once the payer subscribes (empty while incomplete).

Array<object>
object
position
required
integer
payee_id
required
string format: uuid
payee_ref
required
string
address
required
Any of:

An account address in its chain family’s own form: EVM 0x + 40 hex digits (orders, subscriptions and tickets give it in lowercase hex; the risk list EIP-55 checksummed), TRON Base58Check (T…, 34 characters), Solana Base58 (32 bytes, 32-44 characters). Requests accept any of the three.

string
/^0x[0-9a-fA-F]{40}$/
kind
required
string
Allowed values: ratio fixed
bps
required
integer | null
amount_per_period
required

Token amount in base units (integer string; 1 USDC = “1000000”).

string
/^\d+$/
locale
required
string | null
return_url
required
string | null
metadata
required

As given (null when none).

created_at
required
string format: date-time
canceled_at
required
string | null format: date-time
replaces
required

The subscription this one replaces (a plan change’s new subscription).

string | null format: uuid
replaced_by
required

The subscription an applied plan change moved this one to (event subscription.replaced).

string | null format: uuid
pending_plan_change
required
One of:
object
id
required
string format: uuid
subscription_id
required

The subscription being replaced.

string format: uuid
new_subscription_id
required
string format: uuid
plan_id
required
string format: uuid
plan_name
required
string
status
required
string
Allowed values: pending applied expired canceled
effective_at
required

The new subscription’s first period starts (the old one’s next period boundary).

string format: date-time
expires_at
required

The new subscription’s link stays usable until then.

string | null format: date-time
source
required
string
Allowed values: api console
reason
required

Why it was canceled: a newer change, the new subscription canceled, the old one ended.

string | null
Allowed values: superseded canceled subscription_ended
created_at
required
string format: date-time
ended_at
required
string | null format: date-time
checkout_url

Only in pending_plan_change of GET /v1/subscriptions/{id}: where the payer confirms (the new subscription’s link).

string format: uri
plan_change

The change_plan answer, and events subscription.plan_change_pending / _expired / _canceled (on the old subscription): the change.

object
id
required
string format: uuid
subscription_id
required

The subscription being replaced.

string format: uuid
new_subscription_id
required
string format: uuid
plan_id
required
string format: uuid
plan_name
required
string
status
required
string
Allowed values: pending applied expired canceled
effective_at
required

The new subscription’s first period starts (the old one’s next period boundary).

string format: date-time
expires_at
required

The new subscription’s link stays usable until then.

string | null format: date-time
source
required
string
Allowed values: api console
reason
required

Why it was canceled: a newer change, the new subscription canceled, the old one ended.

string | null
Allowed values: superseded canceled subscription_ended
created_at
required
string format: date-time
ended_at
required
string | null format: date-time
checkout_url

Only in pending_plan_change of GET /v1/subscriptions/{id}: where the payer confirms (the new subscription’s link).

string format: uri
charge

Events: subscription.charged and subscription.charged_after_cancel — {id, period_index, amount, tx_hash}; subscription.charge_failed, subscription.unpaid and a subscription.canceled caused by the grace period — {id, period_index, error}.

object
id
required
string format: uuid
period_index
required
integer
amount

Token amount in base units (integer string; 1 USDC = “1000000”).

string
/^\d+$/
tx_hash
Any of:

In the subscription’s chain family’s form (data.chain).

string
/^0x[0-9a-f]{64}$/
error

balance, allowance, or the revert reason.

string
retry_at

Events with a failed charge: the next attempt (null: none).

string | null format: date-time
previous_status

Event subscription.paused: the status before.

string
previous

Events: subscription.plan_changed — the replaced subscription {id, plan_id, plan_name}; subscription.payment_method_changed — the previous method {chain_id, token, payer}.

object
id
string format: uuid
plan_id
string format: uuid
plan_name
string
chain_id
integer | null
token
string | null
payer
One of:
Any of:

An account address in its chain family’s own form: EVM 0x + 40 hex digits (orders, subscriptions and tickets give it in lowercase hex; the risk list EIP-55 checksummed), TRON Base58Check (T…, 34 characters), Solana Base58 (32 bytes, 32-44 characters). Requests accept any of the three.

string
/^0x[0-9a-fA-F]{40}$/
switch

Event subscription.payment_method_changed: the new method (token and chain_id are also the subscription’s own).

object
chain_id
required
integer
payer
required
Any of:

An account address in its chain family’s own form: EVM 0x + 40 hex digits (orders, subscriptions and tickets give it in lowercase hex; the risk list EIP-55 checksummed), TRON Base58Check (T…, 34 characters), Solana Base58 (32 bytes, 32-44 characters). Requests accept any of the three.

string
/^0x[0-9a-fA-F]{40}$/
migration

Event subscription.migration_requested: the merchant replaced its quote signer key and asks the payer to move the subscription to the new payment contract through “my subscriptions” (charges continue on the old contract until then; tell the customer).

object
reason
required
string
Allowed values: signer_rotated signer_compromised
action
required
string
Allowed values: switch_payment_method
effective_at

Events subscription.plan_changed and subscription.replaced: the boundary the new plan starts at.

string format: date-time
reason

Event subscription.canceled: subscription_ended (a plan change’s new subscription whose old one ended first, with before_activation).

string
Allowed values: subscription_ended
before_activation

Event subscription.canceled: the subscription was canceled before its on-chain subscription was confirmed (it never got subscription.activated).

boolean
canceled_by
Any of:

Event subscription.canceled after an on-chain cancel: who sent it.

string
/^0x[0-9a-fA-F]{40}$/
allowance

Event subscription.allowance_low: what the allowance leaves after the pending charge.

string
/^\d+$/
needed

Event subscription.allowance_low: what the remaining periods need.

string
/^\d+$/
Example
{
"status": "incomplete",
"chain": {
"caip2": "eip155:8453",
"family": "evm"
},
"cancel_source": "payer",
"splits": [
{
"kind": "ratio"
}
],
"pending_plan_change": {
"status": "pending",
"source": "api",
"reason": "superseded"
},
"plan_change": {
"status": "pending",
"source": "api",
"reason": "superseded"
},
"migration": {
"reason": "signer_rotated",
"action": "switch_payment_method"
},
"reason": "subscription_ended"
}

invalid_request: the body is not JSON or has an unknown field or a wrong type; an unknown or retired plan_id; expires_in outside 60 – 2592000; return_url; locale (params: field, allowed); split errors as for orders; missing Idempotency-Key. invalid_splits and the split address codes as for orders.

Media typeapplication/json
object
error
required
object
code
required
string
message
required

English, for logs; may change.

string
params

Values for a localized message, e.g. {"field": "expires_in", "min": 60, "max": 604800}. Absent when the error has none.

object
key
additional properties
any
error
required
object
code
Allowed values: invalid_request invalid_splits split_address_not_allowed main_payee_first main_payee_not_registered
Example
{
"error": {
"code": "invalid_request"
}
}

unauthorized: no Authorization: Bearer header, or an unknown or revoked key.

Media typeapplication/json
object
error
required
object
code
required
string
message
required

English, for logs; may change.

string
params

Values for a localized message, e.g. {"field": "expires_in", "min": 60, "max": 604800}. Absent when the error has none.

object
key
additional properties
any
error
required
object
code
Allowed values: unauthorized
Example
{
"error": {
"code": "unauthorized"
}
}

insufficient_scope: the key lacks the operation’s scope.

Media typeapplication/json
object
error
required
object
code
required
string
message
required

English, for logs; may change.

string
params

Values for a localized message, e.g. {"field": "expires_in", "min": 60, "max": 604800}. Absent when the error has none.

object
key
additional properties
any
error
required
object
code
Allowed values: insufficient_scope
Example
{
"error": {
"code": "insufficient_scope"
}
}

not_found (params.what: order, subscription, entry): unknown, or another mode’s.

Media typeapplication/json
object
error
required
object
code
required
string
message
required

English, for logs; may change.

string
params

Values for a localized message, e.g. {"field": "expires_in", "min": 60, "max": 604800}. Absent when the error has none.

object
key
additional properties
any
error
required
object
code
Allowed values: not_found
Example
{
"error": {
"code": "not_found"
}
}

same_plan: the subscription is on this plan already. not_changeable (params.status): not trialing / active, not confirmed on chain yet, no period boundary left before it ends, or its schedule moved meanwhile (try again). switch_in_flight: a payment-method switch is being confirmed. plan_change_in_flight: the payer’s subscribe of an earlier change is on its way. request_in_progress.

Media typeapplication/json
object
error
required
object
code
required
string
message
required

English, for logs; may change.

string
params

Values for a localized message, e.g. {"field": "expires_in", "min": 60, "max": 604800}. Absent when the error has none.

object
key
additional properties
any
error
required
object
code
Allowed values: same_plan not_changeable switch_in_flight plan_change_in_flight request_in_progress
Example
{
"error": {
"code": "same_plan"
}
}

payload_too_large: the body is over 64 KiB (the bulk import: 4 MiB).

Media typeapplication/json
object
error
required
object
code
required
string
message
required

English, for logs; may change.

string
params

Values for a localized message, e.g. {"field": "expires_in", "min": 60, "max": 604800}. Absent when the error has none.

object
key
additional properties
any
error
required
object
code
Allowed values: payload_too_large
Example
{
"error": {
"code": "payload_too_large"
}
}

no_payable_route: no enabled network with a Subscriptions contract and ERC-20 token can settle the new plan with these splits (params.reason payee_address with payees[] and chains[] when the payees’ addresses are why, as for orders). payee_blocked: a split address failed screening, as for orders. idempotency_key_reused.

Media typeapplication/json
object
error
required
object
code
required
string
message
required

English, for logs; may change.

string
params

Values for a localized message, e.g. {"field": "expires_in", "min": 60, "max": 604800}. Absent when the error has none.

object
key
additional properties
any
error
required
object
code
Allowed values: no_payable_route payee_blocked idempotency_key_reused
Example
{
"error": {
"code": "no_payable_route"
}
}

chain_unavailable: none of the networks that could pay a split address could be reached to screen it. Nothing is recorded (not replayed for the Idempotency-Key): retry later.

Media typeapplication/json
object
error
required
object
code
required
string
message
required

English, for logs; may change.

string
params

Values for a localized message, e.g. {"field": "expires_in", "min": 60, "max": 604800}. Absent when the error has none.

object
key
additional properties
any
error
required
object
code
Allowed values: chain_unavailable
Example
{
"error": {
"code": "chain_unavailable"
}
}