Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .env-example
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,10 @@ MESSAGES_APPLICATION_ID=12a3b4cd-a1b2-1ab2-a1b2-a1234bc5d678
VOICE_CALLBACK_TYPE=tel
VOICE_CALLBACK_VALUE=447700900002
VOICE_STATUS_URL=https://example.com/webhooks/status

# Verify API examples
BRAND_NAME=Acme, Inc.
CODE=
NUMBER=
REQUEST_ID=
WORKFLOW_ID=4
2 changes: 1 addition & 1 deletion verify/request.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
$basic = new \Nexmo\Client\Credentials\Basic(NEXMO_API_KEY, NEXMO_API_SECRET);
$client = new \Nexmo\Client(new \Nexmo\Client\Credentials\Container($basic));

$verification = new \Nexmo\Verify\Verification(RECIPIENT_NUMBER, 'Acme Inc');
$verification = new \Nexmo\Verify\Verification(NUMBER, 'Acme Inc');
$client->verify()->start($verification);

echo "Started verification, `request_id` is " . $verification->getRequestId();
52 changes: 52 additions & 0 deletions verify/request_with_workflow.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?php
require_once __DIR__ . '/../config.php';
require_once __DIR__ . '/../vendor/autoload.php';

$basic = new \Nexmo\Client\Credentials\Basic(NEXMO_API_KEY, NEXMO_API_SECRET);
$client = new \Nexmo\Client(new \Nexmo\Client\Credentials\Container($basic));

$options = getopt('n:w:b:h');
$helpText = <<<ENDHELP
Sends a verification request and allows setting a Workflow ID

Usage:
php request_with_workflow.php -n <NUMBER> [-b <BRAND_NAME>] [-w <WORKFLOW_ID>]

NUMBER the telephone number to send the Verify request to
BRAND_NAME is the name of the company sending the request. Defaults to 'Acme, Inc.'
WORKFLOW_ID is the workflow ID to use. Must be between 1-5

Options can also be passed as environment variables.

ENDHELP;

if (array_key_exists('h', $options)) {
echo $helpText;
exit(1);
}

if (!defined('NUMBER')) {
define('NUMBER', (array_key_exists('n', $options)) ? $options['n'] : null);
}

if (!defined('BRAND_NAME')) {
define('BRAND_NAME', (array_key_exists('b', $options)) ? $options['b'] : 'Acme, Inc');
}

if (!defined('WORKFLOW_ID')) {
define('WORKFLOW_ID', (array_key_exists('w', $options)) ? $options['w'] : 4);
}

if (is_null(NUMBER)) {
echo "Please supply a NUMBER to send a verification request to."
. PHP_EOL
. PHP_EOL
. $helpText
;
exit(1);
}

$verification = new \Nexmo\Verify\Verification(NUMBER, BRAND_NAME, ['workflow_id' => WORKFLOW_ID]);
$client->verify()->start($verification);

echo "Started verification, `request_id` is " . $verification->getRequestId();
46 changes: 46 additions & 0 deletions verify/search.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php
require_once __DIR__ . '/../config.php';
require_once __DIR__ . '/../vendor/autoload.php';

$basic = new \Nexmo\Client\Credentials\Basic(NEXMO_API_KEY, NEXMO_API_SECRET);
$client = new \Nexmo\Client(new \Nexmo\Client\Credentials\Container($basic));

$options = getopt('h');
$helpText = <<<ENDHELP
Searches for a verify request

Usage:
php search.php <REQUEST_ID>

REQUEST_ID is the ID of a verification event

ENDHELP;

if (array_key_exists('h', $options)) {
echo $helpText;
exit(1);
}

if (!defined('REQUEST_ID')) {
define('REQUEST_ID', (array_key_exists(1, $argv)) ? $argv[1] : null);
}

if (is_null(REQUEST_ID)) {
echo "Please supply a REQUEST_ID to search for."
. PHP_EOL
. PHP_EOL
. $helpText
;
exit(1);
}

try {
$result = $client->verify()->search(REQUEST_ID);
echo "Request has a status of " . $result->getStatus() . PHP_EOL;
} catch (\Nexmo\Client\Exception\Request $e) {
error_log("Client error: " . $e->getMessage());
exit(1);
} catch (\Nexmo\Client\Exception\Server $e) {
error_log("Server error: " . $e->getMessage());
exit(1);
}