Skip to Content
SubscriptionsLifecycle & Changes

Lifecycle

An action that doesn’t fit the current status is rejected with a 400. One that is already satisfied returns a no-op result with a message. Nothing is half-applied. All actions accept an idempotencyKey. On pause, cancel, and change plan, reason is optional (max 255 chars).

Statuses and transitions

StatusMeaningCharges?Can move to
trialingAccess before the first chargeAt trialEndsAtactive, past_due, canceled, expired
activePeriod paid, or first charge pendingAt nextBillingAtpast_due, paused, canceled, expired
past_dueA charge failed; recovery runningOn the retry scheduleactive, paused, canceled, expired
pausedBilling stoppedNoactive, canceled, expired
canceledCancelled now or at period endNoTerminal
expiredRecovery window closed unpaidNoTerminal
draftReserved; the API never creates oneNotrialing, active, canceled

canceled and expired are final. Late provider callbacks and late Ratiba debits are recorded but never reopen a subscription. For a returning customer, create a new one.

A trialing subscription cannot be paused (no trialing → paused edge). Cancel the trial, or let it fail into past_due, where pause is allowed.

Actions

ActionAllowed fromEffectWebhook
Pauseactive, past_dueStops billing, voids pending attemptssubscription.paused
ResumepausedRestarts billingsubscription.resumed
Cancel nowtrialing, active, past_due, pausedFinal canceled, voids attemptssubscription.canceled
Cancel at period endactive, trialing with a nextBillingAtKeeps billing until thensubscription.canceled twice
Change planactive, trialing, past_due, pausedNew price at next boundarysubscription.plan_changed (twice when deferred)
Change billing dateOpen, with a nextBillingAtMoves next charge, re-anchorssubscription.billing_date_changed
Schedule / clear endOpenEnds on a date via hourly sweepsubscription.end_scheduled / end_cleared, then canceled when it fires
Retry chargepast_dueRetries the overdue periodsubscription.retry_scheduled
Initiate chargetrialing, active, past_dueCharges nowsubscription.retry_scheduled
Standing orderOpenRegisters a Ratiba mandateNone on enable; subscription.standing_order_rejected if it reverts

Every action appears in activity() and audit(). Enabling a standing order is the only one with no webhook.

Pause and resume

await vectapay.subscriptions.pause(subscriptionId, { reason: "Customer requested a break until January", idempotencyKey: "pause-2026-11-16", }); await vectapay.subscriptions.resume(subscriptionId, { idempotencyKey: "resume-2027-01-05" });

Pausing stores the old billing date, clears nextBillingAt, and voids pending and in-flight attempts. Whether the customer keeps access is your decision. A payment that still lands is recorded (as a charge_succeeded with attributedToPeriod: false) but never un-pauses the subscription.

Resuming restores the paid time that was left (20 days left at pause means 20 days from resume). If the billing date had already passed, there is nothing to restore and the next charge is due 30 seconds after resume, so the next scheduler run (within five minutes) sends the prompt. A subscription paused while past_due resumes as active with the same charge; if it fails, it returns to past_due.

Pause is refused while cancelAtPeriodEnd is set, and there is no way to undo cancel-at-period-end. Resuming an active subscription is a no-op. Any other status except paused is rejected with a 400: recover past_due through a successful charge, and let trials run.

Cancel now or at period end

// Terminal; access ends now. await vectapay.subscriptions.cancel(subscriptionId, { reason: "Customer closed the account" }); // Let the paid period finish, then stop. await vectapay.subscriptions.cancel(subscriptionId, { cancelAtPeriodEnd: true, reason: "Customer is not renewing", });

Now: status canceled, endedAt = now, nextBillingAt cleared, pending attempts voided, one subscription.canceled.

At period end (active or trialing with a nextBillingAt, once only): sets cancelAtPeriodEnd: true, moves nextBillingAt into endedAt, voids pending attempts, and dispatches subscription.canceled while status is still active or trialing. The hourly sweep later flips it to canceled and dispatches a second subscription.canceled. The boundary charge never runs.

In your handler, read data.status rather than assuming canceled, and dedupe the two deliveries on data.subscriptionId plus the state you care about (the event IDs differ).

cancelAtPeriodEnd also blocks pause and retries, and in practice initiateCharge() too, since the cancel voids the pending attempt it would act on. Cancelling now from a period-end state finalises immediately.

Change plan

const result = await vectapay.subscriptions.changePlan(subscriptionId, { targetPlanId: newPlanId, reason: "Customer upgraded to Growth", });

A plan change never prorates or credits. The old price stands until the period ends; then the new price, frequency, and plan apply.

  • The target plan must be active, in the same currency, and different from the current one.
  • Standing orders are refused: the mandate amount is fixed with Safaricom. Re-register at the new price.
  • With no nextBillingAt (for example, paused) the change applies immediately.
  • The change is stored as pending and subscription.plan_changed is sent with applied: false. Within five minutes of the boundary the scheduler applies it (swaps the plan fields, voids pending attempts, schedules one at the new price) and sends subscription.plan_changed again with applied: true. The boundary charge is held until then, so it is charged at the new price, up to five minutes late. If a charge is processing at the boundary, the change waits for the next run.

result.message says whether it was deferred (Plan will change … on YYYY-MM-DD) or immediate (the first webhook then already has applied: true).

Change billing date

await vectapay.subscriptions.changeBillingDate(subscriptionId, { newDate: "2026-12-01", });

Moves the next charge and re-anchors every renewal to the new day of the month. The charge is due at 00:00 UTC (03:00 Nairobi) on the new date.

  • newDate is YYYY-MM-DD, in the future by UTC day, and within 30 days of the current nextBillingAt in either direction.
  • The subscription needs a nextBillingAt, must be open, and the date must fall before any scheduled end.
  • Standing orders are refused; the date belongs to the mandate.

The pending attempt is voided and rescheduled. There is no proration: earlier charges the full price sooner, later gives free days.

Schedule an end date

scheduleEnd() takes a future date up to two years out and stores it in endedAt. clearEnd() removes it while the subscription is open.

await vectapay.subscriptions.scheduleEnd(subscriptionId, { endAt: "2027-03-31" });

On the first hourly sweep after midnight UTC on that date, the subscription becomes canceled, nextBillingAt is cleared, and subscription.canceled is sent with eventPayload: { cancelAtPeriodEnd: false, effectiveAt }. The customer gets the usual end-of-service email.

Billing stops at the end date regardless of what is in flight: attempts queued for that date or later are voided, renewals that settle earlier keep endedAt (the next boundary is never charged), and an attempt reaching the worker after the sweep is voided.

clearEnd() resumes billing from the stored nextBillingAt; if that has passed, the catch-up sweep queues the missed charge within the hour. It is refused while cancelAtPeriodEnd is true. scheduleEnd() sends subscription.end_scheduled and clearEnd() sends subscription.end_cleared.

Reading what happened

activity() returns the subscription, recent events, and recent attempts with failure codes. audit() adds the actor and outcome for actions taken by people.

Last updated on