Skip to Content
WebhooksOverview

Webhooks

A payment’s outcome is asynchronous — the customer might take 45 seconds to enter their PIN. Webhooks are how VectaPay tells your server the moment a payment or subscription resolves, instead of you asking repeatedly. (Payouts are not delivered to merchant webhook endpoints — poll the payout or read it from the dashboard.)

There is no waitForCompletion()-style helper in this SDK. Blocking a request thread to poll for an outcome that can legitimately take a minute doesn’t scale — it ties up a connection per in-flight payment for no reason. Use a webhook; it costs nothing while nothing is happening.

One endpoint receives every event

You configure one URL and one signing secret. There is no URL per event type: whether you subscribe to one event or all twenty-five, every delivery arrives at the same address.

The checklist in Developer → Webhooks decides which event types are sent to that URL. An event you haven’t subscribed to is simply never delivered, so subscribe only to the types your handler actually acts on — turning on everything means writing handling code for everything, and a payload you don’t recognise is a payload you can’t act on.

Every delivery has the same top-level envelope. The type field is what you branch on:

FieldMeaning
idevt_… — identifies this delivery. A new id on a re-send; see Signatures & idempotency.
typeThe event type, e.g. payment.succeeded. This is the switch key.
environment"test" for test-mode activity, "live" for real money.
createdAtISO-8601 timestamp of when the event happened.
dataThe event-specific body. Its shape depends on the event family, not on the event.

Where the event types come from

There are four places you can get the list, and they agree with each other:

  • The dashboard checklist at Developer → Webhooks — twenty-five types, split into Payments and Subscriptions.
  • The SDK enum — PlatformEventType in @vectapay/sdk, vectapay (Python), com.vectapay.sdk.webhooks.PlatformEventType (Java), VectaPay.Sdk.PlatformEventType (C#). It’s a runtime value, so you can compare against PlatformEventType.PAYMENT_SUCCEEDED instead of hard-coding the string.
  • The X-Webhook-Event header — repeats type on every request. Handy when you log raw requests before parsing them.
  • The Events page — the full catalogue, including the types that exist but are not delivered to merchant endpoints.

Handling more than one type

A handler that receives several event types is a switch on event.type (or the equivalent — match in Python 3.10+, a switch expression in Java, a switch statement in C#). Parse once, dispatch, then acknowledge:

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" }), // Buffer, not a parsed object async (req, res) => { const rawBody = req.body.toString("utf8"); const signature = req.headers["x-signature"] as string; if (!(await webhooks.verifySignature(rawBody, signature))) { return res.status(400).json({ error: "Invalid signature" }); } const event = JSON.parse(rawBody) as WebhookEvent; try { await handleEvent(event); res.status(200).json({ received: true }); } catch (error) { console.error("webhook handler failed", event.id, error); // 5xx so VectaPay retries this delivery res.status(500).json({ error: "Handler failed" }); } }, ); async function handleEvent(event: WebhookEvent) { if (event.environment === "test") { // Test-mode and simulated traffic — don't touch real orders or ledgers. } switch (event.type) { case PlatformEventType.PAYMENT_SUCCEEDED: await markOrderPaid(event.data.reference, event.data.amount); break; case PlatformEventType.PAYMENT_FAILED: await markOrderFailed(event.data.reference, event.data.failure?.code); break; case PlatformEventType.PAYMENT_REFUNDED: await recordRefund(event.data.paymentId); break; case PlatformEventType.SUBSCRIPTION_CHARGE_FAILED: await notifyDunning(event.data.subscriptionId, event.data.eventPayload); break; default: // A type you didn't subscribe to, or one added after you deployed. Log and move on. return; } }

The same handler in Python, Java and C#, plus a table of every event type and which handler it belongs to, is on Receiving Events.

Two rules for the default branch:

  • Never answer a non-2xx because the type is unfamiliar. The platform treats that as a failed delivery, retries it four more times over about an hour, and counts it against your endpoint’s failure streak. Acknowledge with a 2xx and drop it. New event types can be added to the catalogue; an old handler must not break when one arrives.
  • Don’t treat one payment as one delivery. A payment can produce both payment.failed and, later, payment.late_success. A subscription produces a whole sequence. Your handler should be idempotent and order-tolerant rather than assuming a single linear event per object.

Setting one up

Configure your endpoint

Developer → Webhooks in the dashboard — set your URL and tick the events you want. The URL must be https:// in production. We don’t follow redirects on delivery in production either, so the address you save has to be the one that answers.

Screenshot needed: VectaPay dashboard → Developer → Webhooks page, showing the URL field, the event checklist, and the signing secret (masked) with a “Regenerate” button.

Verify and parse deliveries

The short version: read the raw body, check X-Signature, then parse. The per-language detail lives on Signatures & idempotency; the important part for this page is that verification happens against the bytes you received, not against a re-serialized object.

Use your framework’s raw body, not a JSON body parser, and verify before you parse. The signature is computed over the exact bytes received — re-serializing parsed JSON can produce a different string and fail verification even for a genuine delivery.

Respond quickly

Answer with a 2xx within 30 seconds. Anything else — a 3xx, a 4xx, a 5xx, a timeout, or no response at all — is a failed attempt and is retried. Do the actual work (updating your order, sending a confirmation email) after acknowledging, not before; a slow endpoint turns every delivery into a retry.

Test deliveries vs live deliveries

One endpoint and one secret receive both. Every payload carries a top-level environment — "test" for activity from test mode, "live" for real money — so a single handler can route both:

if (event.environment === "test") { log.info("Test delivery", { type: event.type }); return; // don't fulfil an order or write to your ledger }

Deliveries the webhook simulator sends are also marked test: true. That flag appears only on simulated deliveries; a real test-mode payment (one made through the smoke test) has environment: "test" without test: true.

Simulated deliveries show up in the same delivery log and count toward the endpoint’s failure counter like any other attempt, so a test send that gets a non-2xx tells you the endpoint is broken before a real payment depends on it.

Delivery and retries

The first attempt happens immediately. If your endpoint answers with a non-2xx, times out, or refuses the connection, the same delivery is retried after roughly 1, 5, 15, and 60 minutes (±10% jitter), for five attempts in total. After the fifth failure it is moved to the dead-letter queue and no further automatic retry happens.

That failure streak is what pauses an endpoint. It counts deliveries, not attempts: an event that fails all five attempts adds one to the streak, not five. After 5 consecutive failed deliveries the endpoint is paused — new events stop being sent to it, and you get an email. An endpoint pauses, it is not deleted: its URL, secret, and subscriptions are kept. Events that happen during the pause are not held for later — the pause switches delivery off, so they are dropped. Treat the alert email as urgent, and reconcile from the payments API if a pause lasts long.

To start delivering again, fix the endpoint and either

  • save it in Developer → Webhooks (saving an enabled endpoint clears the pause), or
  • send a test event and let it succeed — a successful delivery clears the pause and the streak.

Test sends and manual retries still go through while an endpoint is paused, which is deliberate: that’s how you prove the fix worked before new events start flowing again.

You can retry a specific delivery by hand from Developer → Webhooks → Logs. A retry re-sends that log’s stored payload on the normal five-attempt schedule. Retrying a payment’s webhook separately (dashboard, or payments.retryWebhook()) rebuilds the payload from the payment’s current state and is marked manualRetry: true; that path needs the endpoint enabled and the payment out of pending/initiated.

Next

Last updated on