Skip to content

Commit c467f46

Browse files
authored
SDK-2197 Add support for requesting the profile preview + SDK-2202 Add support to fetch the identity profile preview (#309)
1 parent e1c7807 commit c467f46

File tree

7 files changed

+158
-10
lines changed

7 files changed

+158
-10
lines changed

src/DocScan/Session/Create/SessionSpecification.php

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,8 @@ class SessionSpecification implements JsonSerializable
7878
*/
7979
private $identityProfileRequirements;
8080

81+
private ?bool $createIdentityProfilePreview;
82+
8183
/**
8284
* @param int|null $clientSessionTokenTtl
8385
* @param string|null $sessionDeadline
@@ -92,6 +94,7 @@ class SessionSpecification implements JsonSerializable
9294
* @param IbvOptions|null $ibvOptions
9395
* @param object|null $subject
9496
* @param object|null $identityProfileRequirements
97+
* @param bool $createIdentityProfilePreview
9598
*/
9699
public function __construct(
97100
?int $clientSessionTokenTtl,
@@ -106,7 +109,8 @@ public function __construct(
106109
?bool $blockBiometricConsent = null,
107110
?IbvOptions $ibvOptions = null,
108111
$subject = null,
109-
$identityProfileRequirements = null
112+
$identityProfileRequirements = null,
113+
?bool $createIdentityProfilePreview = null
110114
) {
111115
$this->clientSessionTokenTtl = $clientSessionTokenTtl;
112116
$this->sessionDeadline = $sessionDeadline;
@@ -121,6 +125,7 @@ public function __construct(
121125
$this->ibvOptions = $ibvOptions;
122126
$this->subject = $subject;
123127
$this->identityProfileRequirements = $identityProfileRequirements;
128+
$this->createIdentityProfilePreview = $createIdentityProfilePreview;
124129
}
125130

126131
/**
@@ -142,6 +147,7 @@ public function jsonSerialize(): stdClass
142147
'ibv_options' => $this->getIbvOptions(),
143148
'subject' => $this->getSubject(),
144149
'identity_profile_requirements' => $this->getIdentityProfileRequirements(),
150+
'create_identity_profile_preview' => $this->getCreateIdentityProfilePreview(),
145151
]);
146152
}
147153

@@ -253,4 +259,9 @@ public function getIdentityProfileRequirements()
253259
{
254260
return $this->identityProfileRequirements;
255261
}
262+
263+
public function getCreateIdentityProfilePreview(): ?bool
264+
{
265+
return $this->createIdentityProfilePreview;
266+
}
256267
}

src/DocScan/Session/Create/SessionSpecificationBuilder.php

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,11 @@ class SessionSpecificationBuilder
7777
*/
7878
private $identityProfileRequirements;
7979

80+
/**
81+
* @var bool
82+
*/
83+
private bool $createIdentityProfilePreview = false;
84+
8085
/**
8186
* @param int $clientSessionTokenTtl
8287
* @return $this
@@ -243,6 +248,15 @@ public function withIdentityProfileRequirements($identityProfileRequirements): s
243248
return $this;
244249
}
245250

251+
/**
252+
* @return $this
253+
*/
254+
public function withCreateIdentityProfilePreview(): self
255+
{
256+
$this->createIdentityProfilePreview = true;
257+
return $this;
258+
}
259+
246260
/**
247261
* @return SessionSpecification
248262
*/
@@ -261,7 +275,8 @@ public function build(): SessionSpecification
261275
$this->blockBiometricConsent,
262276
$this->ibvOptions,
263277
$this->subject,
264-
$this->identityProfileRequirements
278+
$this->identityProfileRequirements,
279+
$this->createIdentityProfilePreview,
265280
);
266281
}
267282
}

src/DocScan/Session/Retrieve/GetSessionResult.php

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

52-
/**
53-
* @var IdentityProfileResponse
54-
*/
55-
private $identityProfile;
52+
private ?IdentityProfileResponse $identityProfile;
53+
54+
private ?IdentityProfilePreviewResponse $identityProfilePreview;
5655

