Skip to content

Verify Adyen webhooks

Verify that a webhook really came from Adyen (Europe) before acting on it.

Identifier 'adyen'
Import import { verifyAdyen } from 'verihook/adyen'
Headers hmacsignature (platform and management webhooks)
Signature Standard webhooks: base64 HMAC-SHA256 of selected fields of each notification item, in additionalData.hmacSignature. Platform and management webhooks: base64 HMAC-SHA256 of the raw body in the HmacSignature header.
Replay window None (the provider sends no timestamp)
result.eventType the first item’s eventCode, e.g. AUTHORISATION

The webhook’s HMAC key (hex): in the Customer Area, open Developers → Webhooks, edit the webhook and generate the HMAC key under its security settings.

Store it in an environment variable (ADYEN_HMAC_KEY below) and never commit it.

import { verifyAdyen } from 'verihook/adyen';
export async function POST(request: Request) {
const result = await verifyAdyen(request, process.env.ADYEN_HMAC_KEY!);
if (!result.valid) {
console.warn(result.code, result.reason, result.hint);
return new Response('Invalid signature', { status: 401 });
}
console.log(result.eventType, result.event);
return Response.json({ received: true });
}

request can be a Fetch Request or { headers, body, url? } with the raw body. verifyWebhook('adyen', request, secret) from verihook does the same. Read why the raw body matters if verification fails behind a body parser.

app/api/webhooks/adyen/route.ts
import { createWebhookHandler } from 'verihook/next';
export const POST = createWebhookHandler('adyen', process.env.ADYEN_HMAC_KEY!, async (payload, result) => {
// Runs only for a valid signature
console.log(result.eventType, result.event);
});

Each adapter responds 401 to an invalid signature, 413 to a body over maxBodySize (2 MB by default) and 200 to a duplicate when you pass a dedupeStore.

  • Every item in a batch must verify, or the whole request is rejected.
  • Adyen expects [accepted] as the response body for standard webhooks.

signWebhook from verihook/testing builds a correctly signed Adyen request for your tests:

import { signWebhook } from 'verihook/testing';
import { verifyAdyen } from 'verihook/adyen';
const hook = await signWebhook('adyen', {
secret: '0123456789abcdef0123456789abcdef',
payload: { id: 'evt_test' },
});
const result = await verifyAdyen(
{ headers: hook.headers, body: hook.body, url: hook.url },
hook.secret,
);
// result.valid === true

From the command line, npx verihook simulate adyen --url http://localhost:3000/webhooks/adyen sends one to your local server.

See Testing your handlers for supertest and Fetch Request examples.

Failed results carry a code and often a hint with the likely cause. See Troubleshooting for each error code.

Adyen’s webhook documentation