Check a webhook came from Pay My Business
Verify the signature on every message so your system only trusts genuine ones.
Your webhook address is not a secret, so anyone could send to it. Every genuine message is signed with your secret key. Your developer should check the signature before trusting a message.
What is sent
Each message has a signature header. Its exact name is shown in the How webhooks work & how to set one up panel on the Webhook page, and the header value looks like this:
t=1737460000,v1=3a4f8c...e21b
tis the time in seconds, as a Unix timestamp, at which the message was signed.v1is a hex-encoded HMAC-SHA256 of the textt, then a full stop, then the raw body, keyed with your secret key.
Your secret key is never in the body. It stays on your side and is only used to check.
How to verify
- Read the raw body exactly as received, before any JSON parsing. Re-encoding the parsed body can change spacing or key order and the check fails. This is the most common mistake.
- Split the header into its
tandv1parts. - Compute HMAC-SHA256 of
t, a full stop and the raw body with your secret key, and hex-encode it. - Compare it to
v1with a constant-time comparison (in PHP,hash_equals). Never use a plain equals. - Optional: reject a message whose
tis far from your clock. Keep the window generous, a few hours: deliveries are queued and can be retried, so a tight window rejects genuine messages. - Answer with a 2xx for a message you accept.
The Webhook page has a How webhooks work & how to set one up panel with a PHP example you can copy.