1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Bytesfield\SimpleKyc\Classes; |
4
|
|
|
|
5
|
|
|
use Bytesfield\SimpleKyc\Classes\IdFilter; |
6
|
|
|
use Bytesfield\SimpleKyc\Exceptions\NotValidException; |
7
|
|
|
use Bytesfield\SimpleKyc\Exceptions\DataMismatchException; |
8
|
|
|
use Bytesfield\SimpleKyc\Exceptions\NotFoundException; |
9
|
|
|
|
10
|
|
|
class Validation |
11
|
|
|
{ |
12
|
|
|
/** |
13
|
|
|
* Validate Appruve information |
14
|
|
|
* |
15
|
|
|
* @param array $response |
16
|
|
|
* @param \Bytesfield\SimpleKyc\Classes\IdFilter |
17
|
|
|
* |
18
|
|
|
* @return array |
19
|
|
|
*/ |
20
|
|
|
public function validateAppruve(array $response, IdFilter $IdFilter): array |
21
|
|
|
{ |
22
|
|
|
$idType = $IdFilter->getIDType(); |
23
|
|
|
|
24
|
|
|
if ($IdFilter->getCountry() == IdFilter::COUNTRIES['GHANA']) { |
25
|
|
|
|
26
|
|
|
if ($idType == IdFilter::IDVALUES['TYPE_VOTER_CARD']) { |
27
|
|
|
return $response; |
28
|
|
|
} //Exclude Appruve Field Verification for this |
29
|
|
|
|
30
|
|
|
if ($idType == IdFilter::IDVALUES['TYPE_TIN']) { |
31
|
|
|
if (!$response['data']['is_valid']) { |
32
|
|
|
throw new NotValidException('Tin is not valid'); |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
return $response; |
36
|
|
|
} //Exclude Appruve Field Verification for this |
37
|
|
|
|
38
|
|
|
if ($idType == IdFilter::IDVALUES['TYPE_DRIVERS_LICENSE']) { |
39
|
|
|
if (!$response['data']['is_full_name_match']) { |
40
|
|
|
throw new DataMismatchException('Fullname does not match'); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
if (!$response['data']['is_date_of_birth_match']) { |
44
|
|
|
throw new DataMismatchException('Date of birth does not match'); |
45
|
|
|
} |
46
|
|
|
return $response; |
47
|
|
|
} //Exclude Appruve Field Verification for this |
48
|
|
|
|
49
|
|
|
if ($idType == IdFilter::IDVALUES['TYPE_SSNIT']) { |
50
|
|
|
if (!$response['data']['is_full_name_match']) { |
51
|
|
|
throw new DataMismatchException('Fullname does not match'); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
return $response; |
55
|
|
|
} //Exclude Appruve Field Verification for this |
56
|
|
|
|
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
if ( |
60
|
|
|
$idType == IdFilter::IDVALUES['TYPE_TIN'] |
61
|
|
|
|| $idType == IdFilter::IDVALUES['TYPE_KRA'] |
62
|
|
|
|| $idType == IdFilter::IDVALUES['TELCO_SUBSCRIBER'] |
63
|
|
|
) { |
64
|
|
|
return $response; |
65
|
|
|
} //Exclude Appruve Field Verification for this |
66
|
|
|
|
67
|
|
|
$isVerified = $this->verifyAppruve($response); |
68
|
|
|
|
69
|
|
|
if ($isVerified == true) { |
|
|
|
|
70
|
|
|
return $response; |
71
|
|
|
} |
|
|
|
|
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* Verify Appruve information |
76
|
|
|
* |
77
|
|
|
* @param array result |
|
|
|
|
78
|
|
|
* |
79
|
|
|
* @throws \Bytesfield\SimpleKyc\Exceptions\DataMismatchException |
80
|
|
|
* |
81
|
|
|
* @return bool |
82
|
|
|
*/ |
83
|
|
|
private function verifyAppruve($result): bool |
84
|
|
|
{ |
85
|
|
|
$data = $result['data']; |
86
|
|
|
|
87
|
|
|
if (!$data['is_first_name_match']) { |
88
|
|
|
throw new DataMismatchException('Firstname does not match'); |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
if (!$data['is_last_name_match']) { |
92
|
|
|
throw new DataMismatchException('Lastname does not match'); |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
if (!$data['is_date_of_birth_match']) { |
96
|
|
|
throw new DataMismatchException('Date of birth does not match'); |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
return true; |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
/** |
103
|
|
|
* Validate Credequity information |
104
|
|
|
* |
105
|
|
|
* @param array $response |
106
|
|
|
* @param \Bytesfield\SimpleKyc\Classes\IdFilter |
107
|
|
|
* |
108
|
|
|
* @return array |
109
|
|
|
*/ |
110
|
|
|
public function validateCredequity($response, IdFilter $IdFilter): array |
111
|
|
|
{ |
112
|
|
|
$isVerified = $this->verifyCredequity($response, $IdFilter); |
113
|
|
|
|
114
|
|
|
if ($isVerified == true) { |
|
|
|
|
115
|
|
|
return $response; |
116
|
|
|
} |
|
|
|
|
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
/** |
120
|
|
|
* Verify Credequity information |
121
|
|
|
* |
122
|
|
|
* @param array result |
123
|
|
|
* @param Bytesfield\SimpleKyc\Classes\IdFilter |
124
|
|
|
* |
125
|
|
|
* @throws \Bytesfield\SimpleKyc\Exceptions\DataMismatchException |
126
|
|
|
* |
127
|
|
|
* @return bool |
128
|
|
|
*/ |
129
|
|
|
private function verifyCredequity($result, $IdFilter): bool |
130
|
|
|
{ |
131
|
|
|
$data = $result['data']; |
132
|
|
|
$idType = $IdFilter->getIDType(); |
133
|
|
|
|
134
|
|
|
if ($idType == IdFilter::IDVALUES['TYPE_BVN']) { |
135
|
|
|
|
136
|
|
|
if (strtoupper($data['firstName']) !== strtoupper($IdFilter->getFirstName())) { |
137
|
|
|
throw new DataMismatchException('Firstname does not match'); |
138
|
|
|
} |
139
|
|
|
|
140
|
|
|
if (strtoupper($data['lastName']) !== strtoupper($IdFilter->getLastName())) { |
141
|
|
|
throw new DataMismatchException('Lastname does not match'); |
142
|
|
|
} |
143
|
|
|
|
144
|
|
|
if ($data['dateOfBirth'] !== $IdFilter->getDOB()) { |
145
|
|
|
throw new DataMismatchException('Date of birth does not match'); |
146
|
|
|
} |
147
|
|
|
} |
148
|
|
|
|
149
|
|
|
if ($idType == IdFilter::IDVALUES['TYPE_DRIVERS_LICENSE']) { |
150
|
|
|
if ($data['Birthdate'] !== $IdFilter->getDOB()) { |
151
|
|
|
throw new DataMismatchException('Date of birth does not match'); |
152
|
|
|
} |
153
|
|
|
} |
154
|
|
|
|
155
|
|
|
if ($idType == IdFilter::IDVALUES['TYPE_NIN']) { |
156
|
|
|
if (strtoupper($data['firstname']) !== strtoupper($IdFilter->getFirstName())) { |
157
|
|
|
throw new DataMismatchException('Firstname does not match'); |
158
|
|
|
} |
159
|
|
|
|
160
|
|
|
if ($data['birthdate'] !== $IdFilter->getDOB()) { |
161
|
|
|
throw new DataMismatchException('Date of birth does not match'); |
162
|
|
|
} |
163
|
|
|
} |
164
|
|
|
|
165
|
|
|
return true; |
166
|
|
|
} |
167
|
|
|
|
168
|
|
|
/** |
169
|
|
|
* Validate Smile response |
170
|
|
|
* |
171
|
|
|
* @param array $response |
172
|
|
|
* |
173
|
|
|
* @throws \Bytesfield\SimpleKyc\Exceptions\NotFoundException |
174
|
|
|
* |
175
|
|
|
* @return array |
176
|
|
|
*/ |
177
|
|
|
public function validateSmile(array $response): array |
178
|
|
|
{ |
179
|
|
|
$isVerified = $this->verifySmile($response); |
180
|
|
|
|
181
|
|
|
if ($isVerified === false) { |
182
|
|
|
throw new NotFoundException("{$response['data']['ResultText']}"); |
183
|
|
|
} |
184
|
|
|
return $response; |
185
|
|
|
} |
186
|
|
|
|
187
|
|
|
/** |
188
|
|
|
* Verify Smile response |
189
|
|
|
* |
190
|
|
|
* @param array $response |
191
|
|
|
* |
192
|
|
|
* @return bool |
193
|
|
|
*/ |
194
|
|
|
private function verifySmile($response): bool |
195
|
|
|
{ |
196
|
|
|
if (($response['data']['Actions']['Verify_ID_Number'] !== 'Verified')) { |
197
|
|
|
return false; |
198
|
|
|
} |
199
|
|
|
|
200
|
|
|
return true; |
201
|
|
|
} |
202
|
|
|
} |
203
|
|
|
|