Skip to content

Commit f8aa64f

Browse files
committed
Update WebhooksHelper
1 parent 0b58af8 commit f8aa64f

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

src/Utils/WebhooksHelper.php

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
<?php
2+
23
namespace Square\Utils;
34

45
use Exception;
56

67
/**
78
* Utility to help with Square Webhooks
89
*/
9-
class WebhooksHelper {
10+
class WebhooksHelper
11+
{
1012
/**
1113
* Verifies and validates an event notification.
1214
* See the documentation for more details.
@@ -34,13 +36,16 @@ public static function verifySignature(
3436
throw new Exception('notificationUrl is null or empty');
3537
}
3638

37-
// Perform UTF-8 encoding to bytes
39+
// Compute the payload.
3840
$payload = $notificationUrl . $requestBody;
39-
$payloadBytes = mb_convert_encoding($payload, 'UTF-8');
40-
$signatureKeyBytes = mb_convert_encoding($signatureKey, 'UTF-8');
4141

4242
// Compute the hash value
43-
$hash = hash_hmac('sha256', $payloadBytes, $signatureKeyBytes, true);
43+
$hash = hash_hmac(
44+
algo: 'sha256',
45+
data: $payload,
46+
key: $signatureKey,
47+
binary: true
48+
);
4449

4550
// Compare the computed hash vs the value in the signature header
4651
$hashBase64 = base64_encode($hash);

0 commit comments

Comments
 (0)