Skip to the page

Webhooks

When a pay-in or a payout reaches a final or a review status, AquaPay posts a signed event to your server. Verify the signature, answer 2xx, and apply the event if it is newer than what you hold.

Events

TypeSent when
payin.succeededThe payer paid and the amount matches, including a late payment on a failed or expired pay-in.
payin.failedThe provider refused or failed the pay-in. Nothing was credited.
payin.expiredThe pay-in was still unpaid two hours after it was opened.
payin.needs_reviewThe evidence does not settle it, such as a paid amount that differs.
payout.succeededThe provider confirmed the payout for exactly its amount.
payout.failedThe payout failed, at creation or later. Its hold is released.
payout.needs_reviewThe evidence is contradictory. The amount stays held.
payout.reversedThe payout was paid, then returned. Its hold is released.

Every move into one of these statuses makes exactly one event. Moves into pending orprocessing make none: the call that created the payment already answered. Events cover every payment of the account, whichever way it was created.

An event
{
  "id": "event_q2w8e5r1t7y3v",
  "type": "payin.succeeded",
  "mode": "live",
  "account": "ga_3k9d2m7q1x8vb",
  "createdAt": "2026-12-03T09:15:07Z",
  "data": { "id": "payin_7h2kq9w3m1zt4", "status": "succeeded", "version": 3, "…": "the whole pay-in or payout" }
}

data is the pay-in or the payout exactly as GET returns it at that moment, so an event is complete on its own.

Endpoints and secrets

  • An account has up to three endpoints. Add them in the console under Developers, Webhooks, or with POST /webhook-endpoints.
  • An endpoint is an https address reachable from the internet. It can take every event type, or only the ones you pick.
  • Each endpoint has its own signing secret, aqwh_ and 40 characters, shown once when it is made or replaced. It is not an API key.
  • Use one endpoint for each gateway account and put the account in the path, so your server knows which secret to use before it reads the body. Check the event's account as well.

The signature

A delivery's header
AquaPay-Signature: t=1796289307,sha256=d43246d6edb197cca25a95aec428d59625c5c64e125e731c0f0dab2d4235475e
  • sha256 is the hex HMAC-SHA256 of <t>.<raw body>, keyed with the endpoint's secret, prefix included.
  • t is the Unix time of this delivery attempt. Refuse a delivery whose t is more than 300 seconds from your clock.
  • For 24 hours after a secret is replaced the header carries two sha256 values, one for each secret. A server holding either one accepts it, so replacing a secret needs no downtime.
  • Verify the bytes exactly as they arrived. Parsing the JSON and writing it out again changes them.

Verify in your code

The check is a few lines in any language: read t and the sha256 values, refuse an oldt, and compare the HMAC in constant time. Each of these is complete, uses nothing outside its language's own library, and accepts the test vector below.

import { createHmac, timingSafeEqual } from "node:crypto";

// rawBody is the request body exactly as it arrived (a Buffer or a string), before any JSON parser touches it.
// secrets holds the endpoint's signing secret: two of them while you switch after replacing it.
export function verifyAquaPayWebhook(header, rawBody, secrets, now = Date.now() / 1000) {
  const parts = header.split(",").map((part) => part.trim().split("="));
  const t = parts.find(([key]) => key === "t")?.[1] ?? "";
  const signatures = parts.filter(([key, value]) => key === "sha256" && /^[0-9a-f]{64}$/.test(value));
  if (!/^\d+$/.test(t) || signatures.length === 0) throw new Error("malformed AquaPay-Signature");
  if (Math.abs(now - Number(t)) > 300) throw new Error("signature outside the 300 s tolerance");
  for (const secret of secrets) {
    const expected = createHmac("sha256", secret).update(`${t}.`).update(rawBody).digest();
    for (const [, signature] of signatures) {
      if (timingSafeEqual(expected, Buffer.from(signature, "hex"))) return JSON.parse(rawBody);
    }
  }
  throw new Error("signature does not match");
}

// With Express: express.raw({ type: "application/json" }) on this route keeps req.body as the bytes that were signed.
// const event = verifyAquaPayWebhook(req.get("AquaPay-Signature") ?? "", req.body, [process.env.AQUAPAY_WEBHOOK_SECRET]);
import hashlib
import hmac
import json
import re
import time


