Skip to Content
SubscriptionsOverview

Subscriptions

Subscriptions charge a customer on a schedule. You define a plan, put a customer on it, and VectaPay collects each period and reports the outcome by webhook. For the dashboard walkthrough, see Recurring Payments.

The pieces

PieceWhat it is
PlanA reusable price: amount, billing frequency, trial, retry policy.
CustomerThe person being billed. Must exist first (dashboard → Customers).
Customer subscriptionOne customer on one price, with a status, next billing date, and charge mode.
Charge attemptOne attempt to collect one billing period.
Subscription eventAppend-only history, readable with vectapay.subscriptions.activity().
WebhookNotification for the events you need to act on.

A subscription copies the plan’s price, currency, and frequency at creation. Editing the plan later does not reprice existing subscriptions; use change plan.

How a period gets paid

chargeMode decides what the customer sees each cycle.

chargeModeEach periodCustomer doesSet by
customer_approvalM-Pesa prompt if the customer has a phone. Email only: the attempt waits for you to start a card checkout.Approves every periodDefault
automaticSaved card charged silentlyNothing, after the first card paymentA reusable card is captured
standing_orderSafaricom debits on the mandate’s scheduleApproves the mandate onceenableStandingOrder()

Start with customer_approval; it works without a saved card or mandate.

Without a saved card or a standing order, the customer approves every period. An ignored prompt fails the period and starts recovery; it is not retried forever.

A first subscription

This assumes the customer exists and the plan has no trial.

import { VectaPayClient } from "@vectapay/sdk"; const vectapay = new VectaPayClient({ apiKey: process.env.VECTAPAY_API_KEY! }); // Prices are in shillings: 2500 is KES 2,500. const plan = await vectapay.subscriptions.createPlan({ code: "starter-monthly", name: "Starter", billingInterval: "monthly", amount: 2500, status: "active", }); const result = await vectapay.subscriptions.create({ customerId: "9b2f0f6e-3f4a-4c1e-9d6e-6f1b2c3d4e5f", planId: plan.id, externalReference: "member_8842", idempotencyKey: "signup-member_8842", }); // Phone customers get the first prompt automatically. // Email-only customers need a checkout from your site: const charge = await vectapay.subscriptions.initiateCharge(result.subscription.id, { method: "card", email: "amina@example.com", returnUrl: "https://your-app.example.com/billing/return", }); if (charge.checkoutRedirectUrl) redirect(charge.checkoutRedirectUrl);

create returns as soon as the subscription is recorded. A phone customer’s prompt may already be on their phone, but that does not mean they paid. Settlement is the webhook.

Settle from webhooks

EventMeaning
subscription.createdSubscription exists; no money moved.
subscription.charge_succeededA period was paid (see Settling a charge).
subscription.charge_failedAn attempt failed. Read failureCode and retryAt.
subscription.dunning_started / retry_scheduled / dunning_exhaustedRecovery progress.
subscription.activatedA trial converted or a past-due subscription recovered.
subscription.paused / subscription.resumedBilling stopped or restarted.
subscription.plan_changedA plan change was requested (applied: false) or took effect (applied: true).
subscription.billing_date_changed, end_scheduled, end_clearedThe schedule was edited.
subscription.standing_order_rejectedA Ratiba mandate was declined or timed out; billing reverted to customer_approval.
subscription.canceledCancellation requested or took effect. Check data.status.
subscription.expiredRecovery window closed unpaid.

Never grant access from payment.succeeded. A payment can succeed while the subscription attempt fails (underpayment, wrong currency). The subscription.* event carries the period-level outcome.

Payload shapes are on Events.

Money

Plan prices are in shillings (amount: 2500 is KES 2,500.00). Everything the platform reports is a money object:

{ "amount": "250000", "currency": "KES", "formatted": "KSh 2,500.00" }

Display formatted. Use amount (integer minor units, as a string) only for reconciliation, and never divide it yourself.

Before you start

  • A provider account for each rail you use: M-Pesa for prompts and standing orders, Paystack for cards (dashboard → Providers).
  • A customer record with the Customer ID copied from the dashboard.
  • A webhook endpoint subscribed to the subscription.* events you handle. Without one you are polling activity().

There is no test mode for subscriptions

Every subscription is live and moves real money, even with a test key. Two ways to test:

  1. Handler: Developer → Webhooks → Send test event sends a signed event with environment: "test". See Testing Your Endpoint.
  2. End to end: use the smallest amount the rail accepts, subscribe your own phone or card, then cancel. Never use a customer’s number or a “test” plan with a real customer.

Where to go next

PageRead it when
PlansPricing, frequency, trials, retries
Customer subscriptionsCreating, listing, looking up
LifecyclePause, cancel, change plan or date
ChargingReconciling, dunning, payment pages
Standing ordersM-Pesa automatic debits
Last updated on