Skip to content

Commit 86938f3

Browse files
LuborRodRodion Liuborets
andauthored
SDK-2100 Retrieve the identity profile in the IDV response (#279)
Co-authored-by: Rodion Liuborets <[email protected]>
1 parent d611e92 commit 86938f3

File tree

8 files changed

+275
-0
lines changed

8 files changed

+275
-0
lines changed

src/DocScan/Session/Retrieve/GetSessionResult.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,16 @@ class GetSessionResult
4949
*/
5050
private $biometricConsent;
5151

52+
/**
53+
* @var IdentityProfileResponse
54+
*/
55+
private $identityProfile;
56+
5257
/**
5358
* DocScanSession constructor.
5459
* @param array<string, mixed> $sessionData
60+
*
61+
* @throws \Yoti\Exception\DateTimeException
5562
*/
5663
public function __construct(array $sessionData)
5764
{
@@ -74,6 +81,10 @@ public function __construct(array $sessionData)
7481
if (isset($sessionData['resources'])) {
7582
$this->resources = new ResourceContainer($sessionData['resources']);
7683
}
84+
85+
if (isset($sessionData['identity_profile'])) {
86+
$this->identityProfile = new IdentityProfileResponse($sessionData['identity_profile']);
87+
}
7788
}
7889

7990
/**
@@ -268,4 +279,12 @@ function ($checkResponse) use ($class): bool {
268279

269280
return array_values($filtered);
270281
}
282+
283+
/**
284+
* @return IdentityProfileResponse
285+
*/
286+
public function getIdentityProfile(): IdentityProfileResponse
287+
{
288+
return $this->identityProfile;
289+
}
271290
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
3+
namespace Yoti\DocScan\Session\Retrieve\IdentityProfile;
4+
5+
class FailureReasonResponse
6+
{
7+
/**
8+
* @var string
9+
*/
10+
private $stringCode;
11+
12+
/**
13+
* @param string $stringCode
14+
*/
15+
public function __construct(string $stringCode)
16+
{
17+
$this->stringCode = $stringCode;
18+
}
19+
20+
/**
21+
* @return string
22+
*/
23+
public function getStringCode(): string
24+
{
25+
return $this->stringCode;
26+
}
27+
}
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
<?php
2+
3+
namespace Yoti\DocScan\Session\Retrieve;
4+
5+
use Yoti\DocScan\Session\Retrieve\IdentityProfile\FailureReasonResponse;
6+
7+
class IdentityProfileResponse
8+
{
9+
/**
10+
* @var string
11+
*/
12+
private $subjectId;
13+
14+
/**
15+
* @var string
16+
*/
17+
private $result;
18+
19+
/**
20+
* @var FailureReasonResponse
21+
*/
22+
private $failureReason;
23+
24+
/**
25+
* @var object
26+
*/
27+
private $identityProfileReport;
28+
29+
/**
30+
* @param array<string, mixed> $sessionData
31+
*/
32+
public function __construct(array $sessionData)
33+
{
34+
$this->subjectId = $sessionData['subject_id'];
35+
$this->result = $sessionData['result'];
36+
37+
if (isset($sessionData['failure_reason'])) {
38+
$this->failureReason = new FailureReasonResponse($sessionData['failure_reason']['reason_code']);
39+
}
40+
41+
if (isset($sessionData['identity_profile_report'])) {
42+
$this->identityProfileReport = (object)$sessionData['identity_profile_report'];
43+
}
44+
}
45+
46+
/**
47+
* @return string
48+
*/
49+
public function getSubjectId(): string
50+
{
51+
return $this->subjectId;
52+
}
53+
54+
/**
55+
* @return string
56+
*/
57+
public function getResult(): string
58+
{
59+
return $this->result;
60+
}
61+
62+
/**
63+
* @return FailureReasonResponse
64+
*/
65+
public function getFailureReason(): FailureReasonResponse
66+
{
67+
return $this->failureReason;
68+
}
69+
70+
/**
71+
* @return object
72+
*/
73+
public function getIdentityProfileReport()
74+
{
75+
return $this->identityProfileReport;
76+
}
77+
}

tests/DocScan/DocScanClientTest.php

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
use Yoti\Test\TestCase;
2121
use Yoti\Test\TestData;
2222
use Yoti\Util\Config;
23+
use Yoti\Util\Json;
2324

2425
/**
2526
* @coversDefaultClass \Yoti\DocScan\DocScanClient
@@ -497,4 +498,45 @@ public function testTriggerIbvEmailNotification()
497498
TestData::DOC_SCAN_SESSION_ID
498499
);
499500
}
501+
502+
/**
503+
* @test
504+
*
505+
* Parse session response with identity profile
506+
*/
507+
public function testParseIdentityProfileResponse()
508+
{
509+
$sessionDataString = Json::decode(file_get_contents(TestData::SESSION_RESULT_IDENTITY_PROFILE));
510+
$sessionResult = new GetSessionResult($sessionDataString);
511+
512+
$this->assertEquals('DONE', $sessionResult->getIdentityProfile()->getResult());
513+
$this->assertEquals('someStringHere', $sessionResult->getIdentityProfile()->getSubjectId());
514+
$this->assertEquals(
515+
'MANDATORY_DOCUMENT_COULD_NOT_BE_PROVIDED',
516+
$sessionResult->getIdentityProfile()->getFailureReason()->getStringCode()
517+
);
518+
519+
$this->assertEquals(
520+
'UK_TFIDA',
521+
$sessionResult->getIdentityProfile()->getIdentityProfileReport()->trust_framework
522+
);
523+
$this->assertEquals(
524+
'DBS',
525+
$sessionResult->getIdentityProfile()->getIdentityProfileReport()->schemes_compliance[0]['scheme']['type']
526+
);
527+
$this->assertEquals(
528+
'STANDARD',
529+
$sessionResult->getIdentityProfile()->getIdentityProfileReport()
530+
->schemes_compliance[0]['scheme']['objective']
531+
);
532+
$this->assertEquals(
533+
'some string here',
534+
$sessionResult->getIdentityProfile()->getIdentityProfileReport()
535+
->schemes_compliance[0]['requirements_not_met_info']
536+
);
537+
$this->assertTrue(
538+
$sessionResult->getIdentityProfile()->getIdentityProfileReport()
539+
->schemes_compliance[0]['requirements_met']
540+
);
541+
}
500542
}

