Skip to content

Commit b7e6ea3

Browse files
LuborRodRodion Liuborets
andauthored
SDK-2101 Add subject to IDV request (#277)
Co-authored-by: Rodion Liuborets <[email protected]>
1 parent b2e7bd8 commit b7e6ea3

File tree

3 files changed

+98
-2
lines changed

3 files changed

+98
-2
lines changed

src/DocScan/Session/Create/SessionSpecification.php

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,11 @@ class SessionSpecification implements JsonSerializable
6868
*/
6969
private $ibvOptions;
7070

71+
/**
72+
* @var object|null
73+
*/
74+
private $subject;
75+
7176
/**
7277
* @param int|null $clientSessionTokenTtl
7378
* @param string|null $sessionDeadline
@@ -80,6 +85,7 @@ class SessionSpecification implements JsonSerializable
8085
* @param RequiredDocument[] $requiredDocuments
8186
* @param bool|null $blockBiometricConsent
8287
* @param IbvOptions|null $ibvOptions
88+
* @param object|null $subject
8389
*/
8490
public function __construct(
8591
?int $clientSessionTokenTtl,
@@ -92,7 +98,8 @@ public function __construct(
9298
?SdkConfig $sdkConfig,
9399
array $requiredDocuments = [],
94100
?bool $blockBiometricConsent = null,
95-
?IbvOptions $ibvOptions = null
101+
?IbvOptions $ibvOptions = null,
102+
$subject = null
96103
) {
97104
$this->clientSessionTokenTtl = $clientSessionTokenTtl;
98105
$this->sessionDeadline = $sessionDeadline;
@@ -105,6 +112,7 @@ public function __construct(
105112
$this->requiredDocuments = $requiredDocuments;
106113
$this->blockBiometricConsent = $blockBiometricConsent;
107114
$this->ibvOptions = $ibvOptions;
115+
$this->subject = $subject;
108116
}
109117

110118
/**
@@ -124,6 +132,7 @@ public function jsonSerialize(): stdClass
124132
'required_documents' => $this->getRequiredDocuments(),
125133
'block_biometric_consent' => $this->getBlockBiometricConsent(),
126134
'ibv_options' => $this->getIbvOptions(),
135+
'subject' => $this->getSubject(),
127136
]);
128137
}
129138

@@ -219,4 +228,12 @@ public function getIbvOptions(): ?IbvOptions
219228
{
220229
return $this->ibvOptions;
221230
}
231+
232+
/**
233+
* @return object|null
234+
*/
235+
public function getSubject()
236+
{
237+
return $this->subject;
238+
}
222239
}

src/DocScan/Session/Create/SessionSpecificationBuilder.php

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,11 @@ class SessionSpecificationBuilder
6767
*/
6868
private $ibvOptions;
6969

70+
/**
71+
* @var object|null
72+
*/
73+
private $subject;
74+
7075
/**
7176
* @param int $clientSessionTokenTtl
7277
* @return $this
@@ -207,6 +212,19 @@ public function withIbvOptions(IbvOptions $ibvOptions): self
207212
return $this;
208213
}
209214

215+
/**
216+
* Sets the Subject object for the session
217+
*
218+
* @param object $subject
219+
*
220+
* @return $this
221+
*/
222+
public function withSubject($subject): self
223+
{
224+
$this->subject = $subject;
225+
return $this;
226+
}
227+
210228
/**
211229
* @return SessionSpecification
212230
*/
@@ -223,7 +241,8 @@ public function build(): SessionSpecification
223241
$this->sdkConfig,
224242
$this->requiredDocuments,
225243
$this->blockBiometricConsent,
226-
$this->ibvOptions
244+
$this->ibvOptions,
245+
$this->subject
227246
);
228247
}
229248
}

tests/DocScan/Session/Create/SessionSpecificationBuilderTest.php

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,11 @@ class SessionSpecificationBuilderTest extends TestCase
5252
*/
5353
private $ibvOptionsMock;
5454

55+
/**
56+
* @var object
57+
*/
58+
private $subject;
59+
5560
public function setup(): void
5661
{
5762
$this->sdkConfigMock = $this->createMock(SdkConfig::class);
@@ -70,6 +75,7 @@ public function setup(): void
7075
$this->requiredDocumentMock->method('jsonSerialize')->willReturn((object)['requiredDocument']);
7176

7277
$this->ibvOptionsMock = $this->createMock(IbvOptions::class);
78+
$this->subject = (object)[1 => 'some'];
7379
}
7480

7581
/**
@@ -320,4 +326,58 @@ public function shouldReturnCorrectJsonStringWithIbvOptions()
320326
json_encode($sessionSpecification)
321327
);
322328
}
329+
330+
/**
331+
* @test
332+
* @covers \Yoti\DocScan\Session\Create\SessionSpecification::getSubject
333+
* @covers \Yoti\DocScan\Session\Create\SessionSpecification::__construct
334+
* @covers \Yoti\DocScan\Session\Create\SessionSpecificationBuilder::withSubject
335+
* @covers \Yoti\DocScan\Session\Create\SessionSpecificationBuilder::build
336+
*/
337+
public function shouldBuildWithSubject()
338+
{
339+
$sessionSpecificationResult = (new SessionSpecificationBuilder())
340+
->withSubject($this->subject)
341+
->build();
342+
343+
$this->assertEquals($this->subject, $sessionSpecificationResult->getSubject());
344+
}
345+
346+
/**
347+
* @test
348+
* @covers \Yoti\DocScan\Session\Create\SessionSpecification::getSubject
349+
* @covers \Yoti\DocScan\Session\Create\SessionSpecification::__construct
350+
* @covers \Yoti\DocScan\Session\Create\SessionSpecificationBuilder::withSubject
351+
* @covers \Yoti\DocScan\Session\Create\SessionSpecificationBuilder::build
352+
*/
353+
public function shouldNotImplicitlySetAValueForSubject()
354+
{
355+
$sessionSpecificationResult = (new SessionSpecificationBuilder())
356+
->build();
357+
358+
$this->assertNull($sessionSpecificationResult->getSubject());
359+
}
360+
361+
/**
362+
* @test
363+
* @covers \Yoti\DocScan\Session\Create\SessionSpecification::jsonSerialize
364+
* @covers \Yoti\DocScan\Session\Create\SessionSpecificationBuilder::withSubject
365+
* @covers \Yoti\DocScan\Session\Create\SessionSpecificationBuilder::build
366+
*/
367+
public function shouldReturnCorrectJsonStringWithSubject()
368+
{
369+
$sessionSpecification = (new SessionSpecificationBuilder())
370+
->withSubject($this->subject)
371+
->build();
372+
373+
$this->assertJsonStringEqualsJsonString(
374+
json_encode([
375+
'requested_checks' => [],
376+
'requested_tasks' => [],
377+
'required_documents' => [],
378+
'subject' => $this->subject,
379+
]),
380+
json_encode($sessionSpecification)
381+
);
382+
}
323383
}

0 commit comments

Comments
 (0)