|
| 1 | +# PHP Didit |
| 2 | + |
| 3 | +[](https://packagist.org/packages/alexstewartja/php-didit) |
| 4 | + |
| 5 | +[](https://packagist.org/packages/alexstewartja/php-didit) |
| 6 | +[](https://packagist.org/packages/alexstewartja/php-didit) |
| 7 | +[](https://packagist.org/packages/alexstewartja/php-didit) |
| 8 | +[](https://buymeacoffee.com/alexstewartja) |
| 9 | + |
| 10 | +PHP SDK for [Didit](https://didit.me/business)'s identity verification (KYC) and authentication (CIAM) solutions |
| 11 | + |
| 12 | +## Features |
| 13 | + |
| 14 | +- :white_check_mark: [Verification](https://docs.didit.me/identity-verification/full-flow) |
| 15 | +- :hourglass_flowing_sand: [Auth](https://docs.didit.me/auth-and-data/sign-in-api-reference/full-flow) |
| 16 | +- :hourglass_flowing_sand: [Data](https://docs.didit.me/auth-and-data/data-api-reference/full-flow) |
| 17 | + |
| 18 | +## Installation |
| 19 | + |
| 20 | +You can install the package via composer: |
| 21 | + |
| 22 | +```bash |
| 23 | +composer require alexstewartja/php-didit |
| 24 | +``` |
| 25 | + |
| 26 | +## Usage |
| 27 | + |
| 28 | +### Get Access Token |
| 29 | + |
| 30 | +Supply |
| 31 | +the [Client ID and Client Secret](https://docs.didit.me/identity-verification/quick-start#configure-verification-settings) |
| 32 | +of your application, from the Didit console: |
| 33 | + |
| 34 | +```php |
| 35 | +// Replace these example credentials with your own... |
| 36 | +$client_id = 'AcL8JK38FqNPmx20qrd3-b'; |
| 37 | +$client_secret = 'QuajPJsV0sKiQ3M33fd4RK2rVofEmHXLolKW_ZeyeNL'; |
| 38 | + |
| 39 | +$token_info = Didit::getAccessToken($client_id, $client_secret); |
| 40 | +$access_token = $token_info->getAccessToken(); |
| 41 | +// Store your access token securely... |
| 42 | +``` |
| 43 | + |
| 44 | +### Create a Verification Session |
| 45 | + |
| 46 | +After obtaining a valid client access token, you can then create a new verification session: |
| 47 | + |
| 48 | +```php |
| 49 | +$access_token = 'eyJhbGciOiAiUlMyNTYiLCAidHlwIjogIkpXVCJ9...'; // Retrieved from secure storage |
| 50 | +$vendor_data = 'c4afad98-e044-4a5f-b68f-5ffaaaefe6a0'; // Commonly, a unique id/uuid of the user in your application |
| 51 | +$callback = 'https://verify.didit.me/'; // URL to redirect your user after they complete verification |
| 52 | +$features = VerificationFeatures::OCR_FACE; // Optional verification features to enable |
| 53 | + |
| 54 | +$session = Didit::createVerificationSession($access_token, $vendor_data, $callback); |
| 55 | +$session_id = $session->getSessionId(); |
| 56 | +// Store your session ID for future reference, commonly as part of your user record... |
| 57 | +$session_url = $session->getSessionUrl(); |
| 58 | +// Redirect your user to the verification URL... |
| 59 | +``` |
| 60 | + |
| 61 | +### Retrieve a Verification Session |
| 62 | + |
| 63 | +Retrieve the results of a verification session by supplying its `session_id`: |
| 64 | + |
| 65 | +```php |
| 66 | +$access_token = 'eyJhbGciOiAiUlMyNTYiLCAidHlwIjogIkpXVCJ9...'; // Retrieved from secure storage |
| 67 | +$session_id = 'e8933296-fa3b-4a7a-9c99-b132d34b19fc'; // Retrieved from user record |
| 68 | + |
| 69 | +$session = Didit::getVerificationSession($access_token, $session_id); |
| 70 | +``` |
| 71 | + |
| 72 | +### Update a Verification Session Status |
| 73 | + |
| 74 | +You may approve or decline a verification, by updating its status to `Approved` or `Declined` respectively: |
| 75 | + |
| 76 | +```php |
| 77 | +$access_token = 'eyJhbGciOiAiUlMyNTYiLCAidHlwIjogIkpXVCJ9...'; // Retrieved from secure storage |
| 78 | +$session_id = 'e8933296-fa3b-4a7a-9c99-b132d34b19fc'; // Retrieved from user record |
| 79 | +$new_status = VerificationStatus::DECLINED; |
| 80 | +$comment = 'User is from a country that is no longer supported'; // Optional comment/reason for review |
| 81 | + |
| 82 | +$declined = Didit::updateVerificationSessionStatus($access_token, $session_id, $new_status, $comment); |
| 83 | +if ($declined) { |
| 84 | + // Status update was successful... |
| 85 | +} |
| 86 | +``` |
| 87 | + |
| 88 | +### Generate a Verification PDF Report |
| 89 | + |
| 90 | +You can generate a PDF for sessions that are either `In Review`, `Declined` or `Approved`: |
| 91 | + |
| 92 | +```php |
| 93 | +$access_token = 'eyJhbGciOiAiUlMyNTYiLCAidHlwIjogIkpXVCJ9...'; // Retrieved from secure storage |
| 94 | +$session_id = 'e8933296-fa3b-4a7a-9c99-b132d34b19fc'; // Retrieved from user record |
| 95 | +$save_to = './session_pdf_downloads/session.pdf'; // Optional file path to store generated PDF |
| 96 | + |
| 97 | +$generated = Didit::generateVerificationSessionPdf($access_token, $session_id, $save_to); |
| 98 | +if ($generated) { |
| 99 | + // PDF generated and stored successfully... |
| 100 | +} |
| 101 | +``` |
| 102 | + |
| 103 | +> :information_source: If no `$save_to` path is supplied, an instance of `Psr\Http\Message\StreamInterface` |
| 104 | +> will be returned, allowing for further processing. |
| 105 | +
|
| 106 | +## Testing |
| 107 | + |
| 108 | +1. Navigate to the `tests/assets` directory and copy `credentials.json.example` to `credentials.json`: |
| 109 | + ```bash |
| 110 | + cp tests/assets/credentials.json.example tests/assets/credentials.json |
| 111 | + ``` |
| 112 | +2. Open `tests/assets/credentials.json`. Enter |
| 113 | + your [Client ID and Client Secret](https://docs.didit.me/identity-verification/quick-start#configure-verification-settings) |
| 114 | + into the `client_id` and |
| 115 | + `client_secret` fields, respectively. |
| 116 | + |
| 117 | +3. Run the test suite: |
| 118 | + ```bash |
| 119 | + composer test |
| 120 | + ``` |
| 121 | + |
| 122 | +## Changelog |
| 123 | + |
| 124 | +Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently. |
| 125 | + |
| 126 | +## Contributing |
| 127 | + |
| 128 | +A [Lando](https://lando.dev/) file is included in the repo to get up and running quickly: |
| 129 | + |
| 130 | +```bash |
| 131 | +lando start |
| 132 | +``` |
| 133 | + |
| 134 | +Please see [CONTRIBUTING](CONTRIBUTING.md) for more details. |
| 135 | + |
| 136 | +## Security |
| 137 | + |
| 138 | +If you discover any security related issues, please |
| 139 | +email [ [email protected]](mailto: [email protected]?Subject=PHP%20Didit) instead of |
| 140 | +using the issue tracker. |
| 141 | + |
| 142 | +## Credits |
| 143 | + |
| 144 | +- [Alex Stewart](https://github.com/alexstewartja) |
| 145 | +- [All Contributors](../../contributors) |
| 146 | + |
| 147 | +## License |
| 148 | + |
| 149 | +The MIT License (MIT). Please see [License File](LICENSE.md) for more information. |
0 commit comments