Change a subscription's plan (upgrade or downgrade)
const url = 'https://pay.example.com/v1/subscriptions/2489E9AD-2EE2-8E00-8EC9-32D5F69181C0/change_plan';const options = { method: 'POST', headers: { 'Idempotency-Key': 'example', Authorization: 'Bearer <token>', 'Content-Type': 'application/json' }, body: '{"plan_id":"8a1c2e40-7d3b-4b8f-a0e6-5f9d3c2b1a07"}'};
try { const response = await fetch(url, options); const data = await response.json(); console.log(data);} catch (error) { console.error(error);}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.
Authorizations
Section titled “Authorizations”Parameters
Section titled “Parameters”Path Parameters
Section titled “Path Parameters”A UUID (400 invalid_request, params.field: id, otherwise).
Header Parameters
Section titled “Header Parameters”Any unique string per logical request (a UUID); see the introduction.
Request Bodyrequired
Section titled “Request Bodyrequired”object
An active plan other than the current one.
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
The payee’s reference (alternative to payee_id). The payee must be active.
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.
With address: the recipient’s name, shown in the console and statements (default: the address; a later name replaces it).
For ratio: share of what the fixed members leave, in basis points; the ratio members sum to 10000.
For fixed: an amount in the order’s currency (the plan’s for subscriptions).
Accepted token symbols (default: the new plan’s).
Default: the old subscription’s.
Default: the old subscription’s.
Default: the old subscription’s.
Seconds the link stays usable; never past 15 minutes before effective_at.
Example
{ "plan_id": "8a1c2e40-7d3b-4b8f-a0e6-5f9d3c2b1a07"}Responses
Section titled “Responses”The new subscription (incomplete, replaces the old one) with plan_change
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
false for a test subscription (created with a test key).
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.
API answers only: the subscription link (<public_url>/pay/sub/{id}).
The network paid on (null while incomplete).
The chain a record is on: its id (chain_id as well, unchanged), CAIP-2 identifier and family.
object
eip155:<id>, tron:0x2b6653dc, solana:<genesis hash prefix>.
Chain family: decides the address and transaction id forms, and the wallets that can pay.
Token symbol.
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.
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.
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.
Token base units.
Start of period 0 (after the trial).
0-based index of the last period charged.
Of the last failed charge: balance, allowance, or the revert reason.
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).
Resolved on the paid chain once the payer subscribes (empty while incomplete).
object
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.
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.
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.
Token amount in base units (integer string; 1 USDC = “1000000”).
As given (null when none).
The subscription this one replaces (a plan change’s new subscription).
The subscription an applied plan change moved this one to (event subscription.replaced).
object
The subscription being replaced.
The new subscription’s first period starts (the old one’s next period boundary).
The new subscription’s link stays usable until then.
Why it was canceled: a newer change, the new subscription canceled, the old one ended.
Only in pending_plan_change of GET /v1/subscriptions/{id}: where the payer confirms (the new subscription’s link).
The change_plan answer, and events subscription.plan_change_pending / _expired / _canceled (on the old subscription): the change.
object
The subscription being replaced.
The new subscription’s first period starts (the old one’s next period boundary).
The new subscription’s link stays usable until then.
Why it was canceled: a newer change, the new subscription canceled, the old one ended.
Only in pending_plan_change of GET /v1/subscriptions/{id}: where the payer confirms (the new subscription’s link).
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
Token amount in base units (integer string; 1 USDC = “1000000”).
balance, allowance, or the revert reason.
Events with a failed charge: the next attempt (null: none).
Event subscription.paused: the status before.
Events: subscription.plan_changed — the replaced subscription {id, plan_id, plan_name};
subscription.payment_method_changed — the previous method {chain_id, token, payer}.
object
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.
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.
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.
Event subscription.payment_method_changed: the new method (token and chain_id are also the subscription’s own).
object
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.
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.
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.
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
Events subscription.plan_changed and subscription.replaced: the boundary the new plan starts at.
Event subscription.canceled: subscription_ended (a plan change’s new subscription whose old one ended
first, with before_activation).
Event subscription.canceled: the subscription was canceled before its on-chain subscription was confirmed (it never got subscription.activated).
Event subscription.allowance_low: what the allowance leaves after the pending charge.
Event subscription.allowance_low: what the remaining periods need.
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.
object
object
English, for logs; may change.
Values for a localized message, e.g. {"field": "expires_in", "min": 60, "max": 604800}. Absent when the error has none.
object
object
Example
{ "error": { "code": "invalid_request" }}unauthorized: no Authorization: Bearer header, or an unknown or revoked key.
object
object
English, for logs; may change.
Values for a localized message, e.g. {"field": "expires_in", "min": 60, "max": 604800}. Absent when the error has none.
object
object
Example
{ "error": { "code": "unauthorized" }}insufficient_scope: the key lacks the operation’s scope.
object
object
English, for logs; may change.
Values for a localized message, e.g. {"field": "expires_in", "min": 60, "max": 604800}. Absent when the error has none.
object
object
Example
{ "error": { "code": "insufficient_scope" }}not_found (params.what: order, subscription, entry): unknown, or another mode’s.
object
object
English, for logs; may change.
Values for a localized message, e.g. {"field": "expires_in", "min": 60, "max": 604800}. Absent when the error has none.
object
object
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.
object
object
English, for logs; may change.
Values for a localized message, e.g. {"field": "expires_in", "min": 60, "max": 604800}. Absent when the error has none.
object
object
Example
{ "error": { "code": "same_plan" }}payload_too_large: the body is over 64 KiB (the bulk import: 4 MiB).
object
object
English, for logs; may change.
Values for a localized message, e.g. {"field": "expires_in", "min": 60, "max": 604800}. Absent when the error has none.
object
object
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.
object
object
English, for logs; may change.
Values for a localized message, e.g. {"field": "expires_in", "min": 60, "max": 604800}. Absent when the error has none.
object
object
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.
object
object
English, for logs; may change.
Values for a localized message, e.g. {"field": "expires_in", "min": 60, "max": 604800}. Absent when the error has none.
object
object
Example
{ "error": { "code": "chain_unavailable" }}