| 123456789101112131415161718192021222324 |
- <?php
- require __DIR__ . '/../../helpers/PayStack.php';
- use common\helpers\PayStack;
- $body = '{"event":"charge.success","data":{"reference":"OS123"}}';
- $secret = 'standalone-test-secret';
- $signature = hash_hmac('sha512', $body, $secret);
- $checks = [
- 'accepts the matching SHA512 signature' => PayStack::verifyWebhookSignature($body, $signature, $secret),
- 'rejects a different signature' => !PayStack::verifyWebhookSignature($body, str_repeat('0', 128), $secret),
- 'rejects an empty signature' => !PayStack::verifyWebhookSignature($body, '', $secret),
- 'signature binds to the raw request body' => !PayStack::verifyWebhookSignature($body . ' ', $signature, $secret),
- ];
- foreach ($checks as $description => $passed) {
- if (!$passed) {
- fwrite(STDERR, "FAIL: {$description}\n");
- exit(1);
- }
- }
- echo 'PASS: ' . count($checks) . " PayStack signature checks\n";
|