xtopaydocs

Webhooks

Xtopay sends your server a signed request when a payment succeeds or fails, when a payout lands or fails, and when a transfer ends.

Live

Webhooks work today, for payments through your xtopay.me link, payment links, payment pages and invoices, and for payouts. Checkouts made through the API will send the same events when the API arrives.

Add an endpoint

In the dashboard's Developers page, choose Add endpoint, enter its URL and choose its events. You get its signing secret (whsec_…) for checking that requests really come from Xtopay; Signing secret shows it again. The owner, admins and developers can add and change endpoints.

  • Endpoints must use HTTPS, on a public address: Xtopay won't call localhost or a private network.
  • A business can have up to 10 endpoints.
  • Send test sends a sample payment.successful, marked "test": true, straight away, so you can check your handler.
  • Switch an endpoint off to stop events for a while. Nothing is kept for it while it's off.

Events

EventWhen
payment.successfulA customer has paid
payment.failedA payment didn't go through
payment.refundedYou refunded a payment, in full or in part. Comes with refunds
payout.paidA payout reached your account
payout.failedA payout couldn't be sent. Its money is back in your balance
transfer.successfulA transfer reached the wallet or account
transfer.failedA transfer couldn't be sent. Its money is back in your balance
transfer.declinedYour owner declined a transfer that waited for approval, or nobody approved it in 24 hours

What you receive

A POST with a JSON body. business_id is the business it happened to (useful if you take payments for several), and data is the payment, the payout or the transfer, as it was when the event happened.

payment.successful
{
  "id": "evt_3n8w2k5p",
  "type": "payment.successful",
  "business_id": "48271935",
  "created_at": "2026-10-24T09:16:42Z",
  "data": {
    "reference": "XTP-7C9ADM3DKQF2",
    "business_id": "48271935",
    "checkout": null,
    "amount": 350,
    "customer_fee": 6.83,
    "fee": 6.83,
    "net": 350,
    "currency": "GHS",
    "status": "successful",
    "method": "mtn",
    "customer": { "name": "Kofi Boateng", "phone": "233244123456", "email": null },
    "description": "Jollof party pack",
    "source": { "type": "link", "id": "lnk_…", "name": "Jollof party pack" },
    "metadata": {},
    "refunded_amount": 0,
    "failure_reason": null,
    "created_at": "2026-10-24T09:16:10Z",
    "paid_at": "2026-10-24T09:16:41Z"
  }
}
payout.paid
{
  "id": "evt_9q2m4k7x",
  "type": "payout.paid",
  "business_id": "48271935",
  "created_at": "2026-10-25T10:02:13Z",
  "data": {
    "reference": "XTP-PO-7K2M9QH4TZ",
    "business_id": "48271935",
    "amount": 1250,
    "fee": 0,
    "currency": "GHS",
    "status": "paid",
    "trigger": "scheduled",
    "account": {
      "type": "momo",
      "network": "mtn",
      "bank": null,
      "name": "NANA AMA OWUSU",
      "number": "024 ••• 1234"
    },
    "failure_reason": null,
    "created_at": "2026-10-25T10:00:04Z",
    "paid_at": "2026-10-25T10:02:12Z"
  }
}

With these headers:

Header
Xtopay-Signaturet=<unix time>,v1=<signature>
Xtopay-EventThe event's type, like payment.successful
Content-Typeapplication/json
User-AgentXtopay-Webhooks/1.0

Check the signature

The signature is an HMAC-SHA256, in hex, of the time, a full stop and the raw request body, keyed with your endpoint's signing secret. Check it before you trust anything in the body, and refuse requests more than 5 minutes old, so an old request can't be replayed. A request that fails either check didn't come from Xtopay, however right it looks: anyone can post to your endpoint's address. Keep the signing secret on your server, never in an app or a web page.

For orders worth a lot, confirm before you hand anything over: get the payment with GET /v1/payments/:reference and check its status and amount yourself.

import crypto from "node:crypto";
import express from "express";

const app = express();

// The raw body: the signature is over the exact bytes sent.
app.post("/xtopay/webhook", express.raw({ type: "application/json" }), (req, res) => {
  const header = req.get("Xtopay-Signature") ?? "";
  const parts = Object.fromEntries(header.split(",").map((p) => p.split("=")));
  const expected = crypto
    .createHmac("sha256", process.env.XTOPAY_WEBHOOK_SECRET)
    .update(`${parts.t}.${req.body}`)
    .digest("hex");
  const fresh = Math.abs(Date.now() / 1000 - Number(parts.t)) < 300;
  const valid =
    parts.v1?.length === expected.length &&
    crypto.timingSafeEqual(Buffer.from(parts.v1), Buffer.from(expected));
  if (!fresh || !valid) return res.sendStatus(400);

  const event = JSON.parse(req.body);
  if (event.type === "payment.successful") {
    // Fulfil the order for event.data.metadata.order_id, once.
  }
  res.sendStatus(200);
});

Answer quickly, act once

  • Answer with any 2xx within 10 seconds. Do slow work, like sending emails, after you've answered.
  • If you don't, Xtopay tries again, 8 more times over about 3 days: after 1 minute, 5 minutes, 30 minutes, 2 hours, 6 hours, 12 hours, a day and a day. Each try has the same event id. Redirects aren't followed, so use your endpoint's final address.
  • The same event can arrive twice, and events can arrive out of order. Keep the ids you've handled and skip repeats. When the order matters, get the payment from the API for its current status.

Every delivery shows in Developers with your server's answer, how long it took, what went wrong and when the next try is. Resend tries one again now; if that fails too, the retries carry on while any are left.

On this page