Skip to content

Commit e5010f4

Browse files
committed
Fetch notificationRequestItem from payload
1 parent 3d98d4c commit e5010f4

File tree

1 file changed

+20
-3
lines changed

1 file changed

+20
-3
lines changed

tools/hmac/HMACValidatorPayments.php

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,28 @@
2727

2828
// load payload as JSON
2929
$payload = file_get_contents($payloadFile);
30-
$payload = json_decode($payload, true);
30+
$jsonData = json_decode($payload, true);
31+
32+
if (json_last_error() !== JSON_ERROR_NONE) {
33+
echo "Error: Invalid JSON in payload file.\n";
34+
exit(1);
35+
}
36+
37+
if (!isset($jsonData['notificationItems']) || !is_array($jsonData['notificationItems'])) {
38+
echo "Error: 'notificationItems' key is missing or not an array.\n";
39+
exit(1);
40+
}
3141

3242
// Fetch the first (and only) NotificationRequestItem
33-
$notificationItems = $payload['notificationItems'];
34-
$notificationRequestItem = array_shift($notificationItems);
43+
$notificationRequestItem = $jsonData['notificationItems'][0]['NotificationRequestItem'] ?? null;
44+
45+
if ($notificationRequestItem === null) {
46+
echo "Error: 'NotificationRequestItem' is not found.\n";
47+
exit(1);
48+
}
49+
50+
// Log notificationRequestItem
51+
//print_r($notificationRequestItem);
3552

3653
$hmacSignature = new HmacSignature();
3754
$signature = $hmacSignature->calculateNotificationHMAC($hmacKey, $notificationRequestItem);

0 commit comments

Comments
 (0)