HMAC Verification
<?php
// Provided to you when configuring webhook
$secret = 'Shared HMAC Key';
// Get the request body (payload)
$requestBody = file_get_contents('php://input');
// Get the HMAC signature sent in the header
$receivedHMAC = $_SERVER['HTTP_X_SIGNATURE'] ?? '';
// Calculate the expected HMAC using the shared secret and the payload sent
$calculatedHMAC = hash_hmac('sha256', $requestBody, $secret);
// Verify that the received signature matches the expected signature
if (hash_equals($calculatedHMAC, $receivedHMAC)) {
// Signature is valid, process the webhook payload
$data = json_decode($payload, true);
// Handle the webhook data as needed
http_response_code(200);
echo 'Webhook verified and processed';
} else {
// Invalid signature
http_response_code(400);
echo 'Invalid signature';
}Last updated