Skip to Content
SubscriptionsStanding Orders

Standing Orders

A standing order is an M-Pesa Ratiba mandate. The customer approves it once and Safaricom debits their M-Pesa account on a schedule until the mandate ends or they cancel it. VectaPay registers the mandate, records each debit Safaricom reports, and keeps the subscription in step. It does not decide when to debit and cannot charge the mandate itself.

It is the most hands-off mode for customers without a saved card, and the one with the least merchant control.

When it fits

Use it when the price is a fixed whole number of shillings (KES), the period is supported, and the customer pays by M-Pesa, has a phone on file, and keeps a balance. Otherwise use a payment request or a card. Cards have no whole-shilling or schedule limits and bill silently without needing an M-Pesa balance, so prefer them for online customers.

Requirements

enableStandingOrder() checks all of these before calling Safaricom:

  • An active M-Pesa provider account.
  • The customer has a phone number.
  • Currency is KES and the amount is whole shillings.
  • The billing period is supported.
  • The subscription is open, not already standing_order, and not automatic.

There is no API to remove automatic billing, so a subscription that captured a reusable card cannot switch to Ratiba. Decide before the first successful card charge.

Supported billing periods

Billing periodRatiba frequency
daily, 1Daily
weekly, 1Weekly
monthly, 1Monthly
monthly, 2Every two months
monthly, 3Quarterly
monthly, 6Every six months
yearly, 1Yearly

Anything else is rejected. Every-two-weeks (weekly, 2) is the usual casualty.

Turn one on

const result = await vectapay.subscriptions.enableStandingOrder(subscriptionId, { providerAccountId: "5d1f6b2a-1c3e-4a7b-9f8d-2e4c6a8b0d1f", // active M-Pesa account of your business idempotencyKey: "ratiba-enable-2026-11-16", }); console.log(result.message); // customer must approve on their phone (reference RTB…)

The RTB… reference is VectaPay’s handle for the mandate, not a Safaricom transaction ID.

Enabling:

  1. Registers the mandate with Safaricom, starting at nextBillingAt if it is in the future, otherwise now. The name is SUB- plus the first eight characters of the subscription ID (retried once with -2 if Safaricom reports it taken, code 1050).
  2. Sets chargeMode to standing_order and standingOrderStatus to pending_consent. Nothing is debited yet.
  3. Voids pending attempts so the scheduler sends no more prompts.
  4. Records standing_order_enabled in activity. No webhook is sent.

The mandate ends five years after it starts, with no automatic renewal and no expiry exposed by the API. Re-register before it lapses.

If the call errors after Safaricom accepted the mandate (the local write failed), the customer can still get the prompt while nothing tracks it. The logs carry ORPHAN STANDING ORDER with the CustomStoId; cancel it with Safaricom. A concurrent second enable for the same subscription is rejected instead of registering a second mandate.

standingOrderStatusMeaning
pending_consentPrompt sent, no definitive answer yet.
activeFirst debit succeeded; mandate is live.
rejectedDeclined, timed out, or rejected by Safaricom. History, not a live state.

The first successful occurrence sets active. From trialing or past_due it also activates the subscription (subscription.activated); from active only subscription.charge_succeeded is sent.

Rejection. Safaricom code 1032 (declined), 2001, or a cancellation with no code reverts immediately. A timeout code such as 1037 is ambiguous (the prompt may never have arrived, and a late approval could still land), so pending_consent stays.

Timeout. An hourly sweep reverts a pending mandate when:

now >= min(requestedAt + 48h, max(requestedAt + 2h, nextBillingAt + 30min))

That is between two hours and two days after the request, usually about 30 minutes after the next billing date.

On revert: chargeMode returns to customer_approval, standingOrderStatus becomes rejected, the mandate and Safaricom references are cleared, and a fresh pending charge is scheduled at nextBillingAt (or now), provided the subscription is open and not cancelling at period end. VectaPay keeps its internal request ID. The revert sends subscription.standing_order_rejected with failureReason.

A revert does not cancel the mandate at Safaricom. If the customer approves late, a debit whose request ID matches is re-linked automatically: the subscription goes back to standing_order and active. A debit that matches nothing is only logged, and Safaricom keeps debiting. If a customer says they approved a reverted mandate, check it and cancel it on the M-Pesa side if you don’t want it.

Price and date are fixed

The mandate fixes amount, start date, frequency, and end date.

  • Change plan and change billing date are refused.
  • Editing the plan’s price does nothing to the mandate or to existing subscriptions.

A price change needs a new mandate. There is no API to cancel or replace one; cancel it on the Safaricom side first. Settle plan pricing before enabling Ratiba on a cohort.

Each debit

Safaricom posts a callback per occurrence. VectaPay matches it by mandate reference, records an inbound M-Pesa payment, creates an attempt, and settles the period.

On success: the period advances from the scheduled boundary, not the callback time, so a late callback doesn’t walk the billing day forward. nextBillingAt becomes the next boundary, a first success sets active, and subscription.charge_succeeded carries amountVerified: true.

On failure: the occurrence enters past_due recovery with the usual grace window. VectaPay schedules no retry (Safaricom drives the schedule) and sends no dunning_exhausted. A later successful occurrence recovers the subscription; if none lands, grace expiry ends it.

Missing debit: if nothing is reported within about two hours of a billing date, the attempt fails with RATIBA_NO_OCCURRENCE and is flagged for manual review. This is usually a mandate cancelled on the phone or a Safaricom delivery failure. Check with the customer before assuming the money is lost.

Bad amount: a debit with an unreadable, zero, or short amount fails with AMOUNT_UNVERIFIED or UNDERPAID, the subscription goes past_due, no retry is scheduled, and no “payment failed” email is sent. The customer was debited, so check before telling them it failed.

Pause, cancel, and the mandate

Brief support staff on this before they touch a standing-order subscription.

  • Pause stops VectaPay’s scheduler, but Safaricom doesn’t know. A debit can still arrive; it is recorded and the subscription stays paused. Money can be taken while nothing is delivered.
  • Cancel moves the subscription to canceled and voids pending attempts, but does not cancel the mandate. Safaricom can keep debiting, and each debit is recorded against the cancelled subscription without reopening it.

There is no “disable standing order” endpoint. The only reliable way to stop debits is for the customer to cancel in their M-Pesa app, or for you to cancel with Safaricom. Cancel the mandate first, then the subscription. The other order keeps money moving.

Watching a mandate

FieldTells you
standingOrderReferenceVectaPay’s mandate handle. Cleared on revert.
standingOrderStatuspending_consent, active, or rejected.

Enablement is silent. A decline or timeout sends subscription.standing_order_rejected, and the first debit sends subscription.charge_succeeded and flips the status to active. Until one of those arrives, poll get() for standingOrderStatus. Activity also carries standing_order_enabled and, after a revert, charge_scheduled. Debits appear in the payments list as inbound M-Pesa payments with the mandate reference, for manual reconciliation.

Testing

There is no Ratiba sandbox. Enabling registers a real mandate on a real phone that Safaricom debits on its real schedule. Use your own number and a small amount, cancel the mandate on the phone afterwards, and never enable one on a customer you haven’t spoken to. See There is no test mode.

Last updated on