def verify_aquapay_webhook(header: str, raw_body: bytes, secrets: list[str], now: float | None = None) -> dict:
    """Returns the event, or raises ValueError. raw_body is the request body exactly as it arrived."""
    parts = [part.strip().split("=", 1) for part in header.split(",")]
    t = next((part[1] for part in parts if part[0] == "t" and len(part) == 2), "")
    signatures = [part[1] for part in parts if part[0] == "sha256" and len(part) == 2]
    signatures = [value for value in signatures if re.fullmatch(r"[0-9a-f]{64}", value)]
    if not t.isdigit() or not signatures:
        raise ValueError("malformed AquaPay-Signature")
    if abs((time.time() if now is None else now) - int(t)) > 300:
        raise ValueError("signature outside the 300 s tolerance")
    for secret in secrets:
        expected = hmac.new(secret.encode(), t.encode() + b"." + raw_body, hashlib.sha256).hexdigest()
        if any(hmac.compare_digest(expected, signature) for signature in signatures):
            return json.loads(raw_body)
    raise ValueError("signature does not match")


# With Flask: request.get_data() is the raw body.
# event = verify_aquapay_webhook(request.headers.get("AquaPay-Signature", ""), request.get_data(), [SECRET])
<?php
// $rawBody is the request body exactly as it arrived: file_get_contents("php://input").
function verify_aquapay_webhook(string $header, string $rawBody, array $secrets, ?int $now = null): array
{
    $t = "";
    $signatures = [];
    foreach (explode(",", $header) as $part) {
        [$key, $value] = array_pad(explode("=", trim($part), 2), 2, "");
        if ($key === "t") {
            $t = $value;
        } elseif ($key === "sha256" && preg_match('/^[0-9a-f]{64}$/', $value)) {
            $signatures[] = $value;
        }
    }
    if (!ctype_digit($t) || !$signatures) {
        throw new InvalidArgumentException("malformed AquaPay-Signature");
    }
    if (abs(($now ?? time()) - (int) $t) > 300) {
        throw new InvalidArgumentException("signature outside the 300 s tolerance");
    }
    foreach ($secrets as $secret) {
        $expected = hash_hmac("sha256", $t . "." . $rawBody, $secret);
        foreach ($signatures as $signature) {
            if (hash_equals($expected, $signature)) {
                return json_decode($rawBody, true);
            }
        }
    }
    throw new InvalidArgumentException("signature does not match");
}

// $event = verify_aquapay_webhook($_SERVER["HTTP_AQUAPAY_SIGNATURE"] ?? "", file_get_contents("php://input"), [$secret]);
// Verify checks an AquaPay-Signature header against the raw request body.
// secrets holds the endpoint's signing secret: two of them while you switch after replacing it.
func Verify(header string, body []byte, secrets []string, now time.Time) error {
	var ts string
	var sigs [][]byte
	for _, part := range strings.Split(header, ",") {
		k, v, ok := strings.Cut(strings.TrimSpace(part), "=")
		if !ok {
			continue
		}
		switch k {
		case "t":
			ts = v
		case "sha256":
			if b, err := hex.DecodeString(v); err == nil && len(b) == sha256.Size {
				sigs = append(sigs, b)
			}
		}
	}
	sec, err := strconv.ParseInt(ts, 10, 64)
	if err != nil || len(sigs) == 0 {
		return errors.New("malformed AquaPay-Signature")
	}
	if d := now.Sub(time.Unix(sec, 0)); d > 300*time.Second || d < -300*time.Second {
		return errors.New("signature outside the 300 s tolerance")
	}
	for _, secret := range secrets {
		mac := hmac.New(sha256.New, []byte(secret))
		mac.Write([]byte(ts + "."))
		mac.Write(body)
		want := mac.Sum(nil)
		for _, sig := range sigs {
			if hmac.Equal(want, sig) {
				return nil
			}
		}
	}
	return errors.New("signature does not match")
}

