Skip to content

Commit 8219c6c

Browse files
committed
Provide scripts for payments and banking webhooks
1 parent 0bba5ba commit 8219c6c

File tree

2 files changed

+44
-3
lines changed

2 files changed

+44
-3
lines changed
Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
<?php
22

3-
// script to calculate the HMAC signature using the PHP library `calculateHmacSignature` function
3+
// script to calculate the HMAC signature of Banking/Management webhooks (where the signature is calculated over the
4+
// entire webhook payload)
45
//
5-
// Run with: `php tools/hmac/HMACValidator.php {hmacKey} {path to JSON file}
6-
// php tools/hmac/HMACValidator.php 51757397D785FBAE710E7F943F307971BB61B21281C98C9129B3D4018A57B2EB tools/hmac/payload.json
6+
// Run with: `php tools/hmac/HMACValidatorBanking.php {hmacKey} {path to JSON file}
7+
// php tools/hmac/HMACValidatorBanking.php 51757397D785FBAE710E7F943F307971BB61B21281C98C9129B3D4018A57B2EB tools/hmac/payload2.json
78

89
require_once __DIR__ . '/../../vendor/autoload.php';
910

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?php
2+
3+
// script to calculate the HMAC signature of Payments webhooks (where the signature is calculated considering
4+
// a subset of the fields in the payload - i.e. NotificationRequestItem object)
5+
//
6+
// Run with: `php tools/hmac/HMACValidatorPayments.php {hmacKey} {path to JSON file}
7+
// php tools/hmac/HMACValidatorPayments.php 51757397D785FBAE710E7F943F307971BB61B21281C98C9129B3D4018A57B2EB tools/hmac/payload.json
8+
9+
require_once __DIR__ . '/../../vendor/autoload.php';
10+
11+
use Adyen\Util\HmacSignature;
12+
13+
if ($argc !== 3) {
14+
echo "Usage: php calculate_hmac.php <hmacKey> <payloadFile>\n";
15+
exit(1);
16+
}
17+
18+
$hmacKey = $argv[1];
19+
$payloadFile = $argv[2];
20+
21+
if (!file_exists($payloadFile)) {
22+
echo "Error: File '$payloadFile' not found.\n";
23+
exit(1);
24+
}
25+
26+
echo "Calculating HMAC signature with payload from '$payloadFile'\n";
27+
28+
// load payload as JSON
29+
$payload = file_get_contents($payloadFile);
30+
$payload = json_decode($payload, true);
31+
32+
// Fetch the first (and only) NotificationRequestItem
33+
$notificationItems = $payload['notificationItems'];
34+
$notificationRequestItem = array_shift($notificationItems);
35+
36+
$hmacSignature = new HmacSignature();
37+
$signature = $hmacSignature->calculateNotificationHMAC($hmacKey, $notificationRequestItem);
38+
39+
echo "HMAC Signature-> $signature\n";
40+
exit(0);

0 commit comments

Comments
 (0)