5756
/**
5857
* DocScanSession constructor.
@@ -85,6 +84,12 @@ public function __construct(array $sessionData)
8584
if (isset($sessionData['identity_profile'])) {
8685
$this->identityProfile = new IdentityProfileResponse($sessionData['identity_profile']);
8786
}
87+
88+
if (isset($sessionData['identity_profile_preview'])) {
89+
$this->identityProfilePreview = new IdentityProfilePreviewResponse(
90+
$sessionData['identity_profile_preview']
91+
);
92+
}
8893
}
8994

9095
/**
@@ -300,11 +305,13 @@ function ($checkResponse) use ($class): bool {
300305
return array_values($filtered);
301306
}
302307

303-
/**
304-
* @return IdentityProfileResponse
305-
*/
306-
public function getIdentityProfile(): IdentityProfileResponse
308+
public function getIdentityProfile(): ?IdentityProfileResponse
307309
{
308310
return $this->identityProfile;
309311
}
312+
313+
public function getIdentityProfilePreview(): ?IdentityProfilePreviewResponse
314+
{
315+
return $this->identityProfilePreview;
316+
}
310317
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
3+
namespace Yoti\DocScan\Session\Retrieve;
4+
5+
class IdentityProfilePreviewResponse
6+
{
7+
private ?MediaResponse $media = null;
8+
9+
public function __construct(array $sessionData)
10+
{
11+
if (isset($sessionData['media'])) {
12+
$this->media = new MediaResponse($sessionData['media']);
13+
}
14+
}
15+
16+
/**
17+
* @return MediaResponse|null
18+
*/
19+
public function getMedia(): ?MediaResponse
20+
{
21+
return $this->media;
22+
}
23+
}

tests/DocScan/Session/Create/SessionSpecificationBuilderTest.php

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,7 @@ public function shouldReturnCorrectJsonString()
219219
'requested_tasks' => [$this->requestedTaskMock],
220220
'required_documents' => [$this->requiredDocumentMock],
221221
'block_biometric_consent' => true,
222+
'create_identity_profile_preview' => false,
222223
]),
223224
json_encode($sessionSpecification)
224225
);
@@ -237,6 +238,7 @@ public function shouldReturnCorrectJsonStringWithoutOptionalProperties()
237238
'requested_checks' => [],
238239
'requested_tasks' => [],
239240
'required_documents' => [],
241+
'create_identity_profile_preview' => false,
240242
]),
241243
json_encode($sessionSpecification)
242244
);
@@ -257,6 +259,7 @@ public function shouldReturnCorrectJsonStringWithBlockBiometricConsentTrue()
257259
'requested_checks' => [],
258260
'requested_tasks' => [],
259261
'required_documents' => [],
262+
'create_identity_profile_preview' => false,
260263
'block_biometric_consent' => true,
261264
]),
262265
json_encode($sessionSpecification)
@@ -278,6 +281,7 @@ public function shouldReturnCorrectJsonStringWithBlockBiometricConsentFalse()
278281
'requested_checks' => [],
279282
'requested_tasks' => [],
280283
'required_documents' => [],
284+
'create_identity_profile_preview' => false,
281285
'block_biometric_consent' => false,
282286
]),
283287
json_encode($sessionSpecification)
@@ -335,6 +339,7 @@ public function shouldReturnCorrectJsonStringWithIbvOptions()
335339
'requested_checks' => [],
336340
'requested_tasks' => [],
337341
'required_documents' => [],
342+
'create_identity_profile_preview' => false,
338343
'ibv_options' => $this->ibvOptionsMock,
339344
]),
340345
json_encode($sessionSpecification)
@@ -389,6 +394,7 @@ public function shouldReturnCorrectJsonStringWithSubject()
389394
'requested_checks' => [],
390395
'requested_tasks' => [],
391396
'required_documents' => [],
397+
'create_identity_profile_preview' => false,
392398
'subject' => $this->subject,
393399
]),
394400
json_encode($sessionSpecification)
@@ -446,9 +452,36 @@ public function shouldReturnCorrectJsonStringWithIdentityProfileRequirements()
446452
'requested_checks' => [],
447453
'requested_tasks' => [],
448454
'required_documents' => [],
455+
'create_identity_profile_preview' => false,
449456
'identity_profile_requirements' => $this->identityProfileRequirements,
450457
]),
451458
json_encode($sessionSpecification)
452459
);
453460
}
461+
462+
/**
463+
* @test
464+
* @covers \Yoti\DocScan\Session\Create\SessionSpecification::jsonSerialize
465+
* @covers \Yoti\DocScan\Session\Create\SessionSpecification::getCreateIdentityProfilePreview
466+
* @covers \Yoti\DocScan\Session\Create\SessionSpecification::__construct
467+
* @covers \Yoti\DocScan\Session\Create\SessionSpecification::jsonSerialize
468+
* @covers \Yoti\DocScan\Session\Create\SessionSpecificationBuilder::withCreateIdentityProfilePreview
469+
* @covers \Yoti\DocScan\Session\Create\SessionSpecificationBuilder::build
470+
*/
471+
public function shouldReturnCorrectJsonStringWithIdentityProfilePreviewTrue()
472+
{
473+
$sessionSpecification = (new SessionSpecificationBuilder())
474+
->withCreateIdentityProfilePreview()
475+
->build();
476+
477+
$this->assertJsonStringEqualsJsonString(
478+
json_encode([
479+
'requested_checks' => [],
480+
'requested_tasks' => [],
481+
'required_documents' => [],
482+
'create_identity_profile_preview' => true,
483+
]),
484+
json_encode($sessionSpecification)
485+
);
486+
}
454487
}

