PHP

verisec/verisec-php is the official library for PHP 8.1 and later. Packagist

Install#

Terminal
composer require verisec/verisec-php

Create a client#

PHP
use VeriSec\Client;

$client = new Client(getenv('VERISEC_API_KEY')); // sk_test_…

With no key argument, the client reads VERISEC_API_KEY. Options: timeout in seconds per attempt (default 300), max_retries (default 2) and headers.

Make a call#

Every endpoint is a method named after its operation: face.verify is $client->face->verify(), age.verifyLive is $client->age->verifyLive(). Field names are exactly the API's.

PHP
$result = $client->face->verify([
    'image1' => 'selfie.jpg',
    'image2' => 'id-photo.jpg',
    'threshold' => 0.8,
]);

$cheque = $client->cheques->read(['image' => 'cheque.jpg']);

An image can be a file path, an open stream, VeriSec\Image::fromBytes($bytes), a data: URI or base64.

Errors#

PHP
use VeriSec\Exception\ApiConnectionException;
use VeriSec\Exception\ApiException;
use VeriSec\Exception\InsufficientCreditsException;
use VeriSec\Exception\InvalidRequestException;
use VeriSec\Exception\RateLimitException;

try {
    $client->face->verify(['image1' => 'selfie.jpg', 'image2' => 'id-photo.jpg']);
} catch (InsufficientCreditsException $e) {
    echo 'Top up credits.';                          // 402: nothing was charged
} catch (InvalidRequestException $e) {
    echo $e->getErrorCode(), ' ', $e->getParam(), ' ', $e->getMessage();
} catch (RateLimitException $e) {
    echo 'Wait ', $e->getRetryAfter(), ' s.';
} catch (ApiException $e) {
    echo $e->getHttpStatus(), ' ', $e->getErrorCode(), ' ', $e->getRequestId();
} catch (ApiConnectionException $e) {
    // $e->wasNeverSent() is true when the request never reached the server
}

Webhooks#

PHP
use VeriSec\Webhook;

$event = Webhook::constructEvent(file_get_contents('php://input'), getallheaders(), getenv('VERISEC_WEBHOOK_SECRET'));

See Webhooks for a full handler.