File tree Expand file tree Collapse file tree 2 files changed +44
-3
lines changed
Expand file tree Collapse file tree 2 files changed +44
-3
lines changed Original file line number Diff line number Diff line change 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
89require_once __DIR__ . '/../../vendor/autoload.php ' ;
910
Original file line number Diff line number Diff line change 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 );
You can’t perform that action at this time.
0 commit comments