Skip to content

Commit 402df52

Browse files
committed
Add script for Platform webhooks
1 parent 4bcd8c0 commit 402df52

File tree

3 files changed

+122
-0
lines changed

3 files changed

+122
-0
lines changed

tools/hmac/README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,15 @@ npm list @adyen/api-library // check version of library and update if needed
2020
node calculateHmacPayments.js 11223344D785FBAE710E7F943F307971BB61B21281C98C9129B3D4018A57B2EB payload.json
2121
```
2222

23+
### Platform webhooks (AfP, Management API, etc..)
24+
25+
Copy the content of the webhook in the payload2.json (or provide a different file), then run with:
26+
`node calculateHmacPlatform.js {hmacKey} {path to JSON file}`
27+
```
28+
cd tools/hmac
29+
npm install
30+
31+
npm list @adyen/api-library // check version of library and update if needed
32+
33+
node calculateHmacPlatform.js 11223344D785FBAE710E7F943F307971BB61B21281C98C9129B3D4018A57B2EB payload2.json
34+
```

tools/hmac/calculateHmacPlatform.js

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
// script to calculate the HMAC signature of Banking/Management webhooks (where the signature is calculated over the
2+
// entire webhook payload)
3+
//
4+
// Run with: `node calculateHmacPlatform.js {hmacKey} {path to JSON file}`
5+
//
6+
// cd tools/hmac
7+
// node calculateHmacPlatform.js 11223344D785FBAE710E7F943F307971BB61B21281C98C9129B3D4018A57B2EB payload2.json
8+
9+
const fs = require('fs');
10+
const crypto = require('crypto');
11+
12+
// Ensure correct arguments
13+
if (process.argv.length !== 4) {
14+
console.error("Usage: node calculateHmacPlatform.js <hmacKey> <payloadFile>");
15+
process.exit(1);
16+
}
17+
18+
const hmacKey = process.argv[2];
19+
const payloadFile = process.argv[3];
20+
21+
// Check if file exists
22+
if (!fs.existsSync(payloadFile)) {
23+
console.error(`Error: File '${payloadFile}' not found.`);
24+
process.exit(1);
25+
}
26+
27+
console.log(`Calculating HMAC signature with payload from '${payloadFile}'`);
28+
29+
// Load payload as raw string
30+
let payload;
31+
try {
32+
payload = fs.readFileSync(payloadFile, 'utf8');
33+
} catch (error) {
34+
console.error(`Error reading file: ${error.message}`);
35+
process.exit(1);
36+
}
37+
38+
// Calculate HMAC signature
39+
function calculateHmacSignature(hmacKey, payload) {
40+
const key = Buffer.from(hmacKey, 'hex');
41+
const hmac = crypto.createHmac('sha256', key);
42+
hmac.update(payload, 'utf8');
43+
return hmac.digest('base64');
44+
}
45+
46+
const signature = calculateHmacSignature(hmacKey, payload);
47+
48+
console.log(`HMAC signature: ${signature}`);
49+
process.exit(0);

tools/hmac/payload2.json

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
{
2+
"data": {
3+
"balancePlatform": "YOUR_BALANCE_PLATFORM",
4+
"accountHolder": {
5+
"contactDetails": {
6+
"email": "[email protected]",
7+
"phone": {
8+
"number": "0612345678",
9+
"type": "mobile"
10+
},
11+
"address": {
12+
"houseNumberOrName": "23",
13+
"city": "Amsterdam",
14+
"country": "NL",
15+
"postalCode": "12345",
16+
"street": "Main Street 1"
17+
}
18+
},
19+
"description": "Shelly Eller",
20+
"legalEntityId": "LE00000000000000000001",
21+
"reference": "YOUR_REFERENCE-2412C",
22+
"capabilities": {
23+
"issueCard": {
24+
"enabled": true,
25+
"requested": true,
26+
"allowed": false,
27+
"verificationStatus": "pending"
28+
},
29+
"receiveFromTransferInstrument": {
30+
"enabled": true,
31+
"requested": true,
32+
"allowed": false,
33+
"verificationStatus": "pending"
34+
},
35+
"sendToTransferInstrument": {
36+
"enabled": true,
37+
"requested": true,
38+
"allowed": false,
39+
"verificationStatus": "pending"
40+
},
41+
"sendToBalanceAccount": {
42+
"enabled": true,
43+
"requested": true,
44+
"allowed": false,
45+
"verificationStatus": "pending"
46+
},
47+
"receiveFromBalanceAccount": {
48+
"enabled": true,
49+
"requested": true,
50+
"allowed": false,
51+
"verificationStatus": "pending"
52+
}
53+
},
54+
"id": "AH00000000000000000001",
55+
"status": "active"
56+
}
57+
},
58+
"environment": "test",
59+
"timestamp": "2024-12-15T15:42:03+01:00",
60+
"type": "balancePlatform.accountHolder.created"
61+
}

0 commit comments

Comments
 (0)