|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Bytesfield\SimpleKyc\Pipes; |
|
4
|
|
|
|
|
5
|
|
|
use Bytesfield\SimpleKyc\Classes\IdFilter; |
|
6
|
|
|
use Closure; |
|
7
|
|
|
use Noodlehaus\Config; |
|
8
|
|
|
use Bytesfield\SimpleKyc\HttpProcessor; |
|
9
|
|
|
|
|
10
|
|
|
class Appruve |
|
11
|
|
|
{ |
|
12
|
|
|
public function __construct() |
|
13
|
|
|
{ |
|
14
|
|
|
$config = new Config(__DIR__ . '/../config'); |
|
15
|
|
|
|
|
16
|
|
|
$this->handler = $config->get('appruve.handler'); |
|
|
|
|
|
|
17
|
|
|
$this->apiKey = $config->get('appruve.api_key'); |
|
|
|
|
|
|
18
|
|
|
$this->baseUrl = $config->get('appruve.api_url'); |
|
|
|
|
|
|
19
|
|
|
} |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* Process http calls |
|
23
|
|
|
* |
|
24
|
|
|
* @param string $method The call method get|post|put|delete|patch |
|
25
|
|
|
* @param string $url The url to call |
|
26
|
|
|
* @param array $payload |
|
27
|
|
|
|
|
28
|
|
|
* @return \Bytesfield\SimpleKyc\HttpProcessor |
|
29
|
|
|
*/ |
|
30
|
|
|
private function process($method, $url, $payload): HttpProcessor |
|
31
|
|
|
{ |
|
32
|
|
|
//HttpProcessor class to handle http request |
|
33
|
|
|
$processor = new HttpProcessor($this->baseUrl, $this->apiKey, $this->handler); |
|
|
|
|
|
|
34
|
|
|
|
|
35
|
|
|
return $processor->process($method, $url, $payload); |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* Handles the ID request |
|
40
|
|
|
* |
|
41
|
|
|
* @param \Bytesfield\SimpleKyc\Classes\IdFilter |
|
42
|
|
|
* @param Closure $next |
|
43
|
|
|
* |
|
44
|
|
|
* @return mixed |
|
45
|
|
|
*/ |
|
46
|
|
|
public function handle(IdFilter $IdFilter, Closure $next) |
|
47
|
|
|
{ |
|
48
|
|
|
if (!$IdFilter->isSuccessful()) { |
|
49
|
|
|
|
|
50
|
|
|
$idType = strtoupper($IdFilter->getIDType()); |
|
51
|
|
|
$country = strtolower($IdFilter->getCountry()); |
|
|
|
|
|
|
52
|
|
|
$type = $this->getType($idType); |
|
53
|
|
|
$url = '/v1/verifications/' . $country . '/' . $type; |
|
54
|
|
|
|
|
55
|
|
|
$body = [ |
|
56
|
|
|
'id' => $IdFilter->getIdNumber(), |
|
57
|
|
|
'first_name' => $IdFilter->getFirstName(), |
|
58
|
|
|
'last_name' => $IdFilter->getLastName(), |
|
59
|
|
|
'middle_name' => $IdFilter->getMiddleName(), |
|
60
|
|
|
'date_of_birth' => $IdFilter->getDOB(), |
|
61
|
|
|
'phone_number' => $IdFilter->getPhoneNumber(), |
|
62
|
|
|
'expiry_date' => $IdFilter->getExpiry(), |
|
63
|
|
|
'gender' => $IdFilter->getGender(), |
|
64
|
|
|
'address' => $IdFilter->getAddress(), |
|
65
|
|
|
'pin' => $IdFilter->getPin(), |
|
66
|
|
|
'tin' => $IdFilter->getTin(), |
|
67
|
|
|
'full_name' => $IdFilter->getFullName(), |
|
68
|
|
|
'company_name' => $IdFilter->getCompany(), |
|
69
|
|
|
'registration_number' => $IdFilter->getRegistrationNumber() |
|
70
|
|
|
]; |
|
71
|
|
|
|
|
72
|
|
|
try { |
|
73
|
|
|
$response = $this->process('POST', $url, array_filter($body))->getResponse(); |
|
74
|
|
|
|
|
75
|
|
|
$IdFilter->confirmSuccess(); |
|
76
|
|
|
|
|
77
|
|
|
$IdFilter->setHandler($this->handler); |
|
78
|
|
|
|
|
79
|
|
|
$IdFilter->setData([ |
|
80
|
|
|
'handler' => $IdFilter->getHandler(), |
|
81
|
|
|
'country' => $IdFilter->getCountry(), |
|
82
|
|
|
'message' => $IdFilter->getIDType() . ' Verified' . ' Successfully', |
|
83
|
|
|
'data' => $response |
|
84
|
|
|
]); |
|
85
|
|
|
|
|
86
|
|
|
return $IdFilter->getData(); |
|
87
|
|
|
} catch (\Exception $e) { |
|
88
|
|
|
|
|
89
|
|
|
$IdFilter->setError(['error' => $e->getMessage()]); |
|
90
|
|
|
|
|
91
|
|
|
return $next($IdFilter); |
|
92
|
|
|
} |
|
93
|
|
|
} |
|
94
|
|
|
return $next($IdFilter); |
|
95
|
|
|
} |
|
96
|
|
|
|
|
97
|
|
|
/** |
|
98
|
|
|
* Transform the ID |
|
99
|
|
|
* |
|
100
|
|
|
* @param string $type |
|
101
|
|
|
* |
|
102
|
|
|
* @return string |
|
103
|
|
|
*/ |
|
104
|
|
|
private function getType(string $type): string |
|
105
|
|
|
{ |
|
106
|
|
|
if ($type === IdFilter::IDVALUES['TYPE_NATIONAL_ID'] || $type === IdFilter::IDVALUES['TYPE_NIN']) { |
|
107
|
|
|
return 'national_id'; |
|
108
|
|
|
} |
|
109
|
|
|
if ($type === IdFilter::IDVALUES['TYPE_DRIVERS_LICENSE']) { |
|
110
|
|
|
return 'driver_license'; |
|
111
|
|
|
} |
|
112
|
|
|
if ($type === IdFilter::IDVALUES['TYPE_VOTER_CARD']) { |
|
113
|
|
|
return 'voter'; |
|
114
|
|
|
} |
|
115
|
|
|
if ($type === IdFilter::IDVALUES['TYPE_BVN']) { |
|
116
|
|
|
return 'bvn'; |
|
117
|
|
|
} |
|
118
|
|
|
if ($type === IdFilter::IDVALUES['TELCO_SUBSCRIBER']) { |
|
119
|
|
|
return 'telco_subscriber'; |
|
120
|
|
|
} |
|
121
|
|
|
return strtolower($type); |
|
122
|
|
|
} |
|
123
|
|
|
} |
|
124
|
|
|
|