Webhooks

AegisPay POSTs a signed JSON event to your server when a payment reaches a final state.

Where they go #

Set a default URL in the dashboard under Settings → Webhooks, or send callback_url when creating a payment (it overrides the default for that payment). Each payment keeps the URL it was created with. URLs must be public https://.

Events #

typeWhen
payment.succeededThe payment is paid and confirmed with the bank network. Fulfil the order.
payment.expiredThe payer didn't pay before expires_at. A payment.succeeded may still follow if the bank confirms late.
payment.succeeded
{
  "id": "evt_9Zx4Cv7Bn2Mq5Lp8aB3c",
  "object": "event",
  "type": "payment.succeeded",
  "created_at": "2026-11-25T08:03:12.000Z",
  "data": {
    "object": "payment",
    "id": "pay_7Hq2xK9mN4pR8sT1aB3c",
    "status": "succeeded",
    "amount": "150.00",
    "currency": "MYR",
    "method": "fpx",
    "merchant_reference": "ORDER-1001",
    "description": "Order #1001",
    "fee": "2.25",
    "net_amount": "147.75",
    "checkout_url": null,
    "expires_at": "2026-11-25T08:15:00.000Z",
    "paid_at": "2026-11-25T08:03:10.000Z",
    "created_at": "2026-11-25T08:00:00.000Z",
    "updated_at": "2026-11-25T08:03:12.000Z"
  }
}

data is the same payment object the API returns.

Headers #

ParameterTypeRequiredDescription
X-Aegis-Merchant-IdstringYesMust equal YOUR merchant ID.
X-Aegis-Event-IdstringYesThe event ID (evt_…). The same on every retry: de-duplicate on it.
X-Aegis-Key-IdstringYesThe AegisPay key that signed it. Must be one of your pinned keys.
X-Aegis-TimestampstringYesUnix seconds of THIS attempt (re-signed on every retry).
X-Aegis-SignaturestringYesBase64 RSA-PSS signature of the canonical string below.
Webhook canonical string
AEGIS1-WEBHOOK-RSA-PSS-SHA256
<X-Aegis-Merchant-Id>
<X-Aegis-Event-Id>
<X-Aegis-Key-Id>
<X-Aegis-Timestamp>
<lower-case hex SHA-256 of the raw request body>

Your handler must #

  1. Read the raw body bytes before any JSON parsing.
  2. Check the merchant ID, the key ID (pinned), the timestamp (±300 s) and the signature. If anything fails, answer 401 and do nothing.
  3. De-duplicate on the event ID. Retries resend the same event.
  4. Check amount, currency and merchant_reference against your order. Never auto-fulfil a mismatch.
  5. Make the update idempotent: "mark paid" twice must be harmless.
  6. Answer 2xx within 10 seconds. Do slow work (emails, shipping) in the background.
Node.js + Express (aegispay.mjs)
import express from "express";
import { aegis } from "./aegis.mjs"; // your configured AegisPay instance

const app = express();

// express.raw: the signature covers the EXACT bytes, so don't let a JSON parser touch them first.
app.post("/aegis/webhook", express.raw({ type: "application/json", limit: "64kb" }), async (req, res) => {
  const event = aegis.verifyWebhook(req.headers, req.body);
  if (!event) return res.sendStatus(401);

  // Retries resend the same event id: process each id once.
  if (await db.webhookAlreadyProcessed(event.id)) return res.sendStatus(200);

  const payment = event.data;
  const order = await db.findOrderByReference(payment.merchant_reference);
  if (order && event.type === "payment.succeeded") {
    if (payment.amount !== order.amount || payment.currency !== "MYR") {
      await alertHuman("AegisPay amount mismatch", payment.id); // never auto-fulfil a mismatch
    } else {
      await db.markOrderPaid(order.id, payment.id); // must be harmless if run twice
    }
  }
  await db.recordWebhookProcessed(event.id);
  res.sendStatus(200); // answer within 10 s; do slow work in the background
});
Python + Flask (aegis1.py)
# Flask example, using aegis1.py
import json
from flask import Flask, request
from aegis1 import verify_webhook

app = Flask(__name__)

@app.post("/aegis/webhook")
def aegis_webhook():
    raw = request.get_data()  # exact bytes, before any JSON parsing
    event_id = verify_webhook(PLATFORM_KEYS, expected_merchant_id=MERCHANT_ID, headers=request.headers, body=raw)
    if event_id is None:
        return "", 401
    if already_processed(event_id):
        return "", 200
    event = json.loads(raw)
    handle(event)            # check amount/currency against your order; idempotent
    mark_processed(event_id)
    return "", 200

Retries #

Anything other than a 2xx within 10 seconds (an error, timeout, TLS problem or redirect) is retried after 1 min, 5 min, 15 min, 1 h, 3 h, 6 h and 12 h, then every 24 h until 72 hours have passed. Then the delivery is marked failed. The dashboard's Webhooks page shows every attempt and lets you resend any event.

A webhook is a notification, not the only source of truth. If one seems late, call GET /v1/payments/{id}.