-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #32 from njoguamos/add-id-search-and-verification
Add ID Search & Verification
- Loading branch information
Showing
8 changed files
with
270 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<?php | ||
|
||
namespace NjoguAmos\Jenga\Api; | ||
|
||
use Carbon\Carbon; | ||
use Illuminate\Support\Facades\Http; | ||
use NjoguAmos\Jenga\Concerns\JengaConnector; | ||
use NjoguAmos\Jenga\Dto\IDVerificationDto; | ||
|
||
class IDVerification extends DefaultJengaConnector implements JengaConnector | ||
{ | ||
public function getEndPoint(): string | ||
{ | ||
return $this->getBaseUrl() . '/v3-apis//v3.0/validate/identity'; | ||
} | ||
|
||
public function search(IDVerificationDto $data): string | ||
{ | ||
$signatureData = [ | ||
"countryCode" => $data->countryCode ?: config(key: 'jenga.country'), | ||
"documentNumber" => $data->documentNumber, | ||
]; | ||
|
||
$postData = [ | ||
"documentNumber" => $data->documentNumber, | ||
"firstName" => $data->firstName, | ||
"lastName" => $data->lastName, | ||
"dateOfBirth" => Carbon::parse($data->dateOfBirth)->format(format: 'Y-m-d'), | ||
"documentType" => $data->documentType ?: config(key: 'jenga.country'), | ||
"countryCode" => $data->countryCode ?: 'ID' | ||
]; | ||
|
||
return Http::asJson() | ||
->withToken(token: $this->getToken()) | ||
->withHeaders($this->getSignatureHeader($signatureData)) | ||
->post(url: $this->getEndPoint(), data: $postData) | ||
->body(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace NjoguAmos\Jenga\Dto; | ||
|
||
class IDVerificationDto | ||
{ | ||
public function __construct( | ||
/** The document id number */ | ||
public string $documentNumber, | ||
|
||
/** First name as per identity document type */ | ||
public string $firstName, | ||
|
||
/** Last name as per identity document type */ | ||
public string $lastName, | ||
|
||
/** Date in of birth as per identity document type */ | ||
public string $dateOfBirth, | ||
|
||
/** The document type of the customer. for example ID, PASSPORT, ALIENID */ | ||
public ?string $documentType = null, | ||
|
||
/** The country in which the document relates to (only KE and RW enabled for now)*/ | ||
public ?string $countryCode = null, | ||
) { | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
<?php | ||
|
||
use Illuminate\Http\Client\Request; | ||
use Illuminate\Support\Facades\Http; | ||
use NjoguAmos\Jenga\Api\IDVerification; | ||
use NjoguAmos\Jenga\Dto\IDVerificationDto; | ||
use NjoguAmos\Jenga\JengaSignature; | ||
use NjoguAmos\Jenga\Models\JengaToken; | ||
|
||
test(description: 'it can search ID details successfully', closure: function () { | ||
$token = JengaToken::factory()->create(); | ||
|
||
$url = config(key: 'jenga.host') . '/v3-apis//v3.0/validate/identity'; | ||
|
||
$response = [ | ||
"status" => true, | ||
"code" => 0, | ||
"message" => "success", | ||
"data" => [ | ||
"identity" => [ | ||
"customer" => [ | ||
"firstName" => "JOHN", | ||
"lastName" => "DOE", | ||
"occupation" => "", | ||
"gender" => "M", | ||
"nationality" => "Kenyan", | ||
"deathDate" => "", | ||
"fullName" => "JOHN JOHN DOE DOE", | ||
"middlename" => "JOHN DOE", | ||
"ShortName" => "JOHN", | ||
"birthCityName" => "", | ||
"birthDate" => "1985-06-20T12:00:00", | ||
"faceImage" => "" | ||
], | ||
"documentType" => "NATIONAL ID", | ||
"documentNumber" => "555555", | ||
"documentSerialNumber" => "55555555555", | ||
"documentIssueDate" => "2011-12-08T12:00:00", | ||
"documentExpirationDate" => "", | ||
"IssuedBy" => "REPUBLIC OF KENYA", | ||
"additionalIdentityDetails" => [ | ||
[ | ||
"documentType" => "", | ||
"documentNumber" => "", | ||
"issuedBy" => "" | ||
] | ||
], | ||
"address" => [ | ||
"locationName" => "", | ||
"districtName" => "", | ||
"subLocationName" => "", | ||
"provinceName" => "", | ||
"villageName" => "" | ||
] | ||
] | ||
] | ||
]; | ||
|
||
$signatureData = [ | ||
"countryCode" => 'KE', | ||
"documentNumber" => '555555', | ||
]; | ||
|
||
$this->artisan(command: 'jenga:keys'); | ||
|
||
$signature = (new JengaSignature(data: $signatureData))->getSignature(); | ||
|
||
Http::fake([ | ||
$url => Http::response($response, 200), | ||
]); | ||
|
||
Http::preventStrayRequests(); | ||
|
||
$data = new IDVerificationDto( | ||
documentNumber: '555555', | ||
firstName: 'John', | ||
lastName: 'Doe', | ||
dateOfBirth: '20 June 1985', | ||
documentType: 'ID', | ||
countryCode: 'KE', | ||
); | ||
|
||
|
||
$search = (new IDVerification())->search($data); | ||
|
||
expect($search)->toBe(json_encode($response)); | ||
|
||
Http::assertSent(function (Request $request) use ($url, $token, $signature) { | ||
return | ||
$request->hasHeader('Authorization', "Bearer $token->access_token") | ||
&& $request->hasHeader('signature', "Bearer $signature") | ||
&& $request['documentNumber'] == '555555' | ||
&& $request['firstName'] == 'John' | ||
&& $request['lastName'] == 'Doe' | ||
&& $request['dateOfBirth'] == '1985-06-20' | ||
&& $request['documentType'] == 'ID' | ||
&& $request['countryCode'] == 'KE'; | ||
}); | ||
}); |