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 Credequity |
11
|
|
|
{ |
12
|
|
|
public function __construct() |
13
|
|
|
{ |
14
|
|
|
$config = new Config(__DIR__ . '/../config'); |
15
|
|
|
|
16
|
|
|
$this->handler = $config->get('credequity.handler'); |
|
|
|
|
17
|
|
|
$this->apiKey = $config->get('credequity.api_key'); |
|
|
|
|
18
|
|
|
$this->baseUrl = $config->get('credequity.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
|
|
|
* @param \Bytesfield\SimpleKyc\Classes\IdFilter |
41
|
|
|
* @param Closure $next |
42
|
|
|
* |
43
|
|
|
* @return array |
44
|
|
|
*/ |
45
|
|
|
public function handle(IdFilter $IdFilter, Closure $next) |
46
|
|
|
{ |
47
|
|
|
|
48
|
|
|
if (!$IdFilter->isSuccessful()) { |
49
|
|
|
|
50
|
|
|
if ($IdFilter->getCountry() == IdFilter::COUNTRIES['NIGERIA']) { |
51
|
|
|
|
52
|
|
|
if ($IdFilter->isWithImage()) { |
53
|
|
|
return $this->getWithImage($IdFilter); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
$idNumber = $IdFilter->getIDNumber(); |
57
|
|
|
$firstName = $IdFilter->getFirstName(); |
58
|
|
|
$lastName = $IdFilter->getLastName(); |
59
|
|
|
$phone = $IdFilter->getPhoneNumber(); |
60
|
|
|
|
61
|
|
|
if ($IdFilter->getIDType() === IdFilter::IDVALUES['TYPE_BVN']) { |
62
|
|
|
$url = '/CredBvn/api/v1/Bvn/GetCustomerBvn'; |
63
|
|
|
|
64
|
|
|
$body = [ |
65
|
|
|
'bvn' => $idNumber, |
66
|
|
|
'PhoneNumber' => $phone |
67
|
|
|
]; |
68
|
|
|
|
69
|
|
|
return $this->postData($IdFilter, $body, $url); |
70
|
|
|
} |
71
|
|
|
if ($IdFilter->getIDType() === IdFilter::IDVALUES['TYPE_NIN']) { |
72
|
|
|
if (!$IdFilter->isSuccessful()) { |
73
|
|
|
$url = '/CredNin/api/v1/Identity?phoneNo=' . $phone; |
74
|
|
|
$body = []; |
75
|
|
|
|
76
|
|
|
return $this->postData($IdFilter, $body, $url); |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
//If request is not successful makes post with IdNumber |
80
|
|
|
if (!$IdFilter->isSuccessful()) { |
81
|
|
|
$url = '/CredNin/api/v1/IdentityByNin?nin=' . $idNumber; |
82
|
|
|
$body = []; |
83
|
|
|
|
84
|
|
|
return $this->postData($IdFilter, $body, $url); |
85
|
|
|
} |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
if ($IdFilter->getIDType() === IdFilter::IDVALUES['TYPE_DRIVERS_LICENSE']) { |
89
|
|
|
$url = '/Verify/api/v1/FrscInfo'; |
90
|
|
|
|
91
|
|
|
$body = [ |
92
|
|
|
'firstname' => $firstName, |
93
|
|
|
'lastname' => $lastName, |
94
|
|
|
'phoneNo' => $phone, |
95
|
|
|
'frscidentityNo' => $idNumber |
96
|
|
|
]; |
97
|
|
|
|
98
|
|
|
return $this->postData($IdFilter, $body, $url); |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
if ($IdFilter->getIDType() === IdFilter::IDVALUES['TYPE_CUSTOMER_PROFILE']) { |
102
|
|
|
$url = '/CredBvn/api/v1/CustomerProfile'; |
103
|
|
|
//$IdFilter->setCredequityProfile(); |
104
|
|
|
$profile = $IdFilter->getCredequityProfile(); |
105
|
|
|
|
106
|
|
|
$body = [ |
107
|
|
|
"Nin" => $profile['nin'], |
108
|
|
|
"FrscNo" => $profile['frscno'], |
109
|
|
|
"phoneNo" => $phone, |
110
|
|
|
"Bvn" => $profile['bvn'] |
111
|
|
|
]; |
112
|
|
|
|
113
|
|
|
return $this->postData($IdFilter, $body, $url); |
114
|
|
|
} |
115
|
|
|
} |
116
|
|
|
} |
117
|
|
|
return $next($IdFilter); |
118
|
|
|
} |
119
|
|
|
|
120
|
|
|
/** |
121
|
|
|
* Get ID information via images |
122
|
|
|
* |
123
|
|
|
* @param \Bytesfield\SimpleKyc\Classes\IdFilter |
124
|
|
|
|
125
|
|
|
* @return array |
126
|
|
|
*/ |
127
|
|
|
private function getWithImage(IdFilter $IdFilter): array |
128
|
|
|
{ |
129
|
|
|
$relative = ($IdFilter->getIDType() === 'NIN') ? 'VerifyNinWithFace' : 'VerifyFrscWithFace'; |
130
|
|
|
|
131
|
|
|
$url = '/CredOcr/api/v1/' . $relative; |
132
|
|
|
|
133
|
|
|
$body = [ |
134
|
|
|
'IdentificationProof' => $IdFilter->getIdentificationProof(), |
135
|
|
|
'FaceProof' => $IdFilter->getFaceProof() |
136
|
|
|
]; |
137
|
|
|
|
138
|
|
|
return $this->postData($IdFilter, $body, $url); |
139
|
|
|
} |
140
|
|
|
|
141
|
|
|
/** |
142
|
|
|
* Make API call and get the required data from Credequity |
143
|
|
|
* |
144
|
|
|
* @param \Bytesfield\SimpleKyc\Classes\IdFilter |
145
|
|
|
* @param array $body |
146
|
|
|
* @param string url |
|
|
|
|
147
|
|
|
* |
148
|
|
|
* @return array |
149
|
|
|
*/ |
150
|
|
|
private function postData(IdFilter $IdFilter, $body, $url) |
151
|
|
|
{ |
152
|
|
|
try { |
153
|
|
|
$result = $this->process('POST', $url, array_filter($body)); |
154
|
|
|
|
155
|
|
|
$response = (object) $result->getResponse(); |
156
|
|
|
|
157
|
|
|
if ($response->message === 'Successful') { |
158
|
|
|
|
159
|
|
|
$IdFilter->confirmSuccess(); |
160
|
|
|
|
161
|
|
|
$IdFilter->setHandler($this->handler); |
162
|
|
|
|
163
|
|
|
$IdFilter->setData([ |
164
|
|
|
'handler' => $IdFilter->getHandler(), |
165
|
|
|
'message' => $IdFilter->getIDType() . ' Verified' . ' Successfully', |
166
|
|
|
'data' => $response->data |
167
|
|
|
]); |
168
|
|
|
|
169
|
|
|
return $IdFilter->getData(); |
170
|
|
|
} |
171
|
|
|
} catch (\Exception $e) { |
172
|
|
|
$IdFilter->setError(['error' => $e->getMessage()]); |
173
|
|
|
|
174
|
|
|
return json_encode(['error' => $IdFilter->getError()]); |
|
|
|
|
175
|
|
|
} |
176
|
|
|
} |
177
|
|
|
} |
178
|
|
|
|