Skip to content

Commit 5e798e9

Browse files
committed
Added PSD2 and Signed Webhooks examples
1 parent 2e45661 commit 5e798e9

5 files changed

+99
-2
lines changed

.env-example

+4-1
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,7 @@ BRAND_NAME=Acme, Inc.
2727
CODE=
2828
NUMBER=
2929
REQUEST_ID=
30-
WORKFLOW_ID=4
30+
WORKFLOW_ID=4
31+
RECIPIENT_NUMBER=
32+
PAYEE_NAME=
33+
AMOUNT=

composer.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{
22
"require": {
33
"vonage/client": "^2.3",
4-
"vlucas/phpdotenv": "^2.5"
4+
"vlucas/phpdotenv": "^2.5",
5+
"lcobucci/jwt": "^3.0"
56
}
67
}

jwt/decode_incoming_jwt_token.php

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
3+
require_once __DIR__ . '/../vendor/autoload.php';
4+
require_once __DIR__ . '/../config.php';
5+
6+
$headers = getallheaders();
7+
$authHeader = $headers['Authorization'];
8+
$token = substr($authHeader, 7);
9+
10+
$secret = VONAGE_API_SIGNATURE_SECRET;
11+
12+
$key = \Lcobucci\JWT\Signer\Key\InMemory::plainText($secret);
13+
$configuration = \Lcobucci\JWT\Configuration::forSymmetricSigner(
14+
new Lcobucci\JWT\Signer\Hmac\Sha256(),
15+
$key
16+
);
17+
$token = $configuration->parser()->parse($token);
18+
try {
19+
$configuration->validator()->validate(
20+
$token,
21+
new \Lcobucci\JWT\Validation\Constraint\SignedWith($configuration->signer(), $configuration->signingKey())
22+
);
23+
echo 'Token was validated';
24+
} catch (\Exception $e) {
25+
var_dump($e->getMessage());
26+
}

verify/send_psd2_request.php

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php
2+
3+
require_once __DIR__ . '/../config.php';
4+
require_once __DIR__ . '/../vendor/autoload.php';
5+
6+
$basic = new \Vonage\Client\Credentials\Basic(VONAGE_API_KEY, VONAGE_API_SECRET);
7+
$client = new \Vonage\Client(new \Vonage\Client\Credentials\Container($basic));
8+
9+
$request = new \Vonage\Verify\RequestPSD2(RECIPIENT_NUMBER, PAYEE_NAME, AMOUNT);
10+
$response = $client->verify()->requestPSD2($request);
11+
12+
echo "Started verification, `request_id` is " . $response['request_id'];
+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
<?php
2+
require_once __DIR__ . '/../config.php';
3+
require_once __DIR__ . '/../vendor/autoload.php';
4+
5+
$basic = new \Vonage\Client\Credentials\Basic(VONAGE_API_KEY, VONAGE_API_SECRET);
6+
$client = new \Vonage\Client(new \Vonage\Client\Credentials\Container($basic));
7+
8+
$options = getopt('n:w:b:h');
9+
$helpText = <<<ENDHELP
10+
Sends a verification request and allows setting a Workflow ID
11+
12+
Usage:
13+
php request_with_workflow.php -n <NUMBER> [-b <BRAND_NAME>] [-w <WORKFLOW_ID>]
14+
15+
NUMBER the telephone number to send the Verify request to
16+
BRAND_NAME is the name of the company sending the request. Defaults to 'Acme, Inc.'
17+
WORKFLOW_ID is the workflow ID to use. Must be between 1-5
18+
19+
Options can also be passed as environment variables.
20+
21+
ENDHELP;
22+
23+
if (array_key_exists('h', $options)) {
24+
echo $helpText;
25+
exit(1);
26+
}
27+
28+
if (!defined('RECIPIENT_NUMBER')) {
29+
define('RECIPIENT_NUMBER', (array_key_exists('n', $options)) ? $options['n'] : null);
30+
}
31+
32+
if (!defined('PAYEE_NAME')) {
33+
define('PAYEE_NAME', (array_key_exists('b', $options)) ? $options['b'] : 'Acme, Inc');
34+
}
35+
36+
if (!defined('AMOUNT')) {
37+
define('AMOUNT', (array_key_exists('a', $options)) ? $options['a'] : '$10.00');
38+
}
39+
40+
if (!defined('WORKFLOW_ID')) {
41+
define('WORKFLOW_ID', (array_key_exists('w', $options)) ? $options['w'] : 4);
42+
}
43+
44+
if (is_null(RECIPIENT_NUMBER)) {
45+
echo "Please supply a NUMBER to send a verification request to."
46+
. PHP_EOL
47+
. PHP_EOL
48+
. $helpText;
49+
exit(1);
50+
}
51+
52+
$request = new \Vonage\Verify\RequestPSD2(RECIPIENT_NUMBER, BRAND_NAME, AMOUNT, (int) WORKFLOW_ID);
53+
$response = $client->verify()->requestPSD2($request);
54+
55+
echo "Started verification, `request_id` is " . $response['request_id'];

0 commit comments

Comments
 (0)