|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Bytesfield\SimpleKyc; |
|
4
|
|
|
|
|
5
|
|
|
use Bytesfield\SimpleKyc\Classes\IdFilter; |
|
6
|
|
|
use Bytesfield\SimpleKyc\Services\IdVerification; |
|
7
|
|
|
use Bytesfield\SimpleKyc\Exceptions\IsNullException; |
|
8
|
|
|
use Bytesfield\SimpleKyc\Exceptions\NotFoundException; |
|
9
|
|
|
|
|
10
|
|
|
class SimpleKyc |
|
11
|
|
|
{ |
|
12
|
|
|
|
|
13
|
|
|
/** |
|
14
|
|
|
* Verify ID |
|
15
|
|
|
* |
|
16
|
|
|
* @param array $payload |
|
17
|
|
|
* |
|
18
|
|
|
* @throws IsNullException|NotFoundException |
|
19
|
|
|
* @return array |
|
20
|
|
|
*/ |
|
21
|
|
|
public function verifyId(array $payload) |
|
22
|
|
|
{ |
|
23
|
|
|
$requestData = (object) $payload; |
|
24
|
|
|
|
|
25
|
|
|
if (empty((array) $requestData)) { |
|
26
|
|
|
throw new IsNullException('Payload must not be empty.'); |
|
27
|
|
|
} |
|
28
|
|
|
|
|
29
|
|
|
$arrayKeyFormats = array_values(IdFilter::REQUEST_FORMAT); |
|
30
|
|
|
|
|
31
|
|
|
foreach ($requestData as $key => $data) { |
|
32
|
|
|
if (!in_array($key, $arrayKeyFormats)) { |
|
33
|
|
|
throw new NotFoundException("{$key} is not a supported form field or array key."); |
|
34
|
|
|
} |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
$idValue = array_values(IdFilter::IDVALUES); |
|
38
|
|
|
|
|
39
|
|
|
if (!array_key_exists('id_type', (array) $requestData)) { |
|
40
|
|
|
throw new IsNullException('id_type key and value must be specified.'); |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
$idType = $requestData->id_type; |
|
44
|
|
|
|
|
45
|
|
|
//Checks for valid ID Types |
|
46
|
|
|
if (!in_array($idType, $idValue)) { |
|
47
|
|
|
throw new NotFoundException("{$idType} is not supported or not a valid ID TYPE."); |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
$supportedCountries = array_values(IdFilter::COUNTRIES); |
|
51
|
|
|
|
|
52
|
|
|
//Checks for supported country |
|
53
|
|
|
if (!in_array($requestData->country, $supportedCountries)) { |
|
54
|
|
|
throw new NotFoundException("{$requestData->country} is not a valid country or not supported."); |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
$idVerification = new IdVerification($requestData); |
|
58
|
|
|
|
|
59
|
|
|
return $idVerification->verify(); |
|
60
|
|
|
} |
|
61
|
|
|
} |
|
62
|
|
|
|