Recurring payments
A subscription is an agreement to charge a customer's card again and again. securepayAPI keeps the card, the schedule, the retries and the lifecycle; your server never sees card data and never runs a billing job for a fixed-price plan.
Three objects, all under your secret key (Authorization: Bearer sp_secret_…):
| Object | What it is | Where |
|---|---|---|
| Plan | The product: price (or a price cap), currency, interval, consent terms | /api/v1/subscription-plans |
Payment Intent with a subscription block | The customer's first charge and consent, collected in the widget | /api/v1/payment-intents |
| Agreement (the subscription itself) | What the platform bills from then on; read, bill, pause, cancel | /api/v1/subscriptions |
Every call takes an optional mode ("live", the default, or "sandbox"), exactly like a Payment Intent. Plans and agreements live in one cabinet or the other; a sandbox plan cannot be named by a live intent.
your server ──POST /api/v1/subscription-plans──▶ plan "monthly-gold" (once)
│
├─ POST /api/v1/payment-intents { amount, subscription: { planExternalReference: "monthly-gold", … } }
│
browser ──widget: card + consent checkbox──▶ success { subscription: { status: "pending_activation" } }
│
your server ──GET /api/v1/subscriptions/membership-42──▶ status "active" → grant access
│
platform ──bills every period──▶ webhooks subscription.renewal_paid / … ──▶ your server1. Create a plan
A plan is immutable once created (you add versions to change it, see below). Create it once, then name it from every intent that sells it.
curl https://checkout.securepayapi.com/api/v1/subscription-plans \
-H "Authorization: Bearer sp_secret_…" \
-H "Content-Type: application/json" \
-d '{
"externalReference": "monthly-gold",
"name": "Gold",
"amountMode": "fixed",
"amount": "19.99",
"currency": "USD",
"intervalUnit": "month",
"intervalCount": 1,
"termsVersion": "2026-10-01",
"termsHash": "5d48345db32747eed3f5666e43c946652760795f35d09d81c4e0f6f29c353ed3"
}'| Field | Required | Contract |
|---|---|---|
externalReference | yes | Your id for the plan, 1–255 chars. |
name | yes | Display name, 1–255 chars. |
amountMode | yes | "fixed" or "variable" (see Fixed and variable plans). |
amount | fixed plans | Exact positive decimal string, e.g. "19.99". Not allowed on a variable plan. |
maximumAmount | variable plans | The most a single period may charge, decimal string. Not allowed on a fixed plan. |
currency | yes | "USD". |
intervalUnit, intervalCount | yes | "day", "week", "month" or "year", and how many of them per period (1 month, 3 months, …), 1–365. |
termsVersion | yes | Your label for the consent terms, 1–64 chars. |
termsHash | yes | Lowercase SHA-256 hex (64 chars) of the exact consent text you will show. |
idempotencyKey | no | A UUID, echoed in the answer. It has no effect on plan creation, which is idempotent on externalReference plus the plan's facts. |
mode | no | "live" (default) or "sandbox". |
Money is always a decimal string here ("19.99"), not minor units — only the Payment Intent uses cents (1999). The intent that sells this plan must carry the same amount: 1999 for "19.99".
Sending the same externalReference again is accepted only when every fact — name included — equals the plan's original facts (you get the existing plan back, with created: false). A changed fact fails, and at present it fails as 502 upstream_error rather than a clean 409; so does an amount that is not a positive decimal, or amount / maximumAmount sent for the wrong amountMode. Treat a 502 on plan creation as "check the request", not only as "retry". To change a plan, add a version:
curl https://checkout.securepayapi.com/api/v1/subscription-plans/versions \
-H "Authorization: Bearer sp_secret_…" \
-H "Content-Type: application/json" \
-d '{ "externalReference": "monthly-gold", "expectedVersion": 1,
"amountMode": "fixed", "amount": "24.99",
"currency": "USD", "intervalUnit": "month", "intervalCount": 1,
"termsVersion": "2027-01-01", "termsHash": "<sha256 of the new terms text>" }'expectedVersion is required: the plan's current version number as you last read it (currentVersion.version from GET …?externalReference=, 1 for a plan that was never versioned). The version is appended only if the plan is still at that number — if someone added a version in between, the call is refused with 409 and you re-read the plan first. Every version must carry a termsVersion this plan has never used — a new price is new terms, so write a new consent text, hash it and give it a new label; reusing a termsVersion is 409, as is a version that changes nothing. Existing agreements keep the version they consented to; new intents must send the current one, so stop using intents created before the change.
POST /api/v1/subscription-plans/archive stops new agreements on a plan (existing ones keep billing); …/reactivate allows them again. Both take { externalReference, idempotencyKey?, mode? }.
Read plans back with GET /api/v1/subscription-plans?externalReference=… (one plan, with its versions newest first, up to 100) or ?status=active&limit=25&cursor=… (a page: { items, nextCursor }).
The consent text and its hash
The customer must read and tick the exact terms you hashed. Write the text once, hash it, and keep both:
const { createHash } = require("node:crypto");
const termsText = "I authorize securepayAPI to charge my card USD 19.99 every month " +
"starting on the date shown, until I cancel.";
const termsHash = createHash("sha256").update(termsText, "utf8").digest("hex");The plan stores termsVersion + termsHash; the intent sends the same two plus termsText, and the widget shows termsText to the customer. Two checks keep what the customer sees equal to what they agree to, at two moments:
- when you create the intent —
termsTextmust hash to thetermsHashin the same request, or the intent is refused (subscription_terms_hash_mismatch); - when the customer pays — that version and hash must be the plan's current ones, or the payment is refused in the widget.
The plan itself is not read at creation: a wrong plan reference, outdated terms or a wrong amount give a normal 200 intent that fails only at payment. Run a sandbox payment after every plan change.
2. The first charge: a Payment Intent with subscription
Sell the plan by creating an intent that names it. The customer pays the first period in the widget and ticks the consent box; nothing else changes in your integration.
curl https://checkout.securepayapi.com/api/v1/payment-intents \
-H "Authorization: Bearer sp_secret_…" \
-H "Content-Type: application/json" \
-d '{
"amount": 1999,
"currency": "USD",
"reference": "order-9001",
"subscription": {
"planExternalReference": "monthly-gold",
"shopperExternalReference": "cust_88213",
"subscriptionExternalReference": "membership-42",
"termsVersion": "2026-10-01",
"termsText": "I authorize securepayAPI to charge my card USD 19.99 every month starting on the date shown, until I cancel.",
"termsHash": "5d48345db32747eed3f5666e43c946652760795f35d09d81c4e0f6f29c353ed3",
"billingAnchor": "2026-12-03T12:00:00-05:00",
"billingTimezone": "America/New_York"
}
}'Every field of the block is specified in Payment Intents → Recurring payments and the API reference. The rules that matter for the money:
amountmust equal the plan's amount on a fixed plan (1999↔"19.99"). On a variable plan it may be anything above zero and up tomaximumAmount. A mismatch is refused when the customer pays, with a clear message in the widget.billingAnchoris when recurring billing starts — the first renewal. The customer pays today; the next charge happens at the anchor, and every interval after it. The anchor must be at least an hour ahead when you create the intent and still in the future when the customer pays (an intent lives 7 days — give it room).- Cards only. Apple Pay and Google Pay are not offered on a subscription intent; the email is required (renewal notices and receipts go there).
subscriptionExternalReferenceis your id for the agreement. Store it with the customer: it is the key for every call below. Use a new one for every agreement: once a setup payment for it was captured, another intent carrying it is refused when the customer pays.
Activation
success carries the agreement reference:
{ "intentId": "k3m9q2x7v1b8n4c6d0f5g7h2", "status": "succeeded", "reference": "LU…",
"subscription": { "status": "pending_activation", "externalReference": "membership-42" } }The first charge is captured, but the agreement goes live only once the platform has confirmed the first payment's authentication on its side — normally seconds later. Do not grant access on pending_activation alone. Read the agreement:
curl "https://checkout.securepayapi.com/api/v1/subscriptions/membership-42" \
-H "Authorization: Bearer sp_secret_…"and grant access when status is "active". There is deliberately no subscription.activated webhook — poll this read a few times after success.
An agreement activates only when the first payment was authenticated by the issuer with 3-D Secure (liability shifted). If the issuer did not authenticate the card, the charge was still captured but the agreement stays pending_setup. If it is still pending_setup after a few minutes, treat the setup as not completed: the customer paid one period and nothing will be billed again — fulfil that period as a one-off or refund it, and ask for another card. Nothing expires such an agreement on its own: cancel it with POST /api/v1/subscriptions/cancel (a pending_setup agreement ends at once) before you set the customer up again under a new subscriptionExternalReference.
Fixed and variable plans
Fixed (amountMode: "fixed") | Variable (amountMode: "variable") | |
|---|---|---|
| Price | amount, the same every period | A cap, maximumAmount; the real amount is yours per period |
| First charge | Must equal amount | Any amount > 0 and ≤ maximumAmount |
| Renewals | Billed by the platform at nextBillingAt, nothing to do | You submit each period's amount with POST /api/v1/subscriptions/cycles; nothing is charged until you do |
| Typical use | Memberships, SaaS seats | Usage-based billing, metered plans, promo pricing, free periods |
A variable plan and its first charge
The plan names the cap, not a price; the intent names the first amount:
curl https://checkout.securepayapi.com/api/v1/subscription-plans \
-H "Authorization: Bearer sp_secret_…" \
-H "Content-Type: application/json" \
-d '{
"externalReference": "usage-pro",
"name": "Pro (metered)",
"amountMode": "variable",
"maximumAmount": "99.00",
"currency": "USD",
"intervalUnit": "month",
"intervalCount": 1,
"termsVersion": "2026-10-01",
"termsHash": "<sha256 of: I authorize securepayAPI to charge my card up to USD 99.00 every month …>"
}'curl https://checkout.securepayapi.com/api/v1/payment-intents \
-H "Authorization: Bearer sp_secret_…" \
-H "Content-Type: application/json" \
-d '{
"amount": 100,
"currency": "USD",
"reference": "order-9002",
"subscription": {
"planExternalReference": "usage-pro",
"shopperExternalReference": "cust_88213",
"subscriptionExternalReference": "usage-42",
"termsVersion": "2026-10-01",
"termsText": "I authorize securepayAPI to charge my card up to USD 99.00 every month for my usage, starting on the date shown, until I cancel.",
"termsHash": "<sha256 of termsText>",
"billingAnchor": "2026-12-01T00:00:00-05:00",
"billingTimezone": "America/New_York"
}
}'amount: 100 ($1.00) is accepted because it is above zero and below "99.00". From billingAnchor on, every period is billed only by your POST /api/v1/subscriptions/cycles call below ("99.00", "12.34", "0" — whatever that period is worth, never above the cap).
Billing a variable period
When the agreement is due (nextBillingAt has passed), submit the amount for that period. The call schedules the charge and answers at once (status: "scheduled"); the platform charges the stored card shortly afterwards, tells you by webhook, and moves the schedule one interval forward once that charge is paid:
curl https://checkout.securepayapi.com/api/v1/subscriptions/cycles \
-H "Authorization: Bearer sp_secret_…" \
-H "Content-Type: application/json" \
-d '{ "externalReference": "membership-42", "amount": "5.99",
"idempotencyKey": "6f1c2a0e-5b1d-4c0a-9d8e-3b2a1c0d9e8f" }'amountis an exact non-negative decimal string in the plan's currency, at most 18 decimal places, never abovemaximumAmount."amount": "0"closes the period without a charge: the cycle is recorded asskipped, the schedule advances one interval, you receivesubscription.renewal_skipped. No card is touched.- Not sending the request does not mean zero. The period stays due and the schedule does not move until you submit something — no charge, no webhook, no error. If you missed several periods, each call bills the oldest one and the next is due at once: one call per missed period (
"0"skips one). - The call is accepted only once the period is due: before
nextBillingAtit is409(subscription variable-price period is not due). - The agreement must be
active, due, not cancelled, with an active card credential — otherwise409with the reason. An amount abovemaximumAmountis409too, and a variable cycle is refused on a fixed plan. - Do not read the answer as "paid": wait for
subscription.renewal_paid(or read the agreement'scycles) before extending access. - The
idempotencyKeyis required here and owns the submitted facts permanently: the same key with the same amount returns the original cycle, the same key with a different amount is409, and a different key for a period that already has a cycle is409. Generate the key when you decide the amount, store it, and reuse it on every retry — a retry under a new key would be refused, and you could not tell whether the first call billed.
A positive amount enters the same path as a fixed renewal: the same retries, the same subscription.renewal_paid / renewal_retry_scheduled / renewal_past_due webhooks.
Trials, introductory prices, free periods
The platform never stores a card without a charge — the first payment is what creates the agreement, and it must be above zero. Within that rule:
| You want | Do this |
|---|---|
| First period at the full price, the next charge later ("30 days for the price of one", annual plans billed in advance) | Fixed plan; set billingAnchor to when the second charge should happen. |
| Introductory price, e.g. $1 for the first week, then $5.99 a month | Variable plan with maximumAmount: "5.99", intervalUnit: "month". Intent amount: 100, billingAnchor = now + 7 days. From then on submit "5.99" each month with /cycles. |
| A free month in the middle (pause billing without pausing the agreement) | Variable plan: submit "amount": "0" for that period. |
| Full price, but one period on the house | Fixed plan: let the renewal run and refund it. Pausing does not skip a period — a period that fell due during a pause is charged right after resume. (On a variable plan, submit "0".) |
| $0 trial / card check only | Not available: there is no zero-amount setup. Charge a nominal first amount instead. |
3. Reading an agreement
GET /api/v1/subscriptions/{externalReference}?mode=live
GET /api/v1/subscriptions?externalReference=…&mode=live (same thing)
GET /api/v1/subscriptions?status=past_due&limit=25&cursor=… (a page: { items, nextCursor })One agreement comes with its timeline: the last cycles, each with its attempts, and the lifecycle events.
{
"externalReference": "membership-42",
"environment": "production",
"status": "active",
"cancelAtPeriodEnd": false,
"billingAnchor": "2026-12-03T17:00:00.000Z",
"billingTimezone": "America/New_York",
"nextBillingAt": "2027-01-03T17:00:00.000Z",
"startedAt": "2026-11-03T14:12:09.000Z",
"pausedAt": null, "cancelledAt": null, "endedAt": null,
"shopperExternalReference": "cust_88213",
"customerContact": { "configured": true, "updatedAt": "2026-11-03T14:12:09.000Z" },
"plan": { "externalReference": "monthly-gold", "name": "Gold", "version": 1,
"amountMode": "fixed", "amount": "19.99", "maximumAmount": null,
"currency": "USD", "intervalUnit": "month", "intervalCount": 1,
"termsVersion": "2026-10-01", "termsHash": "5d48…3ed3" },
"paymentMethod": { "status": "active", "bin": "51716665", "lastFour": "5100",
"country": "US", "activatedAt": "…", "recoveryInProgress": false },
"recovery": { "eligible": false, "cycleStatus": "paid", "periodStart": "…", "periodEnd": "…",
"amount": "19.99", "currency": "USD", "attemptNumber": 1,
"attemptStatus": "authorised", "refusalCode": null, "retryAt": null },
"cycles": [ { "periodStart": "…", "periodEnd": "…", "billingAt": "…", "amount": "19.99",
"currency": "USD", "status": "paid", "paid": true, "attempts": [ … ] } ],
"events": [ { "type": "renewal_paid", "occurredAt": "…", "data": { … } } ]
}The read also carries createdAt / updatedAt, and each attempt in cycles[] is { attemptNumber, kind, status, paymentId, refusalCode, retryAt, submittedAt, completedAt, … }. The timeline is bounded: the last 100 cycles and 400 events. A page of agreements (the list form) returns them without cycles and events.
events[].type uses the timeline's own names, not the webhook names: no subscription. prefix (renewal_paid, renewal_retry_scheduled, subscription_paused, …), and it includes internal steps that have no webhook (setup_payment_captured, renewal_scheduled, …). Do not match webhook types against it.
Statuses
status | Meaning | What you do |
|---|---|---|
pending_setup | The setup has started but is not confirmed. The agreement appears as soon as the customer submits the card — before the charge — so this status alone does not mean anything was captured: confirm the intent. After a captured payment it means activation is not yet confirmed (or never will be, see Activation) | Confirm the intent; wait a few minutes; then treat as not set up |
active | Billing on schedule | Grant access |
past_due | A renewal was not paid: refused and being retried, refused with no retry left, or its outcome is unknown (the newest cycle reads outcome_unknown). It stays past_due until a retry succeeds or the customer gives a new card — with no further charge and no further event if you do nothing | Keep or restrict access per your policy; offer a card update when recovery.eligible is true; never ask for money while the newest cycle is outcome_unknown |
paused | You paused it: no claims, no retries | — |
cancelled | Ended — immediately, or at the period end that has now passed. cancelAtPeriodEnd: true with status active means a cancellation is scheduled | Revoke access when endedAt passes |
completed | Part of the status list, but no current flow ends an agreement this way (plans have no end date) | Do not wait for it |
paymentMethod.status is the stored card credential: pending (setup not confirmed), active, revoked (cancelled, or replaced), expired.
Cycle statuses: scheduled, processing, paid, retryable (refused, a retry is scheduled), failed (no more retries), outcome_unknown (the provider did not answer; never retried automatically — the platform waits for the provider's evidence, and pause or cancel answer 409 meanwhile), skipped (a zero variable period — or a pending period dropped by a cancellation).
Renewals and retries
A fixed renewal is attempted at nextBillingAt or shortly after: the platform first emails the customer an upcoming-renewal notice (30 days ahead for yearly plans, 7 for monthly, 3 for weekly, 12 hours for daily) and charges once that notice has gone out. If you change the customer's address with /contact just before a renewal, a fresh notice goes to the new address first.
Most declines are not retried. Only a refusal the issuer marks as temporary is retried — up to 4 attempts over 30 days, by default 1, 3 and 7 days apart, or at the delay the issuer's advice code asks for — and reported as subscription.renewal_retry_scheduled (nextRetryAt). Any other decline (a closed or blocked card, "do not retry") ends the period at the first attempt: subscription.renewal_past_due arrives without a retry before it, and the customer needs to give a new card. The agreement is past_due meanwhile; it returns to active when a retry succeeds (subscription.renewal_recovered) or when the customer gives a new card.
The customer receives email notices from the platform at the agreement's address: activation, upcoming renewal, a retry, past-due, a scheduled or final cancellation, and a receipt for every paid renewal. Each non-final notice carries a link where the customer can cancel online — at the period end or at once — through the same lifecycle as your API call, so you receive the same subscription.cancelled webhook either way. Change that address with POST /api/v1/subscriptions/contact { externalReference, customerEmail }.
4. Cancel, pause, resume
curl https://checkout.securepayapi.com/api/v1/subscriptions/cancel \
-H "Authorization: Bearer sp_secret_…" \
-H "Content-Type: application/json" \
-d '{ "externalReference": "membership-42", "atPeriodEnd": true }'
curl https://checkout.securepayapi.com/api/v1/subscriptions/pause \
-H "Authorization: Bearer sp_secret_…" -H "Content-Type: application/json" \
-d '{ "externalReference": "membership-42", "idempotencyKey": "0b6d1c62-4f0a-4a5e-9c1b-7a2d3e4f5061" }'
curl https://checkout.securepayapi.com/api/v1/subscriptions/resume \
-H "Authorization: Bearer sp_secret_…" -H "Content-Type: application/json" \
-d '{ "externalReference": "membership-42", "idempotencyKey": "7c1e9a40-2b3d-4e5f-8a9b-0c1d2e3f4a5b" }'Answer, for all three:
{ "externalReference": "membership-42", "status": "active", "cancelAtPeriodEnd": true,
"effectiveAt": "2027-01-03T17:00:00.000Z", "created": true,
"idempotencyKey": "3f6a2b1c-9d8e-4f70-a1b2-c3d4e5f60718" }| Call | Body | Effect |
|---|---|---|
POST /api/v1/subscriptions/cancel | externalReference, atPeriodEnd (default true), idempotencyKey?, mode? | atPeriodEnd: true: billing stops, access runs to the end of the paid period (cancelAtPeriodEnd: true, then cancelled with effectiveAt). false: ends now. A period-end cancellation also ends at once when the current period is unpaid — a retry is scheduled, or a variable cycle you submitted has not been charged yet — or when nextBillingAt has already passed: the answer is status: "cancelled" with effectiveAt at the start of that period (possibly in the past), and the pending cycle becomes skipped. Read status in the answer, do not assume. |
POST /api/v1/subscriptions/pause | externalReference, idempotencyKey?, mode? | No new charges, no retries, no upcoming-renewal notices. The unpaid cycle, if any, is kept; nextBillingAt does not move. Allowed from active or past_due (409 from pending_setup); pausing a paused agreement answers 200. |
POST /api/v1/subscriptions/resume | same | Billing resumes; the stored card credential is re-checked first (409 if it is no longer usable). The schedule is not shifted: a period that fell due during the pause is charged after the resume. Answers status: "past_due" instead of active when a period is still unpaid. |
All three answer { externalReference, status, cancelAtPeriodEnd, effectiveAt, created, idempotencyKey } and emit subscription.cancellation_scheduled / subscription.cancelled / subscription.paused / subscription.resumed. They are refused with 409 while a cycle is processing, has an unknown outcome, or a card replacement is in progress — the answer must never promise that an in-flight charge will not settle. Retry a little later.
idempotencyKey is optional: send your own UUID to make a retry safe (the same key repeats the same transition and answers created: false), or omit it and get a fresh one echoed back. Send your own whenever you may retry — a 502 can hide a transition that was applied. A replay with the same key sends the webhook again; deduplicate on your side. A key belongs to one action with one set of facts: reusing a cancel key with a different atPeriodEnd is an error (answered 502 upstream_error at present), while the same UUID may serve a pause and a later resume.
A pending_setup agreement is cancelled at once, whatever atPeriodEnd says. There is no call to undo a scheduled cancellation: once cancelAtPeriodEnd is true, the customer needs a new agreement after the period ends. Until then a variable plan cannot be billed through /cycles (409).
5. Replacing the card
When a renewal fails, the agreement is past_due; recovery.eligible is true while its newest period is unpaid (retryable or failed), and recovery.amount / recovery.currency say what is owed. After subscription.renewal_past_due this is the only way to collect that period — nothing is charged again otherwise. Create a Payment Intent for exactly that amount, in cents ("19.99" → 1999):
curl https://checkout.securepayapi.com/api/v1/payment-intents \
-H "Authorization: Bearer sp_secret_…" \
-H "Content-Type: application/json" \
-d '{
"amount": 1999,
"currency": "USD",
"reference": "membership-42-recovery-2027-02",
"subscription": {
"operation": "recoverPaymentMethod",
"subscriptionExternalReference": "membership-42",
"termsVersion": "2026-10-01",
"termsText": "I authorize securepayAPI to charge my card USD 19.99 every month starting on the date shown, until I cancel.",
"termsHash": "5d48345db32747eed3f5666e43c946652760795f35d09d81c4e0f6f29c353ed3"
}
}'No plan, shopper or anchor fields here — the agreement already has them. Send the terms the agreement was made under — plan.termsVersion and plan.termsHash from the agreement read, with their text — not the plan's newest version if the plan has changed since; other terms are refused when the customer pays. recovery.eligible is false while a cancellation at period end is scheduled or another card replacement is in progress. Send the customer to the widget: it collects the new card under the same rules (3-D Secure is always required here), pays the unpaid period, and the agreement returns to active — or stays paused if it was paused. You receive subscription.payment_method_recovered only — not renewal_recovered. While the customer is paying, the period is held for up to two hours: pause, cancel and a second replacement answer 409. If the new card is refused you receive subscription.payment_method_recovery_failed and can try again; an abandoned attempt sends nothing and simply frees the period again. Details in Payment Intents.
6. Webhooks
Agreements report through the same webhook endpoint, signed with the same secret. The events you will act on most:
| Event | When | What you do |
|---|---|---|
subscription.renewal_paid | A period was charged | Extend access by one period |
subscription.renewal_retry_scheduled | A charge was refused, a retry is planned (nextRetryAt) | Nothing to send; grace is your choice |
subscription.renewal_past_due | The period will not be retried: outcome refused / failed / action_required (retries exhausted, or a decline that is never retried) — or outcome_unknown | refused, failed, action_required: restrict access, offer a card update. outcome_unknown: the charge may have happened — do not ask for money and do not cancel; wait for a later event or read the agreement |
subscription.renewal_outcome_unknown | The provider reported a failed capture on the latest attempt; automatic retry stops | As outcome_unknown above |
subscription.renewal_recovery_scheduled | The provider proved the authorization went through although the attempt looked unpaid; the same attempt is resumed (not a new charge) | Wait for renewal_paid / renewal_recovered |
subscription.renewal_recovered | A retry paid the overdue period, or a resumed past_due agreement was charged | Restore access |
subscription.renewal_skipped | You submitted a zero variable period | — |
subscription.payment_method_recovered | A card replacement paid the unpaid period; the new card is on file | Restore access |
subscription.payment_method_recovery_failed | The new card was refused | Let the customer try another card |
subscription.paused, subscription.resumed | Your API call | Read the agreement after resumed: past_due means a period is outstanding |
subscription.cancellation_scheduled, subscription.cancelled | Your API call or the customer online (effectiveAt) | Keep access until effectiveAt; end it at cancelled |
subscription.plan_version_created, subscription.plan_archived, subscription.plan_reactivated | A plan changed | — |
No event is sent when an agreement is created or activated, when you change the contact address, or when you submit a positive variable amount.
Each agreement event carries id, type, subscriptionExternalReference, environment (a number: 0 live, 1 sandbox — unlike the API's "production" / "sandbox"), processorConfigId, occurredAt and merchantid (your account id on the platform). Renewal events add attemptNumber, outcome, paymentId, nextRetryAt and, when the worker produced them, refusalCode and retryReason; renewal_skipped adds amount, currency, periodStart, periodEnd instead; payment_method_* events add paymentId (and, on a failure, provider, providerReference, reason). Plan events carry planExternalReference (and version on plan_version_created) instead of an agreement reference. The agreement's status is present only on the lifecycle events (paused, resumed, cancellation scheduled, cancelled — which also carry effectiveAt and source: "merchant" for your API call, "customer" for a cancellation the customer made online) and on the payment_method_* events. A renewal event has no status: read the agreement. A paid renewal looks like this:
{
"id": "subscription:0:…:membership-42:1:subscription.renewal_paid",
"type": "subscription.renewal_paid",
"environment": 0,
"processorConfigId": "…",
"subscriptionExternalReference": "membership-42",
"attemptNumber": 1,
"outcome": "paid",
"paymentId": "sub_6b0e2f4c1a9d48e7b3c5f1a2d4e6b8c0",
"refusalCode": null,
"nextRetryAt": null,
"retryReason": "outcome_not_retryable",
"occurredAt": "2027-01-03T17:00:04.000Z",
"merchantid": "…"
}A renewal's paymentId is sub_ followed by 32 hex characters. A refused attempt reads, for example, "outcome": "refused", "refusalCode": "12", "nextRetryAt": "2027-01-04T17:00:04.000Z", "retryReason": "transient_refusal_12".
The amount of a paid renewal is the plan's amount (fixed) or what you submitted for that period (variable); read the agreement's cycles for the money and the dates.
Do not deduplicate renewal events on id alone. The id of a renewal event is built from the agreement, the attempt number and the type — not the period — so the first successful charge of every period arrives with the same id. A handler that drops "an id it has seen" would ignore every renewal after the first. Deduplicate on id together with paymentId (each charge has its own), or with occurredAt for events without a payment. When in doubt, read the agreement — it is authoritative.
Errors
The subscription endpoints use the same envelope as the rest of the API. Two types are specific to them:
type | Status | code | When |
|---|---|---|---|
invalid_request | 400 | rejected | The platform refused the request; message says why (a malformed amount, an invalid intervalCount or termsHash, an address it does not accept, a mode not enabled, …). Field-level codes (invalid_json, externalReference_invalid, mode_invalid, idempotencyKey_invalid, idempotencyKey_required on /cycles, expectedVersion_required / expectedVersion_invalid on /versions, atPeriodEnd_invalid, amount_invalid, …) are checked before the call. |
forbidden | 403 | not_enabled | A feature not enabled on the account (physical-order renewals). |
not_found | 404 | not_found | No plan or agreement with that reference in that cabinet. |
conflict | 409 | conflict | The state does not allow it: a cycle amount above the plan's maximum, a cycle already billed for that period, a stale expectedVersion or a reused termsVersion, a transition while a charge is in flight — message names the reason. |
server | 500 | internal_error | An unexpected error on our side. |
server | 502 | upstream_unavailable, upstream_error, credentials_unavailable, processor_unconfigured | The platform could not be reached or answered unexpectedly. Usually transient — but upstream_error is also what three bad requests currently produce: a plan replayed with changed facts, an unusable plan amount, and an idempotency key reused with different facts. Check the request before retrying; if it persists, contact support. |
server | 503 | subscriptions_disabled | Subscriptions are not enabled on this platform yet. Not retryable — contact support. |
An account on which the requested mode is not enabled yet (for example sandbox not switched on) is refused with 400 rejected and the message processor configuration is unavailable for this merchant — contact support to enable it.
Before going live
- Recurring billing is enabled per cabinet by securepayAPI after the account is ready for it (payout destination, limits, webhook endpoint). Build and test in sandbox first; a sandbox plan and agreement behave exactly like live ones without moving money.
- Store
subscriptionExternalReferencewith your customer, and for variable plans theidempotencyKeyof every cycle you submit. - Grant access on
status: "active"(read back), extend it onsubscription.renewal_paid, restrict it onsubscription.renewal_past_due. - Never mark the first payment as a subscription from the browser's
successalone — confirm the intent and read the agreement, as with any payment.