tests/DocScan/Session/Retrieve/GetSessionResultTest.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use Yoti\DocScan\Session\Retrieve\AuthenticityCheckResponse;
88
use Yoti\DocScan\Session\Retrieve\CheckResponse;
99
use Yoti\DocScan\Session\Retrieve\GetSessionResult;
10+
use Yoti\DocScan\Session\Retrieve\IdentityProfileResponse;
1011
use Yoti\Test\TestCase;
1112
use Yoti\Util\DateTime;
1213

@@ -31,6 +32,14 @@ class GetSessionResultTest extends TestCase
3132
private const SOME_CLIENT_SESSION_TOKEN = 'someClientSessionToken';
3233
private const SOME_CLIENT_SESSION_TOKEN_TTL = 300;
3334
private const SOME_BIOMETRIC_CONSENT_DATE_STRING = '2019-12-02T12:00:00.123Z';
35+
private const IDENTITY_PROFILE = [
36+
'subject_id' => 'SOME_STRING',
37+
'result' => 'SOME_ANOTHER_STRING',
38+
'failure_reason' => [
39+
'reason_code' => 'ANOTHER_STRING',
40+
],
41+
'identity_profile_report' => [],
42+
];
3443

3544
/**
3645
* @test
@@ -43,6 +52,7 @@ class GetSessionResultTest extends TestCase
4352
* @covers ::getResources
4453
* @covers ::getChecks
4554
* @covers ::getBiometricConsentTimestamp
55+
* @covers ::getIdentityProfile
4656
*/
4757
public function shouldBuildCorrectly()
4858
{
@@ -57,6 +67,7 @@ public function shouldBuildCorrectly()
5767
['type' => self::ID_DOCUMENT_AUTHENTICITY]
5868
],
5969
'resources' => [],
70+
'identity_profile' => self::IDENTITY_PROFILE
6071
];
6172

6273
$result = new GetSessionResult($input);
@@ -70,6 +81,7 @@ public function shouldBuildCorrectly()
7081
$this->assertNotNull($result->getChecks());
7182
$this->assertCount(1, $result->getChecks());
7283
$this->assertInstanceOf(AuthenticityCheckResponse::class, $result->getChecks()[0]);
84+
$this->assertInstanceOf(IdentityProfileResponse::class, $result->getIdentityProfile());
7385

