Validate signed notifications before trusting their identifiers:
try {
WebhookSignatureValidator::validate(
$_SERVER['HTTP_X_SIGNATURE'] ?? null,
$_SERVER['HTTP_X_REQUEST_ID'] ?? null,
$_GET['data.id'] ?? null,
$_ENV['MP_WEBHOOK_SECRET'],
300
);
} catch (InvalidWebhookSignatureException $error) {
http_response_code(401);
exit;
}
Pass x-signature, x-request-id, and data.id exactly as received. Trimming, decoding, or normalizing them before validation can change the signed manifest. QR Code notifications are not signed and must not use this validator.
A production endpoint should:
Use the notification as a signal and the API resource as the current state. Keep server clocks synchronized. Record a sanitized validation result, but never the webhook secret or complete signature.