Skip to content

Commit d4c9a99

Browse files
Moussa Sidibesidibos
authored andcommitted
SDK-676: Add ageVerification to profile page, Introduce profile.inc, Update browser js to 2.2.0
1 parent 40b5327 commit d4c9a99

File tree

5 files changed

+104
-103
lines changed

5 files changed

+104
-103
lines changed

config.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
version = 1.2.1
1+
version = 2.0.0

examples/composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"description": "testing yoti-php-sdk",
33
"require": {
4-
"yoti/yoti-php-sdk": "1.2.*",
4+
"yoti/yoti-php-sdk": "2.0.*",
55
"symfony/dotenv": "3.3.0"
66
}
77
}

examples/index.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
</a>
2222
</div>
2323

24-
<h1 class="yoti-top-header">Business Name now uses Yoti</h1>
24+
<h1 class="yoti-top-header">We now accept Yoti</h1>
2525

2626
<div class="yoti-sdk-integration-section">
2727
<button data-yoti-application-id="<?php echo getenv('YOTI_APP_ID') ?>"
@@ -69,7 +69,7 @@
6969
</section>
7070
</main>
7171

72-
<script src="https://sdk.yoti.com/clients/browser.2.1.0.js"></script>
72+
<script src="https://sdk.yoti.com/clients/browser.2.2.0.js"></script>
7373
<script>
7474
_ybg.init()
7575
</script>

examples/profile.inc.php

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
<?php
2+
3+
// Load dependent packages and env data
4+
require_once __DIR__ . '/bootstrap.php';
5+
6+
// Get the token
7+
$token = isset($_GET['token']) ? $_GET['token'] : '';
8+
$profileAttributes = [];
9+
10+
try {
11+
$yotiClient = new Yoti\YotiClient(getenv('YOTI_SDK_ID'), getenv('YOTI_KEY_FILE_PATH'));
12+
$activityDetails = $yotiClient->getActivityDetails($token);
13+
$profile = $activityDetails->getProfile();
14+
15+
$ageVerifications = $profile->getAgeVerifications();
16+
// Get the first AgeVerification element
17+
$ageVerification = current($ageVerifications);
18+
19+
$profileAttributes = [
20+
[
21+
'name' => 'Given names',
22+
'obj' => $profile->getGivenNames(),
23+
'icon' => 'yoti-icon-profile',
24+
],
25+
[
26+
'name' => 'Family names',
27+
'obj' => $profile->getFamilyName(),
28+
'icon' => 'yoti-icon-profile',
29+
],
30+
[
31+
'name' => 'Mobile number',
32+
'obj' => $profile->getPhoneNumber(),
33+
'icon' => 'yoti-icon-phone',
34+
],
35+
[
36+
'name' => 'Email address',
37+
'obj' => $profile->getEmailAddress(),
38+
'icon' => 'yoti-icon-email',
39+
],
40+
[
41+
'name' => 'Date of birth',
42+
'obj' => $profile->getDateOfBirth(),
43+
'icon' => 'yoti-icon-calendar',
44+
],
45+
[
46+
'name' => 'Age Verification',
47+
'obj' => $ageVerification,
48+
'icon' => 'yoti-icon-calendar',
49+
],
50+
[
51+
'name' => 'Address',
52+
'obj' => $profile->getPostalAddress(),
53+
'icon' => 'yoti-icon-address',
54+
],
55+
[
56+
'name' => 'Gender',
57+
'obj' => $profile->getGender(),
58+
'icon' => 'yoti-icon-gender',
59+
],
60+
[
61+
'name' => 'Nationality',
62+
'obj' => $profile->getNationality(),
63+
'icon' => 'yoti-icon-nationality',
64+
]
65+
];
66+
67+
$ageVerificationStr = '';
68+
if ($ageVerification) {
69+
$result = $ageVerification->getResult() ? 'Yes' : 'No';
70+
$ageVerificationStr = "({$ageVerification->getChecktype()} {$ageVerification->getAge()}) : {$result}";
71+
}
72+
$fullName = $profile->getFullName();
73+
$selfie = $profile->getSelfie();
74+
$selfieFileName = 'selfie.jpeg';
75+
76+
// Create selfie image file.
77+
if ($selfie && is_writable(__DIR__)) {
78+
file_put_contents($selfieFileName, $selfie->getValue()->getContent(), LOCK_EX);
79+
}
80+
} catch(\Exception $e) {
81+
header('Location: /error.php?msg='.$e->getMessage());
82+
exit;
83+
}

examples/profile.php

