Where is WebhooksHelper in PHP SDK?

I’m using the PHP SDK to create a webhook endpoint. I have implemented their example on how to Verify and Validate an Event notification from here:
Webhook event notification validation - PHP

Any time I run my webhook, I get a 500 error, and the server logs the error:
PHP Fatal error: Uncaught Error: Class "Square\\Utils\\WebhooksHelper" not found

Sure enough, when searching through the SDK (both locally and on github), the WebhooksHelper class can’t be found anywhere, and neither can the function ‘isValidWebhookEventSignature’, which WebhooksHelper is calling.

I have installed the PHP SDK using composer.
The version is 29.0.0.20230720
I can remove the references to WebhooksHelper, including the validation function, and I get a proper 200 response, so my webhook is going to the right place.

Am I doing something wrong? Is the documentation outdated? I’m just at a loss of how to proceed with validation.

Hey @ascottme :wave: We’ve identified an issue with the PHP SDK missing the WebhooksHelper utility and are working on releasing a fix!

Ok, great. I thought I was going crazy.

Rather than compose the entire sdk into my project, I adapted the one function I need. Also be aware of incorrect case in documentation PHP example. Correct header: X-Square-Hmacsha256-Signature

function isValidWebhookEventSignature($requestBody, $signatureHeader, $signatureKey, $notificationUrl){
	if ($requestBody === null) {
	  return false;
	}
	if ($signatureKey === null || strlen($signatureKey) === 0) {
		throw new Exception('signatureKey is null or empty');
	}
	if ($notificationUrl === null || strlen($notificationUrl) === 0) {
		throw new Exception('notificationUrl is null or empty');
	}
	$payload = $notificationUrl . $requestBody;
	$payloadBytes = mb_convert_encoding($payload, 'UTF-8');
	$signatureKeyBytes = mb_convert_encoding($signatureKey, 'UTF-8');
	$hash = hash_hmac('sha256', $payloadBytes, $signatureKeyBytes, true);
	$hashBase64 = base64_encode($hash);
	return $hashBase64 === $signatureHeader;
}

1 Like