Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
Added snippets for searching and sending a verify with a specified wo…
…rkflow ID
  • Loading branch information
dragonmantank committed Oct 15, 2019
commit efd9bcb3a1844f9bdeb8dcc522124a3b03a722e0
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);
}