Lines changed: 17 additions & 99 deletions
Original file line numberDiff line numberDiff line change
@@ -1,84 +1,5 @@
11
<?php
2-
3-
// Load dependent packages and env data
4-
require_once __DIR__ . '/bootstrap.php';
5-
6-
// Get the token
7-
$token = isset($_GET['token']) ? $_GET['token'] : '';
8-
$profileAttributes = [];
9-
10-
try {
11-
$yotiConnectApi = getenv('YOTI_CONNECT_API') ?: Yoti\YotiClient::DEFAULT_CONNECT_API;
12-
$yotiClient = new Yoti\YotiClient(
13-
getenv('YOTI_SDK_ID'),
14-
getenv('YOTI_KEY_FILE_PATH'),
15-
$yotiConnectApi
16-
);
17-
$activityDetails = $yotiClient->getActivityDetails($token);
18-
$profile = $activityDetails->getProfile();
19-
$ageVerifications = $profile->getAgeVerifications();
20-
$ageVerification = current($ageVerifications);
21-
22-
$profileAttributes = [
23-
[
24-
'name' => 'Given names',
25-
'obj' => $profile->getGivenNames(),
26-
'icon' => 'yoti-icon-profile',
27-
],
28-
[
29-
'name' => 'Family names',
30-
'obj' => $profile->getFamilyName(),
31-
'icon' => 'yoti-icon-profile',
32-
],
33-
[
34-
'name' => 'Mobile number',
35-
'obj' => $profile->getPhoneNumber(),
36-
'icon' => 'yoti-icon-phone',
37-
],
38-
[
39-
'name' => 'Email address',
40-
'obj' => $profile->getEmailAddress(),
41-
'icon' => 'yoti-icon-email',
42-
],
43-
[
44-
'name' => 'Date of birth',
45-
'obj' => $profile->getDateOfBirth(),
46-
'icon' => 'yoti-icon-calendar',
47-
],
48-
[
49-
'name' => 'Age Verification',
50-
'obj' => $ageVerification,
51-
'icon' => 'yoti-icon-calendar',
52-
],
53-
[
54-
'name' => 'Address',
55-
'obj' => $profile->getPostalAddress(),
56-
'icon' => 'yoti-icon-address',
57-
],
58-
[
59-
'name' => 'Gender',
60-
'obj' => $profile->getGender(),
61-
'icon' => 'yoti-icon-gender',
62-
],
63-
[
64-
'name' => 'Nationality',
65-
'obj' => $profile->getNationality(),
66-
'icon' => 'yoti-icon-nationality',
67-
]
68-
];
69-
70-
$fullName = $profile->getFullName();
71-
$selfie = $profile->getSelfie();
72-
$selfieFileName = 'selfie.jpeg';
73-
74-
// Create selfie image file.
75-
if ($selfie && is_writable(__DIR__)) {
76-
file_put_contents($selfieFileName, $selfie->getValue()->getContent(), LOCK_EX);
77-
}
78-
} catch(\Exception $e) {
79-
header('Location: /error.php?msg='.$e->getMessage());
80-
exit;
81-
}
2+
require_once __DIR__ . '/profile.inc.php';
823
?>
834
<!DOCTYPE html>
845
<html class="yoti-html">
@@ -101,14 +22,14 @@
10122

10223
<div class="yoti-profile-picture-section">
10324
<?php if ($profile->getSelfie()) : ?>
104-
<div class="yoti-profile-picture-area">
105-
<img src="./<?php echo $selfieFileName ?>" class="yoti-profile-picture-image" alt="Yoti" />
106-
<i class="yoti-profile-picture-verified-icon"></i>
107-
</div>
25+
<div class="yoti-profile-picture-area">
26+
<img src="./<?php echo $selfieFileName ?>" class="yoti-profile-picture-image" alt="Yoti" />
27+
<i class="yoti-profile-picture-verified-icon"></i>
28+
</div>
10829
<?php endif; ?>
10930

11031
<div class="yoti-profile-name">
111-
<?php echo $fullName? $fullName->getValue() : '' ?>
32+
<?php echo $fullName ? $fullName->getValue() : '' ?>
11233
</div>
11334
</div>
11435
</section>
@@ -148,20 +69,17 @@
14869
<?php
14970
$name = $item['name'];
15071
$attributeObj = $item['obj'];
151-
switch($name) {
152-
case 'Date of birth':
153-
$value = $item['obj']->getValue()->format('d-m-Y');
154-
break;
155-
case 'Age Verification':
156-
$attributeObj = $item['obj']->getAttribute();
157-
$result = $ageVerification->getResult() ? 'Yes' : 'No';
158-
$value = $ageVerification->getChecktype() . ':' . $ageVerification->getAge()
159-
. ' ' . $result;
160-
break;
161-
default:
162-
$value = $item['obj']->getValue();
72+
if ($name === 'Date of birth') {
73+
$value = $item['obj']->getValue()->format('d-m-Y');
74+
}
75+
elseif ($name === 'Age Verification') {
76+
// Because AgeVerification::class has a different structure
77+
$attributeObj = $item['obj']->getAttribute();
78+
$value = $ageVerificationStr;
79+
}
80+
else {
81+
$value = $item['obj']->getValue();
16382
}
164-
16583
$anchors = $attributeObj->getAnchors();
16684
?>
16785
<div class="yoti-attribute-value-text"><?php echo $value; ?></div>
@@ -172,7 +90,7 @@
17290
<div class="yoti-attribute-anchors-head -subtype">Sub type</div>
17391

17492
<?php foreach($anchors as $anchor) : ?>
175-
<div class="yoti-attribute-anchors -s-v"><?php echo $anchor->getType(); ?></div>
93+
<div class="yoti-attribute-anchors -s-v"><?php echo $anchor->getType() ?></div>
17694
<div class="yoti-attribute-anchors -value"><?php echo $anchor->getValue() ?></div>
17795
<div class="yoti-attribute-anchors -subtype"><?php echo $anchor->getSubType() ?></div>
17896
<?php endforeach; ?>

0 commit comments

Comments
 (0)