1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Bytesfield\SimpleKyc\Services; |
4
|
|
|
|
5
|
|
|
use Noodlehaus\Config; |
6
|
|
|
use Mpociot\Pipeline\Pipeline; |
7
|
|
|
use Bytesfield\SimpleKyc\Pipes\Smile; |
8
|
|
|
use Bytesfield\SimpleKyc\Pipes\Appruve; |
9
|
|
|
use Bytesfield\SimpleKyc\Classes\IdFilter; |
10
|
|
|
use Bytesfield\SimpleKyc\Classes\Validation; |
11
|
|
|
use Bytesfield\SimpleKyc\Pipes\Credequity; |
12
|
|
|
|
13
|
|
|
class IdVerification |
14
|
|
|
{ |
15
|
|
|
|
16
|
|
|
public function __construct($data) |
17
|
|
|
{ |
18
|
|
|
$this->country = filterCountry($data->country); |
|
|
|
|
19
|
|
|
$this->id_type = strtoupper($data->id_type) ?? null; |
|
|
|
|
20
|
|
|
$this->id_number = $data->id ?? null; |
|
|
|
|
21
|
|
|
$this->first_name = $data->first_name ?? null; |
|
|
|
|
22
|
|
|
$this->last_name = $data->last_name ?? null; |
|
|
|
|
23
|
|
|
$this->middle_name = $data->middle_name ?? null; |
|
|
|
|
24
|
|
|
$this->date_of_birth = $data->date_of_birth ?? null; |
|
|
|
|
25
|
|
|
$this->phone = $data->phone_number ?? null; |
|
|
|
|
26
|
|
|
$this->pin = $data->pin ?? null; |
|
|
|
|
27
|
|
|
$this->tin = $data->tin ?? null; |
|
|
|
|
28
|
|
|
$this->gender = $data->gender ?? null; |
|
|
|
|
29
|
|
|
$this->full_name = $this->first_name . ' ' . $this->last_name; |
|
|
|
|
30
|
|
|
$this->user_id = $data->user_id ?? null; |
|
|
|
|
31
|
|
|
$this->company = $data->company ?? null; |
|
|
|
|
32
|
|
|
$this->registration_number = $data->registration_number ?? null; |
|
|
|
|
33
|
|
|
|
34
|
|
|
$this->config = new Config(__DIR__ . '/../config'); |
|
|
|
|
35
|
|
|
|
36
|
|
|
$this->appruveHandler = $this->config->get('appruve.handler'); |
|
|
|
|
37
|
|
|
$this->smileHandler = $this->config->get('smile.handler'); |
|
|
|
|
38
|
|
|
$this->credequityHandler = $this->config->get('credequity.handler'); |
|
|
|
|
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
public function verify() |
42
|
|
|
{ |
43
|
|
|
$IdFilter = new IdFilter( |
44
|
|
|
$this->country, |
45
|
|
|
$this->id_type, |
46
|
|
|
$this->id_number, |
47
|
|
|
$this->first_name, |
48
|
|
|
$this->last_name, |
49
|
|
|
$this->middle_name, |
50
|
|
|
$this->date_of_birth, |
51
|
|
|
$this->phone, |
52
|
|
|
$this->pin, |
53
|
|
|
$this->tin, |
54
|
|
|
$this->gender, |
55
|
|
|
$this->full_name, |
56
|
|
|
$this->user_id, |
57
|
|
|
$this->company, |
58
|
|
|
$this->registration_number |
59
|
|
|
|
60
|
|
|
); |
61
|
|
|
|
62
|
|
|
$response = null; |
|
|
|
|
63
|
|
|
$pipes = [Smile::class, Appruve::class, Credequity::class,]; |
64
|
|
|
|
65
|
|
|
$response = (new Pipeline)->send($IdFilter) |
66
|
|
|
->through($pipes) |
67
|
|
|
->then(function ($result) { |
68
|
|
|
return $result; |
69
|
|
|
}); |
70
|
|
|
|
71
|
|
|
$executedHandler = strtoupper($IdFilter->getHandler()); |
72
|
|
|
|
73
|
|
|
$validation = new Validation(); |
74
|
|
|
|
75
|
|
|
//Validate Appruve Handler result |
76
|
|
|
if ($executedHandler == strtoupper($this->appruveHandler)) { |
|
|
|
|
77
|
|
|
|
78
|
|
|
return $validation->validateAppruve($response, $IdFilter); |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
//Validate Smile Handler result |
82
|
|
|
if ($executedHandler == strtoupper($this->smileHandler)) { |
83
|
|
|
return $validation->validateSmile($response, $IdFilter); |
|
|
|
|
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
//Validate Credequity Handler result |
87
|
|
|
if ($executedHandler == strtoupper($this->credequityHandler)) { |
88
|
|
|
return $validation->validateCredequity($response, $IdFilter); |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
return $response; |
92
|
|
|
} |
93
|
|
|
} |
94
|
|
|
|