tests/DocScan/Session/Retrieve/GetSessionResultTest.php

Lines changed: 24 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\IdentityProfilePreviewResponse;
1011
use Yoti\DocScan\Session\Retrieve\IdentityProfileResponse;
1112
use Yoti\DocScan\Session\Retrieve\ThirdPartyIdentityFraudOneCheckResponse;
1213
use Yoti\Test\TestCase;
@@ -234,4 +235,27 @@ public function thirdPartyIdentityFraudOneChecksShouldReturnEmptyCollectionWhenN
234235

235236
$this->assertCount(0, $result->getThirdPartyIdentityFraudOneChecks());
236237
}
238+
239+
/**
240+
* @test
241+
* @covers ::getIdentityProfilePreview
242+
* @covers ::__construct
243+
*/
244+
public function shouldParseIdentityProfilePreviewResponse()
245+
{
246+
$input = [
247+
'identity_profile_preview' => [
248+
'media' => [
249+
'id' => 'SOME_ID',
250+
'type' => 'JSON',
251+
'created' => '2021-06-11T11:39:24Z',
252+
'last_updated' => '2021-06-11T11:39:24Z',
253+
]
254+
],
255+
];
256+
257+
$result = new GetSessionResult($input);
258+
259+
$this->assertInstanceOf(IdentityProfilePreviewResponse::class, $result->getIdentityProfilePreview());
260+
}
237261
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php
2+
3+
namespace Yoti\Test\DocScan\Session\Retrieve;
4+
5+
use Yoti\DocScan\Session\Retrieve\IdentityProfilePreviewResponse;
6+
use Yoti\DocScan\Session\Retrieve\MediaResponse;
7+
use Yoti\Test\TestCase;
8+
9+
/**
10+
* @coversDefaultClass \Yoti\DocScan\Session\Retrieve\IdentityProfilePreviewResponse
11+
*/
12+
class IdentityProfilePreviewResponseTest extends TestCase
13+
{
14+
/**
15+
* @test
16+
* @covers ::__construct
17+
* @covers ::getMedia
18+
*/
19+
public function shouldCreatedCorrectly(): void
20+
{
21+
$data = [
22+
'media' => [
23+
'id' => 'SOME_ID',
24+
'type' => 'JSON',
25+
'created' => '2021-06-11T11:39:24Z',
26+
'last_updated' => '2021-06-11T11:39:24Z',
27+
]
28+
];
29+
30+
$result = new IdentityProfilePreviewResponse($data);
31+
32+
$this->assertInstanceOf(IdentityProfilePreviewResponse::class, $result);
33+
$this->assertInstanceOf(MediaResponse::class, $result->getMedia());
34+
}
35+
}

0 commit comments

Comments
 (0)