7486
$this->assertNotNull($result->getResources());
7587

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
<?php
2+
3+
namespace Yoti\Test\DocScan\Session\Retrieve;
4+
5+
use Yoti\DocScan\Session\Retrieve\IdentityProfile\FailureReasonResponse;
6+
use Yoti\DocScan\Session\Retrieve\IdentityProfileResponse;
7+
use Yoti\Test\TestCase;
8+
9+
/**
10+
* @coversDefaultClass \Yoti\DocScan\Session\Retrieve\IdentityProfileResponse
11+
*/
12+
class IdentityProfileResponseTest extends TestCase
13+
{
14+
private const RESULT = 'DONE';
15+
private const SUBJECT_ID = 'someStringHere';
16+
private const REASON_CODE = 'MANDATORY_DOCUMENT_COULD_NOT_BE_PROVIDED';
17+
private const IDENTITY_PROFILE_REPORT = [
18+
'trust_framework' => 'UK_TFIDA',
19+
'schemes_compliance' => [
20+
0 => [
21+
'scheme' => [
22+
'type' => 'DBS',
23+
'objective' => 'STANDARD',
24+
],
25+
'requirements_met' => true,
26+
'requirements_not_met_info' => 'some string here',
27+
],
28+
],
29+
'media' => [
30+
],
31+
];
32+
33+
/**
34+
* @test
35+
* @covers ::__construct
36+
* @covers ::getIdentityProfileReport
37+
* @covers ::getFailureReason
38+
* @covers ::getResult
39+
* @covers ::getSubjectId
40+
* @covers \Yoti\DocScan\Session\Retrieve\IdentityProfile\FailureReasonResponse::getStringCode
41+
* @covers \Yoti\DocScan\Session\Retrieve\IdentityProfile\FailureReasonResponse::__construct
42+
*/
43+
public function shouldCreatedCorrectly(): void
44+
{
45+
$testData = [
46+
'subject_id' => self::SUBJECT_ID,
47+
'result' => self::RESULT,
48+
'failure_reason' => [
49+
'reason_code' => self::REASON_CODE,
50+
],
51+
'identity_profile_report' => self::IDENTITY_PROFILE_REPORT,
52+
];
53+
54+
$result = new IdentityProfileResponse($testData);
55+
56+
$this->assertEquals(self::RESULT, $result->getResult());
57+
$this->assertEquals(self::SUBJECT_ID, $result->getSubjectId());
58+
$this->assertEquals((object)self::IDENTITY_PROFILE_REPORT, $result->getIdentityProfileReport());
59+
60+
$this->assertInstanceOf(FailureReasonResponse::class, $result->getFailureReason());
61+
$this->assertEquals(self::REASON_CODE, $result->getFailureReason()->getStringCode());
62+
}
63+
}

tests/TestData.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ class TestData
3232

3333
public const DOC_SCAN_SESSION_CREATION_RESPONSE = __DIR__ . '/sample-data/docs/session-creation.json';
3434
public const DOC_SCAN_SESSION_RESPONSE = __DIR__ . '/sample-data/docs/session.json';
35+
public const SESSION_RESULT_IDENTITY_PROFILE = __DIR__ . '/sample-data/sessionResultIdentityProfileResult.json';
3536

3637
public const SOME_SESSION_SPEC_BYTES = [1,2,3,4];
3738
public const SOME_RESOURCE_ID = 'someResourceId';
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
{
2+
"session_id": "a1746488-efcc-4c59-bd28-f849dcb933a2",
3+
"client_session_token_ttl": 599,
4+
"user_tracking_id": "user-tracking-id",
5+
"biometric_consent": "2022-03-29T11:39:08.473Z",
6+
"state": "COMPLETED",
7+
"client_session_token": "3fa85f64-5717-4562-b3fc-2c963f66afa6",
8+
"identity_profile": {
9+
"subject_id": "someStringHere",
10+
"result": "DONE",
11+
"failure_reason": {
12+
"reason_code": "MANDATORY_DOCUMENT_COULD_NOT_BE_PROVIDED"
13+
},
14+
"identity_profile_report": {
15+
"trust_framework": "UK_TFIDA",
16+
"schemes_compliance": [
17+
{
18+
"scheme": {
19+
"type": "DBS",
20+
"objective": "STANDARD"
21+
},
22+
"requirements_met": true,
23+
"requirements_not_met_info": "some string here"
24+
}
25+
],
26+
"media": {
27+
"id": "c69ff2db-6caf-4e74-8386-037711bbc8d7",
28+
"type": "IMAGE",
29+
"created": "2022-03-29T11:39:24Z",
30+
"last_updated": "2022-03-29T11:39:24Z"
31+
}
32+
}
33+
}
34+
}

0 commit comments

Comments
 (0)