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
| Status | Meaning | Charges? | Can move to |
|---|---|---|---|
trialing | Access before the first charge | At trialEndsAt | active, past_due, canceled, expired |
active | Period paid, or first charge pending | At nextBillingAt | past_due, paused, canceled, expired |
past_due | A charge failed; recovery running | On the retry schedule | active, paused, canceled, expired |
paused | Billing stopped | No | active, canceled, expired |
canceled | Cancelled now or at period end | No | Terminal |
expired | Recovery window closed unpaid | No | Terminal |
draft | Reserved; the API never creates one | No | trialing, 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
| Action | Allowed from | Effect | Webhook |
|---|---|---|---|
| Pause | active, past_due | Stops billing, voids pending attempts | subscription.paused |
| Resume | paused | Restarts billing | subscription.resumed |
| Cancel now | trialing, active, past_due, paused | Final canceled, voids attempts | subscription.canceled |
| Cancel at period end | active, trialing with a nextBillingAt | Keeps billing until then | subscription.canceled twice |
| Change plan | active, trialing, past_due, paused | New price at next boundary | subscription.plan_changed (twice when deferred) |
| Change billing date | Open, with a nextBillingAt | Moves next charge, re-anchors | subscription.billing_date_changed |
| Schedule / clear end | Open | Ends on a date via hourly sweep | subscription.end_scheduled / end_cleared, then canceled when it fires |
| Retry charge | past_due | Retries the overdue period | subscription.retry_scheduled |
| Initiate charge | trialing, active, past_due | Charges now | subscription.retry_scheduled |
| Standing order | Open | Registers a Ratiba mandate | None 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
TypeScript
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
TypeScript
// 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
TypeScript
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_changedis sent withapplied: 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 sendssubscription.plan_changedagain withapplied: true. The boundary charge is held until then, so it is charged at the new price, up to five minutes late. If a charge isprocessingat 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
TypeScript
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.
newDateisYYYY-MM-DD, in the future by UTC day, and within 30 days of the currentnextBillingAtin 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.
TypeScript
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.