Receiving Events
You configure one URL and one signing secret, and every event type you tick in the subscription
list arrives at that URL. There is no per-event address. Use event.type to send each delivery to
its own code.
This page is the receiving side only: the list of types, a switch for each language, and what to do with the shapes that don’t fit the pattern. Signature verification and handling repeats are on Signatures & Idempotency; every payload is described on Events.
Where the list of event types comes from
Four places, and they agree:
- The dashboard checklist — Developer → Webhooks lists the twenty-five types a merchant endpoint can receive, split into Payments and Subscriptions.
- The SDK enum —
PlatformEventType(@vectapay/sdk,vectapay,com.vectapay.sdk.webhooks,VectaPay.Sdk). Compare againstPlatformEventType.PAYMENT_SUCCEEDEDinstead of hard-coding the string. - The
X-Webhook-Eventheader — repeatstypeon every request. Useful for logging before you parse, but it is not signed; never skip verification because of it. - The Events page — the full catalogue, including types that exist but are never delivered to merchant endpoints.
The catalogue holds thirty-nine types. Twenty-five are deliverable. The rest are payout, account,
billing and expected-payment events, plus payment.initiated and subscription.initiated, which
are recorded internally and never sent to a webhook.
One endpoint, one switch
Every delivery has the same envelope — id, type, environment, createdAt, data — so the
only thing that decides the handler is type. Verify the signature first (the raw body, not a
re-serialized object), parse, then branch.
TypeScript
import express from "express";
import { PlatformEventType, WebhookHandler, type WebhookEvent } from "@vectapay/sdk";
const webhooks = new WebhookHandler(process.env.VECTAPAY_WEBHOOK_SECRET!);
const app = express();
app.post(
"/webhooks/vectapay",
express.raw({ type: "application/json" }), // the raw bytes, not a parsed object
async (req, res) => {
const rawBody = (req.body as Buffer).toString("utf8");
const signature = String(req.headers["x-signature"] ?? "");
if (!(await webhooks.verifySignature(rawBody, signature))) {
return res.status(400).json({ error: "Invalid signature" });
}
const event = JSON.parse(rawBody) as WebhookEvent;
try {
await dispatch(event);
res.status(200).json({ received: true });
} catch (error) {
console.error("handler failed", event.id, error);
res.status(500).json({ error: "Handler failed" }); // a 5xx makes VectaPay retry
}
},
);
async function dispatch(event: WebhookEvent) {
if (event.environment === "test") {
return; // simulated or test-mode traffic — don't touch real orders
}
switch (event.type) {
case PlatformEventType.PAYMENT_SUCCEEDED:
return markOrderPaid(event.data.reference, event.data.amount);
case PlatformEventType.PAYMENT_FAILED:
return markOrderFailed(event.data.reference, event.data.failure?.code ?? null);
case PlatformEventType.PAYMENT_REFUNDED:
return recordRefund(event.data.paymentId);
case PlatformEventType.PAYMENT_DISPUTED:
return openDispute(event.data.paymentId); // its `data` is the dispute shape
case PlatformEventType.SUBSCRIPTION_CHARGE_FAILED:
return notifyDunning(event.data.subscriptionId, event.data.eventPayload);
case PlatformEventType.SUBSCRIPTION_CANCELED:
return stopAccess(event.data.subscriptionId);
default:
console.info("unhandled event type", event.type); // acknowledge and drop
}
}Which handler gets which type
Payment events share one data shape — the payment — except the dispute and late-success events,
which carry their own.
| Event | data | What the handler usually does |
|---|---|---|
payment.pending | payment | Mark the order as awaiting payment. Don’t fulfil yet. |
payment.succeeded | payment | Fulfil, once. |
payment.failed | payment | Record failure.code; decide whether the customer can try again. |
payment.cancelled | payment | The customer dismissed the prompt. Release reservations. |
payment.expired | payment | The prompt timed out. Treat it like cancelled. |
payment.reversed | payment | The provider took the money back. Undo fulfilment. |
payment.refunded | payment | A partial refund keeps status: "succeeded"; a full one arrives as "reversed". |
payment.disputed | dispute | Open a case. evidenceDueAt is the response deadline. |
payment.late_success | late success | Money arrived for a payment already marked failed. Record it for reconciliation. |
Subscription events share the subscription data and add a small eventPayload whose fields
depend on the step.
| Event | Fields in data.eventPayload | What the handler usually does |
|---|---|---|
subscription.created | status, planId | Create the membership record. No charge yet. |
subscription.activated | previousStatus, activatedAt, nextBillingAt | Grant access until data.nextBillingAt. Immediate-start creation emits only subscription.created. |
subscription.charge_succeeded | charge fields, including receiptNumber | Extend access to the new period. |
subscription.charge_failed | failureCode, attemptNumber, attemptsLeft, retryAt, graceEndsAt | Mark past due and set the grace boundary. |
subscription.retry_scheduled | retryNumber, retryAt, amount | Record it. Access doesn’t change. |
subscription.dunning_started | previousStatus, graceEndsAt | Start your reminders. Access usually continues until grace ends. |
subscription.dunning_exhausted | graceEndsAt, reason | No automatic retries remain. The subscription is still past_due, not expired. |
subscription.paused | reason, maybe source | Withhold service. |
subscription.resumed | resumedAt, nextBillingAt | Restore service. |
subscription.canceled | On request: cancelAtPeriodEnd, reason (and source from the customer portal). On finalisation: cancelAtPeriodEnd, effectiveAt | If cancelAtPeriodEnd, keep access to the end of the period. |
subscription.expired | graceEndsAt, finalStatus | Revoke access. |
Both families carry amounts as money objects: data.amount.amount is an integer string in
minor units — "50000" is KES 500.00. Show data.amount.formatted and never divide the
integer by 100 yourself.
Types you will never receive
payment.initiated and subscription.initiated exist in the catalogue but are not delivered to
merchant endpoints, so the tables above leave them out. Payout, account, billing and
expected-payment events are also never sent to a merchant webhook — poll the payout API or read the
dashboard. Events lists the full catalogue with payload examples, including
the dispute and late-success shapes.
When the type is unfamiliar
New event types can be added to the catalogue after you deploy, so the default branch is load-
bearing:
- TypeScript and Python parse anything and let it fall through to
default— log it and return2xx. - Java and C# throw while parsing an unknown wire type (
IllegalArgumentExceptionandJsonExceptionrespectively). Catch it after signature verification, as above, and return2xx.
Never answer an unfamiliar type with a non-2xx. VectaPay reads that as “the endpoint could not take this delivery”: it retries four more times over about an hour, and five consecutive failed deliveries pause the endpoint. An old handler that treats a new type as an error takes itself offline the moment the catalogue grows.
One payment can produce more than one event
Don’t model one object as one delivery. A payment can emit payment.failed and later
payment.late_success; a refund arrives after payment.succeeded; a subscription produces a whole
sequence of events. Ordering between different events is not guaranteed either. Write handlers that
set state (paid, past_due) rather than incrementing counters, so a repeat or an out-of-order
arrival doesn’t double-count.
Retries mean the same delivery can reach you twice. Signatures & Idempotency
covers the Idempotency-Key header and how to make a repeat a no-op.
Test each type you handle
Developer → Webhooks → Send test event delivers a correctly signed event of any type you’ve subscribed to, including the ones your own phone can’t easily produce — a dispute, a late success, a dunning sequence. Testing Your Endpoint covers what the payloads look like and how to read the delivery log.