// In a handler: body, _ := io.ReadAll(r.Body), then
// err := Verify(r.Header.Get("AquaPay-Signature"), body, []string{secret}, time.Now())
// rawBody is the request body exactly as it arrived. Returns true when it was signed with one of the secrets.
static boolean verifyAquaPayWebhook(String header, byte[] rawBody, List<String> secrets, long now) throws Exception {
    String t = "";
    List<String> signatures = new ArrayList<>();
    for (String part : header.split(",")) {
        String[] pair = part.trim().split("=", 2);
        if (pair.length != 2) continue;
        if (pair[0].equals("t")) t = pair[1];
        else if (pair[0].equals("sha256") && pair[1].matches("[0-9a-f]{64}")) signatures.add(pair[1]);
    }
    if (!t.matches("\\d+") || signatures.isEmpty()) return false;
    if (Math.abs(now - Long.parseLong(t)) > 300) return false;
    for (String secret : secrets) {
        Mac mac = Mac.getInstance("HmacSHA256");
        mac.init(new SecretKeySpec(secret.getBytes(StandardCharsets.UTF_8), "HmacSHA256"));
        mac.update((t + ".").getBytes(StandardCharsets.UTF_8));
        byte[] expected = mac.doFinal(rawBody);
        for (String signature : signatures) {
            if (MessageDigest.isEqual(expected, HexFormat.of().parseHex(signature))) return true;
        }
    }
    return false;
}

// boolean genuine = verifyAquaPayWebhook(request.getHeader("AquaPay-Signature"), rawBody, List.of(secret), Instant.now().getEpochSecond());

Then, in this order:

  1. Check that event.account is the account this address serves.
  2. Skip an event.id you have already handled. Delivery is at least once.
  3. Apply data only if data.version is greater than the version you hold for that payment. Deliveries can arrive out of order.
  4. Never credit anyone for an event whose mode is test.
  5. Answer 2xx quickly and do slow work afterwards.

Signature debugger

Paste a delivery your server refused. Each step of the check says what it found: the header, the signed time, or the HMAC. It runs in this page with your browser's own cryptography, and nothing you paste is sent anywhere.

The raw request body, exactly as it arrived. A pretty-printed copy will not match.
Checked in this browser with Web Crypto. It is never sent to AquaPay, or anywhere else.

Paste a payload, its header and the endpoint's secret. The three steps of the check appear here: reading the header, the signed time, and the HMAC.

Delivery and retries

  • A delivery succeeds on any 2xx within 10 seconds. The body of your answer is ignored, and redirects are not followed.
  • AquaPay sends Content-Type: application/json, User-Agent: AquaPay-Webhooks/2 and AquaPay-Signature.
  • A failed delivery is tried 8 times: at once, 1 minute, 5 minutes, 30 minutes, 2 hours, 6 hours, 12 hours and 24 hours after each failure, about 45 hours in all. Each try is signed afresh.
  • After that the event stays in the list of events for 30 days, where it can be sent again from the console. An endpoint is never switched off for you.

Polling, as a safety net

GET /events lists the same events, oldest first. ItsnextCursor is never null: store it and poll with it to get only newer events. With waitit holds an empty answer open for up to 30 seconds, so a loop of polls follows the stream as it happens. Poll every few minutes even when webhooks work, and a missed delivery costs you nothing.

In the console

  • Send test event sends a signed event of any type to an endpoint and shows what it answered.
  • Events and deliveries shows every attempt: what AquaPay sent, the status, the time taken and the first 2 KiB of the answer. Any event can be sent again.
  • Each endpoint shows its share of deliveries that got through in the last 24 hours, and its last failure.

A test vector

Check your own implementation against it before you trust it. With a clock set to 1796289307 (the header's t) it must accept this body; with one more character in the body, or a clock 301 seconds later, it must refuse. The body is one line with no newline after it.

Secretaqwh_Zt8kP3vQ9mW2xR6nB1cY7hJ4gF0sD5aL8eT3uK6q
Headert=1796289307,sha256=d43246d6edb197cca25a95aec428d59625c5c64e125e731c0f0dab2d4235475e
Raw body
{"id":"event_q2w8e5r1t7y3v","type":"payin.succeeded","mode":"live","account":"ga_3k9d2m7q1x8vb","createdAt":"2026-12-03T09:15:07Z","data":{"id":"payin_7h2kq9w3m1zt4","reference":"DEP-20261203-0042","status":"succeeded","amount":"500.00","paidAmount":"500.00","currency":"INR","fee":"12.50","net":"487.50","utr":"416512345678","orderId":"AQD2612030915000042","providerOrderId":"CP88123409","nextAction":null,"expiresAt":"2026-12-03T11:15:00Z","failure":null,"version":3,"createdAt":"2026-12-03T09:15:00Z","updatedAt":"2026-12-03T09:15:07Z"}}