1. Go to this page and download the library: Download proofage/php-sdk library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
proofage / php-sdk example snippets
use ProofAge\Sdk\Client;
$client = new Client([
'api_key' => getenv('PROOFAGE_API_KEY'),
'secret_key' => getenv('PROOFAGE_SECRET_KEY'),
'base_url' => 'https://api.proofage.net',
]);
$workspace = $client->workspace()->get();
$reverification = $client->verifications()->create([
'external_id' => 'student-42',
'reference_verification_id' => $kycVerificationId, // an approved document verification of the same workspace
]);
// Send the person to $reverification['url']; the decision arrives by webhook.
$verification = $client->verifications()->find($reverification['id']);
$verification['reauth']; // ['reference_verification_id' => ..., 'reference_verified_at' => ...]
$subscription = $client->webhookSubscriptions()->create([
'url' => 'https://hooks.zapier.com/hooks/standard/12345678/abcdef/',
'statuses' => ['approved', 'declined'], // omit or null for every decision status
'
use ProofAge\Sdk\Exceptions\AuthenticationException; // 401
use ProofAge\Sdk\Exceptions\ValidationException; // 422, getErrors()
use ProofAge\Sdk\Exceptions\TransportException; // connection refused, DNS, TLS, timeout
use ProofAge\Sdk\Exceptions\ProofAgeException; // every other non-2xx, and the base class
use ProofAge\Sdk\Exceptions\ExceptionInterface; // marker: catch the whole family
try {
$client->verifications()->create($data);
} catch (ValidationException $e) {
$errors = $e->getErrors();
} catch (TransportException $e) {
// no response: $e->getResponse() is null, $e->getCode() is the cURL errno
} catch (ProofAgeException $e) {
$e->getCode(); // HTTP status
$e->getErrorCode(); // e.g. MEDIA_NOT_FOUND, PAYMENT_METHOD_REQUIRED, FACE_NOT_FOUND; null when the body has none
$e->getErrorData(); // the `error` object, or the whole body when it is not nested
$e->getResponse(); // ProofAge\Sdk\Http\Response
}
use ProofAge\Sdk\Webhooks\WebhookVerifier;
use ProofAge\Sdk\Exceptions\WebhookVerificationException;
$verifier = new WebhookVerifier(getenv('PROOFAGE_API_KEY'), getenv('PROOFAGE_SECRET_KEY'));
try {
$verifier->verifyHeaders(getallheaders(), file_get_contents('php://input'));
} catch (WebhookVerificationException $e) {
http_response_code($e->statusCode);
echo json_encode($e->toArray()); // {"error": {"code": "INVALID_SIGNATURE", "message": "..."}}
exit;
}
use ProofAge\Sdk\Enums\WebhookEvent;
$body = json_decode($rawBody, true);
if (WebhookEvent::tryFrom($body['event'] ?? 'status.updated') === WebhookEvent::DATA_UPDATED) {
// refresh the stored document fields; this is not a new decision
http_response_code(200);
exit;
}
use ProofAge\Sdk\Http\Request;
use ProofAge\Sdk\Http\Response;
$client->pushMiddleware(function (Request $request, callable $next): Response {
return $next($request->withHeader('X-Request-Id', bin2hex(random_bytes(8))));
}, 'request-id');
// Once per logical call rather than per attempt:
$client->pushMiddleware(function (Request $request, callable $next): Response {
if ($request->attempt === 1) {
$quota->consume();
}
return $next($request);
});
$client->removeMiddleware('request-id');
use ProofAge\Sdk\Http\Psr18\Psr18HttpClient;
$factory = new \GuzzleHttp\Psr7\HttpFactory;
$transport = new Psr18HttpClient(new \GuzzleHttp\Client(['timeout' => 30]), $factory, $factory);
$client = new Client($config, $transport);