Plans
A plan is a reusable price: an amount, a billing frequency, and a failure policy. Use one when several customers get the same offer; otherwise price the subscription inline.
Create a plan
TypeScript
const plan = await vectapay.subscriptions.createPlan({
code: "starter-monthly",
name: "Starter",
billingInterval: "monthly",
intervalCount: 1,
amount: 2500, // KES 2,500.00
trialPeriodDays: 7,
gracePeriodDays: 2,
retryOffsetHours: [24, 48, 72],
status: "active",
});The SDK method names map one-to-one in the other languages (create_plan in Python, CreatePlanAsync in C#).
| Field | Required | Notes |
|---|---|---|
code | Yes | Stable identifier, unique per business. Trimmed, lowercased, whitespace becomes - ("Starter Monthly" → starter-monthly). Max 60 chars. |
name | Yes | Max 160 chars. |
billingInterval | Yes | daily, weekly, monthly, yearly. |
intervalCount | No | Units per period, 1–365. Default 1. |
amount | Yes | Shillings, at least 1, max two decimals. |
currency | No | Always KES; only KES is supported for subscriptions. |
trialPeriodDays | No | 0–365. 0 and null both mean no trial. |
gracePeriodDays | No | 0–365. Recovery window after a failure. |
retryOffsetHours | No | 1–10 entries, each 1–2160 hours. Default [24, 48, 72]. |
status | No | Default draft. Only active plans can be attached. |
allowPause, allowCustomerCancel | No | Default true. Customer-portal permissions only (allowPause also gates portal resume); they never restrict the SDK. |
description | No | Max 800 chars. |
metadata | No | Free-form object. |
Status
A new plan is draft and cannot be subscribed to. Set it active with updatePlan(id, { status: "active" }).
archived means “stop selling”; existing subscriptions keep billing. The API does not enforce a
workflow; draft → active → archived is a convention.
Billing frequency
billingInterval is the unit; intervalCount is how many units make one period.
| Bill | billingInterval | intervalCount |
|---|---|---|
| Every two weeks | weekly | 2 |
| Monthly | monthly | 1 |
| Quarterly | monthly | 3 |
| Every six months | monthly | 6 |
| Yearly | yearly | 1 |
A subscription bills on its start day. Anchors on the 29th–31st clamp to the month’s last day, then return to the anchor (31st → 28 Feb → 31 Mar). Yearly billing clamps 29 Feb to 28 Feb in non-leap years.
Trials
A subscription on a plan with a trial starts trialing, pays nothing, and first charges at trialEndsAt.
When creating a subscription you can override the trial: omit trialPeriodDays to use the plan’s, or send
0 to skip it. No trial is ever added unless the plan or the subscription states one.
Don’t shorten a trial with initiateCharge(). It charges immediately and ends the trial.
Retry policy and grace
A failed charge puts the subscription in past_due. Both settings count from the first failure.
retryOffsetHours: retry times after the first failure.[24, 48, 72]means retries at +24h, +48h, and +72h, not gaps between attempts. The number of retries is the number of offsets.gracePeriodDays: the recovery window closes atfailure + max(last retry offset, gracePeriodDays × 24h).
A short grace never cancels a retry. With [24, 48, 72] and a 2-day grace, the window is 3 days.
Events: charge_failed + dunning_started on first failure, retry_scheduled per retry,
dunning_exhausted when none remain, expired when the window closes.
The default [24, 48, 72] is too slow for daily or weekly billing. Set offsets shorter than the period:
| Frequency | Offsets |
|---|---|
| Daily | [4, 8, 12] |
| Weekly | [12, 24, 48] |
| Monthly or longer | [24, 48, 72] |
Inline subscriptions have no plan, so they fall back to these same values by frequency.
Editing a plan
updatePlan() changes the plan only. Existing subscriptions keep their copied price and frequency;
archiving doesn’t cancel anyone. The exception is retry policy: it is read from the plan at failure
time, so editing retryOffsetHours or gracePeriodDays affects existing subscriptions on their next failure.
To reprice a subscription, use change plan.
Listing plans
listPlans() returns active plans only by default, so new drafts are easy to miss.
TypeScript
const active = await vectapay.subscriptions.listPlans();
const all = await vectapay.subscriptions.listPlans({ includeAll: true });
const drafts = await vectapay.subscriptions.listPlans({ status: "draft" }); // status wins over includeAllResults are ordered by status, then name, then creation date (newest first).
When not to use a plan
Send amount, billingInterval, and intervalCount (all required, no default) directly on the
subscription for per-customer prices, grandfathered imports, or one-offs. Trade-offs:
planId,planCode, andplanNamearenull.allowPauseandallowCustomerCanceldefault totrue.- No plan-level trial or grace; retries use the frequency defaults above.
If more than a handful of customers share the price, make a plan.