-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathReceiptController.php
More file actions
135 lines (127 loc) · 5.56 KB
/
ReceiptController.php
File metadata and controls
135 lines (127 loc) · 5.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
<?php
namespace App\Http\Controllers;
use Yoti\DigitalIdentityClient;
use Illuminate\Http\Request;
use Illuminate\Routing\Controller as BaseController;
use Yoti\Profile\Attribute;
use Yoti\Profile\UserProfile;
use Yoti\Util\Logger;
class ReceiptController extends BaseController
{
public function show(Request $request, DigitalIdentityClient $client, ?LoggerInterface $logger = null)
{
$logger = $logger ?? new Logger();
$logger->warning("Unknown Content Type parsing as a String");
$shareReceipt = $client->fetchShareReceipt($request->query('ReceiptID'));
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
]);
}
}
/**
* Create attributes display list.
*
* @param UserProfile $profile
*
* @return array
*/
private function createAttributesDisplayList(UserProfile $profile): array
{
$profileAttributes = [];
foreach ($profile->getAttributesList() as $attribute) {
switch ($attribute->getName()) {
case UserProfile::ATTR_SELFIE:
case UserProfile::ATTR_FULL_NAME:
// Selfie and full name are handled separately.
break;
case UserProfile::ATTR_GIVEN_NAMES:
$profileAttributes[] = $this->createAttributeDisplayItem($attribute, 'Given names', 'yoti-icon-profile');
break;
case UserProfile::ATTR_FAMILY_NAME:
$profileAttributes[] = $this->createAttributeDisplayItem($attribute, 'Family names', 'yoti-icon-profile');
break;
case UserProfile::ATTR_DATE_OF_BIRTH:
$profileAttributes[] = $this->createAttributeDisplayItem($attribute, 'Date of Birth', 'yoti-icon-calendar');
break;
case UserProfile::ATTR_GENDER:
$profileAttributes[] = $this->createAttributeDisplayItem($attribute, 'Gender', 'yoti-icon-gender');
break;
case UserProfile::ATTR_STRUCTURED_POSTAL_ADDRESS:
$profileAttributes[] = $this->createAttributeDisplayItem($attribute, 'Structured Postal Address', 'yoti-icon-address');
break;
case UserProfile::ATTR_POSTAL_ADDRESS:
$profileAttributes[] = $this->createAttributeDisplayItem($attribute, 'Address', 'yoti-icon-address');
break;
case UserProfile::ATTR_PHONE_NUMBER:
$profileAttributes[] = $this->createAttributeDisplayItem($attribute, 'Mobile number', 'yoti-icon-phone');
break;
case UserProfile::ATTR_NATIONALITY:
$profileAttributes[] = $this->createAttributeDisplayItem($attribute, 'Nationality', 'yoti-icon-nationality');
break;
case UserProfile::ATTR_EMAIL_ADDRESS:
$profileAttributes[] = $this->createAttributeDisplayItem($attribute, 'Email address', 'yoti-icon-email');
break;
case UserProfile::ATTR_DOCUMENT_DETAILS:
$profileAttributes[] = $this->createAttributeDisplayItem($attribute, 'Document Details', 'yoti-icon-profile');
break;
case UserProfile::ATTR_DOCUMENT_IMAGES:
$profileAttributes[] = $this->createAttributeDisplayItem($attribute, 'Document Images', 'yoti-icon-profile');
break;
default:
// Skip age verifications (name containing ":").
if (strpos($attribute->getName(), ':') === false) {
$profileAttributes[] = $this->createAttributeDisplayItem(
$attribute,
ucwords(str_replace('_', ' ', $attribute->getName())),
'yoti-icon-profile'
);
}
}
}
// Add age verifications.
$ageVerifications = $profile->getAgeVerifications();
if ($ageVerifications) {
foreach ($ageVerifications as $ageVerification) {
$profileAttributes[] = [
'name' => 'Age Verification',
'obj' => $ageVerification->getAttribute(),
'age_verification' => $ageVerification,
'icon' => 'yoti-icon-profile',
];
}
}
return $profileAttributes;
}
/**
* Create attribute display item.
*
* @param Attribute $attribute
* @param string $displayName
* @param string $iconClass
*
* @return array
*/
private function createAttributeDisplayItem(Attribute $attribute, string $displayName, string $iconClass): array
{
return [
'name' => $displayName,
'obj' => $attribute,
'icon' => $iconClass,
];
}
}