alexstewartja / php-didit
PHP SDK for Didit's identity verification (KYC) and authentication (CIAM) solutions
Fund package maintenance!
alexstewartja
Buy Me A Coffee
Requires
- php: ^8.1 || ^8.2 || ^8.3 || ^8.4
- ext-json: *
- ext-reflection: *
- php-http/guzzle7-adapter: ^1.1
Requires (Dev)
- laravel/pint: ^1.14
- pestphp/pest: ^2.36
- phpstan/extension-installer: ^1.3||^2.0
- phpstan/phpstan-deprecation-rules: ^1.1||^2.0
- phpstan/phpstan-phpunit: ^1.3||^2.0
README
PHP Didit
PHP SDK for Didit's identity verification (KYC) and authentication (CIAM) solutions
Features
- ✅ Verification
- ⏳ Auth
- ⏳ Data
Installation
You can install the package via composer:
composer require alexstewartja/php-didit
Usage
Get Access Token
Supply the Client ID and Client Secret of your application, from the Didit console:
// Replace these example credentials with your own... $client_id = 'AcL8JK38FqNPmx20qrd3-b'; $client_secret = 'QuajPJsV0sKiQ3M33fd4RK2rVofEmHXLolKW_ZeyeNL'; $token_info = Didit::getAccessToken($client_id, $client_secret); $access_token = $token_info->getAccessToken(); // Store your access token securely...
Create a Verification Session
After obtaining a valid client access token, you can then create a new verification session:
$access_token = 'eyJhbGciOiAiUlMyNTYiLCAidHlwIjogIkpXVCJ9...'; // Retrieved from secure storage $vendor_data = 'c4afad98-e044-4a5f-b68f-5ffaaaefe6a0'; // Commonly, a unique id/uuid of the user in your application $callback = 'https://verify.didit.me/'; // URL to redirect your user after they complete verification $features = VerificationFeatures::OCR_FACE; // Optional verification features to enable $session = Didit::createVerificationSession($access_token, $vendor_data, $callback); $session_id = $session->getSessionId(); // Store your session ID for future reference, commonly as part of your user record... $session_url = $session->getSessionUrl(); // Redirect your user to the verification URL...
Retrieve a Verification Session
Retrieve the results of a verification session by supplying its session_id
:
$access_token = 'eyJhbGciOiAiUlMyNTYiLCAidHlwIjogIkpXVCJ9...'; // Retrieved from secure storage $session_id = 'e8933296-fa3b-4a7a-9c99-b132d34b19fc'; // Retrieved from user record $session = Didit::getVerificationSession($access_token, $session_id);
Update a Verification Session Status
You may approve or decline a verification, by updating its status to Approved
or Declined
respectively:
$access_token = 'eyJhbGciOiAiUlMyNTYiLCAidHlwIjogIkpXVCJ9...'; // Retrieved from secure storage $session_id = 'e8933296-fa3b-4a7a-9c99-b132d34b19fc'; // Retrieved from user record $new_status = VerificationStatus::DECLINED; $comment = 'User is from a country that is no longer supported'; // Optional comment/reason for review $declined = Didit::updateVerificationSessionStatus($access_token, $session_id, $new_status, $comment); if ($declined) { // Status update was successful... }
Generate a Verification PDF Report
You can generate a PDF for sessions that are either In Review
, Declined
or Approved
:
$access_token = 'eyJhbGciOiAiUlMyNTYiLCAidHlwIjogIkpXVCJ9...'; // Retrieved from secure storage $session_id = 'e8933296-fa3b-4a7a-9c99-b132d34b19fc'; // Retrieved from user record $save_to = './session_pdf_downloads/session.pdf'; // Optional file path to store generated PDF $generated = Didit::generateVerificationSessionPdf($access_token, $session_id, $save_to); if ($generated) { // PDF generated and stored successfully... }
ℹ️ If no
$save_to
path is supplied, an instance ofPsr\Http\Message\StreamInterface
will be returned, allowing for further processing.
Testing
-
Navigate to the
tests/assets
directory and copycredentials.json.example
tocredentials.json
:cp tests/assets/credentials.json.example tests/assets/credentials.json
-
Open
tests/assets/credentials.json
. Enter your Client ID and Client Secret into theclient_id
andclient_secret
fields, respectively. -
Run the test suite:
composer test
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
A Lando file is included in the repo to get up and running quickly:
lando start
Please see CONTRIBUTING for more details.
Security
If you discover any security related issues, please email didit@alexstewartja.com instead of using the issue tracker.
Credits
License
The MIT License (MIT). Please see License File for more information.