Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added example for dbs and updated failure details #362

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "yoti/yoti-php-sdk",
"description": "Yoti SDK for quickly integrating your PHP backend with Yoti",
"version": "4.2.2",
"version": "4.3.0",
"keywords": [
"yoti",
"sdk"
Expand Down Expand Up @@ -66,4 +66,4 @@
"phpstan/extension-installer": true
}
}
}
}
53 changes: 53 additions & 0 deletions examples/digitalidentity/app/Http/Controllers/DbsController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?php

namespace App\Http\Controllers;

use Illuminate\Routing\Controller as BaseController;
use Illuminate\Support\Facades\Log;
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
use Yoti\DigitalIdentityClient;
use Yoti\Identity\Policy\PolicyBuilder;
use Yoti\Identity\ShareSessionRequestBuilder;

class DbsController extends BaseController
{
public function generateSession(DigitalIdentityClient $client)
{
try {
$policy = (new PolicyBuilder())
->withIdentityProfileRequirements((object)[
'trust_framework' => 'UK_TFIDA',
'scheme' => [
'type' => 'DBS',
'objective' => 'BASIC'
]
])
->build();

$redirectUri = 'https://host/redirect/';

$shareSessionRequest = (new ShareSessionRequestBuilder())
->withPolicy($policy)
->withRedirectUri($redirectUri)
->build();
$session = $client->createShareSession($shareSessionRequest);
return $session->getId();
}
catch (\Throwable $e) {
Log::error($e->getTraceAsString());
throw new BadRequestHttpException($e->getMessage());
}
}
public function show(DigitalIdentityClient $client)
{
try {
return view('dbs', [
'title' => 'Digital Identity DBS Check Example',
'sdkId' => $client->id
]);
} catch (\Throwable $e) {
Log::error($e->getTraceAsString());
throw new BadRequestHttpException($e->getMessage());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use Yoti\Profile\Attribute;
use Yoti\Profile\UserProfile;
use Yoti\Util\Logger;
use Yoti\Exception\ActivityDetailsException;
class ReceiptController extends BaseController
{
public function show(Request $request, DigitalIdentityClient $client, ?LoggerInterface $logger = null)
Expand All @@ -17,14 +18,25 @@ public function show(Request $request, DigitalIdentityClient $client, ?LoggerInt

$logger->warning("Unknown Content Type parsing as a String");
$shareReceipt = $client->fetchShareReceipt($request->query('ReceiptID'));

$profile = $shareReceipt->getProfile();

return view('receipt', [
'fullName' => $profile->getFullName(),
'selfie' => $profile->getSelfie(),
'profileAttributes' => $this->createAttributesDisplayList($profile),
]);
if ($shareReceipt->getError() != null)
{
error_log($shareReceipt->getErrorReason()->getRequirementNotMetDetails()->getDocumentCountryIsoCode());
return view('receipt', [
'fullName' => null,
'selfie' => null,
'profileAttributes' => null,
'error' => $shareReceipt->getErrorReason()
]);
}
else {
$profile = $shareReceipt->getProfile();
return view('receipt', [
'fullName' => $profile->getFullName(),
'selfie' => $profile->getSelfie(),
'profileAttributes' => $this->createAttributesDisplayList($profile),
'error' => null
]);
}
}

/**
Expand Down
89 changes: 89 additions & 0 deletions examples/digitalidentity/resources/views/dbs.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
<!DOCTYPE html>
<html class="yoti-html">

<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<title>{{ $title }}</title>
<link rel="stylesheet" type="text/css" href="assets/css/index.css">
<link href="https://fonts.googleapis.com/css?family=Roboto:400,700" rel="stylesheet">
</head>

<body class="yoti-body">
<main>
<section class="yoti-top-section">
<div class="yoti-logo-section">
<a href="https://www.yoti.com" target="_blank">
<img class="yoti-logo-image" src="assets/images/logo.png" srcset="assets/images/[email protected] 2x"
alt="Yoti"/>
</a>
</div>
<h1 class="yoti-top-header">Digital Identity DBS Ckeck Example</h1>

<div class="yoti-sdk-integration-section">
<div id="webshare-target"></div>
</div>

</section>

<section class="yoti-sponsor-app-section">
<h3 class="yoti-sponsor-app-header">The Yoti app is free to download and use:</h3>

<div class="yoti-store-buttons-section">
<a href="https://itunes.apple.com/us/app/yoti/id983980808?ls=1&mt=8" class="yoti-app-button-link">
<img src="assets/images/app-store-badge.png"
srcset="assets/images/[email protected] 2x"
alt="Download on the App Store" />
</a>

<a href="https://play.google.com/store/apps/details?id=com.yoti.mobile.android.live" class="yoti-app-button-link">
<img src="assets/images/google-play-badge.png"
srcset="assets/images/[email protected] 2x"
alt="get it on Google Play" />
</a>
</div>
</section>
</main>
<script>async function onSessionIdResolver() {
const response = await fetch('/generate-advanced-identity-session');
if (!response.ok) {
throw new Error('Response was not ok');
}
const result = await response.text();
console.log("session id %s", result);
return result;
}

async function completionHandler(receivedReceiptId) {
console.log('completion handler:', receivedReceiptId)
const url = '/receipt-info?ReceiptID=' + encodeURIComponent(receivedReceiptId);
window.location.href = url;
}

function onErrorListener(...data) {
console.warn('onErrorListener:', ...data)
}

async function onReadyToStart() {
const { Yoti } = window
await Yoti.createWebShare({
name: 'Use Yoti',
domId: 'webshare-target',
sdkId: '{{$sdkId}}',
hooks: {
sessionIdResolver: onSessionIdResolver,
errorListener: onErrorListener,
completionHandler,
},
flow: "REVEAL_MODAL"
})
}

async function onClientLoaded() {
const { Yoti } = window
await Yoti.ready()
await onReadyToStart()
}</script>
<script src="https://www.yoti.com/share/client/v2" onload="onClientLoaded()"></script>
</body>
</html>
87 changes: 51 additions & 36 deletions examples/digitalidentity/resources/views/partial/report.blade.php
Original file line number Diff line number Diff line change
@@ -1,39 +1,54 @@
@foreach ($report as $key => $value)
<table>
<thead>
<tr>
<td>
<H2>{{ $key }}</H2>
</td>
</tr>
</thead>
<tbody>
@foreach ($value as $name => $result)
@if (is_array($result))
@foreach ($result as $data => $view)
@if (is_array($view))
@foreach ($view as $key2 => $value2)
@if (is_array($value2))
{{json_encode($value2)}}
@else
<tr>
<td><b>{{ $key2 }}</b><br>{{ $value2 }}</td>
</tr>
@endif
@endforeach
@else
<tr>
<td><b>{{ $data }}</b><br>{{ $view }}</td>
</tr>
@endif
@endforeach
@else
<tr>
@if (isset($key) && is_array($key))
@foreach ($report as $key => $value)
<table>
<thead>
<tr>
<td>
<H2>{{ $key }}</H2>
</td>
</tr>
</thead>
<tbody>
@foreach ($value as $name => $result)
@if (isset($result) && is_array($result))
@foreach ($result as $data => $view)
@if (is_array($view))
@foreach ($view as $key2 => $value2)
@if (is_array($value2))
{{json_encode($value2)}}
@else
<tr>
<td><b>{{ $key2 }}</b><br>{{ $value2 }}</td>
</tr>
@endif
@endforeach
@else
<tr>
<td><b>{{ $data }}</b><br>{{ $view }}</td>
</tr>
@endif
@endforeach
@else
<tr>
<td><b>{{ $name }}</b><br>{{ $result }}</td>
</tr>
@endif
@endforeach
</tr>
@endif
@endforeach

</tbody>
</table>
</tbody>
</table>
@endforeach
@else
<table>
@foreach ($report as $key => $value)
<tr>
<td>
{{ $key }}<br/>
<pre>
{!! json_encode($value, JSON_PRETTY_PRINT) !!}
</pre>
</td>
</tr>
@endforeach
</table>
@endif
29 changes: 29 additions & 0 deletions examples/digitalidentity/resources/views/receipt.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,37 @@
</section>

<section class="yoti-attributes-section">

<a href="/">
<img class="yoti-company-logo" src="/assets/images/company-logo.jpg" alt="company logo">
</a>
@if ($error)
<div class="yoti-attribute-list-header">
<div class="yoti-attribute-list-header-attribute"><b>Errors</b></div>
<div class="yoti-attribute-list-header-value"> </div>
</div>
<div class="yoti-attribute-list-header">
<div class="yoti-attribute-list-header-attribute">Audit Id</div>
<div class="yoti-attribute-list-header-value">{{ $error->getRequirementNotMetDetails()->getAuditId() }}</div>
</div>
<div class="yoti-attribute-list-header">
<div class="yoti-attribute-list-header-attribute">Details</div>
<div class="yoti-attribute-list-header-value">{{ $error->getRequirementNotMetDetails()->getDetails() }}</div>
</div>
<div class="yoti-attribute-list-header">
<div class="yoti-attribute-list-header-attribute">Failure Type</div>
<div class="yoti-attribute-list-header-value">{{ $error->getRequirementNotMetDetails()->getFailureType() }}</div>
</div>
<div class="yoti-attribute-list-header">
<div class="yoti-attribute-list-header-attribute">Document Type</div>
<div class="yoti-attribute-list-header-value">{{ $error->getRequirementNotMetDetails()->getDocumentType() }}</div>
</div>
<div class="yoti-attribute-list-header">
<div class="yoti-attribute-list-header-attribute">Country</div>
<div class="yoti-attribute-list-header-value">{{ $error->getRequirementNotMetDetails()->getDocumentCountryIsoCode() }}</div>
</div>

@endif
<div class="yoti-attribute-list-header">
<div class="yoti-attribute-list-header-attribute">Attribute</div>
<div class="yoti-attribute-list-header-value">Value</div>
Expand All @@ -55,6 +82,7 @@
</div>

<div class="yoti-attribute-list">
@if(@$profileAttributes)
@foreach($profileAttributes as $item)
@if ($item['obj'])
<div class="yoti-attribute-list-item">
Expand Down Expand Up @@ -96,6 +124,7 @@
</div>
@endif
@endforeach
@endif
</div>
</section>
</main>
Expand Down
2 changes: 2 additions & 0 deletions examples/digitalidentity/routes/web.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,5 @@
Route::get('/generate-session', 'IdentityController@generateSession');
Route::get('/generate-advanced-identity-share', 'AdvancedIdentityController@show');
Route::get('/generate-advanced-identity-session', 'AdvancedIdentityController@generateSession');
Route::get('/generate-dbs-share', 'DbsController@show');
Route::get('/generate-dbs-session', 'DbsController@generateSession');
Loading
Loading