Skip to content

Commit 091ed0f

Browse files
Rodion LiuboretsLuborRod
authored andcommitted
SDK-1954 Add IbvOptions for session specigfication
1 parent 25cbde5 commit 091ed0f

File tree

7 files changed

+277
-3
lines changed

7 files changed

+277
-3
lines changed

src/DocScan/Constants.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ class Constants
2222
public const FUZZY = 'FUZZY';
2323
public const FACE_CAPTURE = 'FACE_CAPTURE';
2424

25+
public const MANDATORY = "MANDATORY";
26+
public const NOT_ALLOWED = "NOT_ALLOWED";
27+
2528

2629
public const ADVERSE_MEDIA = 'ADVERSE-MEDIA';
2730
public const SANCTIONS = 'SANCTIONS';
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<?php
2+
3+
namespace Yoti\DocScan\Session\Create;
4+
5+
class IbvOptions
6+
{
7+
/**
8+
* @var string
9+
*/
10+
private $support;
11+
12+
/**
13+
* @var string|null
14+
*/
15+
private $guidanceUrl;
16+
17+
/**
18+
* @param string $support
19+
* @param string|null $guidanceUrl
20+
*/
21+
public function __construct(string $support, ?string $guidanceUrl = null)
22+
{
23+
$this->support = $support;
24+
$this->guidanceUrl = $guidanceUrl;
25+
}
26+
27+
/**
28+
* @return string
29+
*/
30+
public function getSupport(): string
31+
{
32+
return $this->support;
33+
}
34+
35+
/**
36+
* @return string
37+
*/
38+
public function getGuidanceUrl(): ?string
39+
{
40+
return $this->guidanceUrl;
41+
}
42+
}
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
<?php
2+
3+
namespace Yoti\DocScan\Session\Create;
4+
5+
use Yoti\DocScan\Constants;
6+
7+
class IbvOptionsBuilder
8+
{
9+
/**
10+
* @var string
11+
*/
12+
private $support;
13+
14+
/**
15+
* @var string|null
16+
*/
17+
private $guidanceUrl;
18+
19+
/**
20+
* @return $this
21+
*/
22+
public function withIbvNotAllowed(): IbvOptionsBuilder
23+
{
24+
return $this->withSupport(Constants::NOT_ALLOWED);
25+
}
26+
27+
/**
28+
* @return $this
29+
*/
30+
public function withIbvMandatory(): IbvOptionsBuilder
31+
{
32+
return $this->withSupport(Constants::MANDATORY);
33+
}
34+
35+
/**
36+
* @param string $support
37+
* @return $this
38+
*/
39+
public function withSupport(string $support): IbvOptionsBuilder
40+
{
41+
$this->support = $support;
42+
return $this;
43+
}
44+
45+
/**
46+
* @param string $guidanceUrl
47+
* @return $this
48+
*/
49+
public function withGuidanceUrl(string $guidanceUrl): IbvOptionsBuilder
50+
{
51+
$this->guidanceUrl = $guidanceUrl;
52+
return $this;
53+
}
54+
55+
/**
56+
* @return IbvOptions
57+
*/
58+
public function build(): IbvOptions
59+
{
60+
return new IbvOptions($this->support, $this->guidanceUrl);
61+
}
62+
}

src/DocScan/Session/Create/SessionSpecification.php

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,11 @@ class SessionSpecification implements JsonSerializable
6363
private $blockBiometricConsent;
6464

6565
/**
66-
* SessionSpecification constructor.
66+
* @var IbvOptions|null
67+
*/
68+
private $ibvOptions;
69+
70+
/**
6771
* @param int|null $clientSessionTokenTtl
6872
* @param string|null $sessionDeadline
6973
* @param int|null $resourcesTtl
@@ -74,6 +78,7 @@ class SessionSpecification implements JsonSerializable
7478
* @param SdkConfig|null $sdkConfig
7579
* @param RequiredDocument[] $requiredDocuments
7680
* @param bool|null $blockBiometricConsent
81+
* @param IbvOptions|null $ibvOptions
7782
*/
7883
public function __construct(
7984
?int $clientSessionTokenTtl,
@@ -85,7 +90,8 @@ public function __construct(
8590
array $requestedTasks,
8691
?SdkConfig $sdkConfig,
8792
array $requiredDocuments = [],
88-
?bool $blockBiometricConsent = null
93+
?bool $blockBiometricConsent = null,
94+
?IbvOptions $ibvOptions = null
8995
) {
9096
$this->clientSessionTokenTtl = $clientSessionTokenTtl;
9197
$this->sessionDeadline = $sessionDeadline;
@@ -97,6 +103,7 @@ public function __construct(
97103
$this->sdkConfig = $sdkConfig;
98104
$this->requiredDocuments = $requiredDocuments;
99105
$this->blockBiometricConsent = $blockBiometricConsent;
106+
$this->ibvOptions = $ibvOptions;
100107
}
101108

102109
/**
@@ -115,6 +122,7 @@ public function jsonSerialize(): array
115122
'sdk_config' => $this->getSdkConfig(),
116123
'required_documents' => $this->getRequiredDocuments(),
117124
'block_biometric_consent' => $this->getBlockBiometricConsent(),
125+
'ibv_options' => $this->getIbvOptions(),
118126
]);
119127
}
120128

@@ -199,4 +207,15 @@ public function getBlockBiometricConsent(): ?bool
199207
{
200208
return $this->blockBiometricConsent;
201209
}
210+
211+
/**
212+
* The options that define if a session will be required to be performed
213+
* using In-Branch Verification
214+
*
215+
* @return IbvOptions|null
216+
*/
217+
public function getIbvOptions(): ?IbvOptions
218+
{
219+
return $this->ibvOptions;
220+
}
202221
}

src/DocScan/Session/Create/SessionSpecificationBuilder.php

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,11 @@ class SessionSpecificationBuilder
6262
*/
6363
private $blockBiometricConsent;
6464

65+
/**
66+
* @var IbvOptions|null
67+
*/
68+
private $ibvOptions;
69+
6570
/**
6671
* @param int $clientSessionTokenTtl
6772
* @return $this
@@ -188,6 +193,20 @@ public function withBlockBiometricConsent(bool $blockBiometricConsent): self
188193
return $this;
189194
}
190195

196+
/**
197+
* Sets the options that define if a session will be required to be performed
198+
* using In-Branch Verification
199+
*
200+
* @param IbvOptions $ibvOptions
201+
*
202+
* @return $this
203+
*/
204+
public function withIbvOptions(IbvOptions $ibvOptions): self
205+
{
206+
$this->ibvOptions = $ibvOptions;
207+
return $this;
208+
}
209+
191210
/**
192211
* @return SessionSpecification
193212
*/
@@ -203,7 +222,8 @@ public function build(): SessionSpecification
203222
$this->requestedTasks,
204223
$this->sdkConfig,
205224
$this->requiredDocuments,
206-
$this->blockBiometricConsent
225+
$this->blockBiometricConsent,
226+
$this->ibvOptions
207227
);
208228
}
209229
}
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
<?php
2+
3+
namespace Yoti\Test\DocScan\Session\Create;
4+
5+
use Yoti\DocScan\Session\Create\IbvOptionsBuilder;
6+
use Yoti\Test\TestCase;
7+
8+
/**
9+
* @coversDefaultClass \Yoti\DocScan\Session\Create\IbvOptionsBuilder
10+
*/
11+
class IbvOptionsBuilderTest extends TestCase
12+
{
13+
private const SOME_SUPPORT_VALUE = "someSupportValue";
14+
private const SOME_GUIDANCE_URL = "someGuidanceUrl";
15+
16+
/**
17+
* @test
18+
* @covers ::build
19+
* @covers ::withIbvMandatory
20+
* @covers \Yoti\DocScan\Session\Create\IbvOptions::__construct
21+
* @covers \Yoti\DocScan\Session\Create\IbvOptions::getSupport
22+
*/
23+
public function builderWithMandatorySupportShouldSetCorrectSupportValue()
24+
{
25+
$result = (new IbvOptionsBuilder())
26+
->withIbvMandatory()
27+
->build();
28+
29+
$this->assertEquals('MANDATORY', $result->getSupport());
30+
}
31+
32+
/**
33+
* @test
34+
* @covers ::build
35+
* @covers ::withIbvNotAllowed
36+
* @covers \Yoti\DocScan\Session\Create\IbvOptions::__construct
37+
* @covers \Yoti\DocScan\Session\Create\IbvOptions::getSupport
38+
*/
39+
public function builderWithNotAllowedSupportShouldSetCorrectSupportValue()
40+
{
41+
$result = (new IbvOptionsBuilder())
42+
->withIbvNotAllowed()
43+
->build();
44+
45+
$this->assertEquals('NOT_ALLOWED', $result->getSupport());
46+
}
47+
48+
/**
49+
* @test
50+
* @covers ::build
51+
* @covers ::withSupport
52+
* @covers \Yoti\DocScan\Session\Create\IbvOptions::__construct
53+
* @covers \Yoti\DocScan\Session\Create\IbvOptions::getSupport
54+
*/
55+
public function builderShouldAllowUserOverrideOfSupportValue()
56+
{
57+
$result = (new IbvOptionsBuilder())
58+
->withSupport(self::SOME_SUPPORT_VALUE)
59+
->build();
60+
61+
$this->assertEquals(self::SOME_SUPPORT_VALUE, $result->getSupport());
62+
}
63+
64+
/**
65+
* @test
66+
* @covers ::build
67+
* @covers ::withIbvMandatory
68+
* @covers ::withGuidanceUrl
69+
* @covers \Yoti\DocScan\Session\Create\IbvOptions::__construct
70+
* @covers \Yoti\DocScan\Session\Create\IbvOptions::getGuidanceUrl
71+
*/
72+
public function builderShouldSetCorrectGuidanceUrlValue()
73+
{
74+
$result = (new IbvOptionsBuilder())
75+
->withIbvMandatory()
76+
->withGuidanceUrl(self::SOME_GUIDANCE_URL)
77+
->build();
78+
79+
$this->assertEquals(self::SOME_GUIDANCE_URL, $result->getGuidanceUrl());
80+
}
81+
}

tests/DocScan/Session/Create/SessionSpecificationBuilderTest.php

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
use Yoti\DocScan\Session\Create\Check\RequestedCheck;
88
use Yoti\DocScan\Session\Create\Filters\RequiredDocument;
9+
use Yoti\DocScan\Session\Create\IbvOptions;
910
use Yoti\DocScan\Session\Create\NotificationConfig;
1011
use Yoti\DocScan\Session\Create\SdkConfig;
1112
use Yoti\DocScan\Session\Create\SessionSpecificationBuilder;
@@ -46,6 +47,11 @@ class SessionSpecificationBuilderTest extends TestCase
4647
*/
4748
private $requiredDocumentMock;
4849

50+
/**
51+
* @var IbvOptions
52+
*/
53+
private $ibvOptionsMock;
54+
4955
public function setup(): void
5056
{
5157
$this->sdkConfigMock = $this->createMock(SdkConfig::class);
@@ -62,6 +68,8 @@ public function setup(): void
6268

6369
$this->requiredDocumentMock = $this->createMock(RequiredDocument::class);
6470
$this->requiredDocumentMock->method('jsonSerialize')->willReturn((object)['requiredDocument']);
71+
72+
$this->ibvOptionsMock = $this->createMock(IbvOptions::class);
6573
}
6674

6775
/**
@@ -273,4 +281,43 @@ public function shouldSetTheSessionDeadline()
273281

274282
$this->assertEquals($correctDateFormatValue, $sessionSpecificationResult->getSessionDeadline());
275283
}
284+
285+
/**
286+
* @test
287+
* @covers \Yoti\DocScan\Session\Create\SessionSpecification::getIbvOptions
288+
* @covers \Yoti\DocScan\Session\Create\SessionSpecification::__construct
289+
* @covers \Yoti\DocScan\Session\Create\SessionSpecificationBuilder::withIbvOptions
290+
* @covers \Yoti\DocScan\Session\Create\SessionSpecificationBuilder::build
291+
*/
292+
public function withIbvOptionsShouldSetTheIbvOptions()
293+
{
294+
$sessionSpecificationResult = (new SessionSpecificationBuilder())
295+
->withIbvOptions($this->ibvOptionsMock)
296+
->build();
297+
298+
$this->assertEquals($this->ibvOptionsMock, $sessionSpecificationResult->getIbvOptions());
299+
}
300+
301+
/**
302+
* @test
303+
* @covers \Yoti\DocScan\Session\Create\SessionSpecification::jsonSerialize
304+
* @covers \Yoti\DocScan\Session\Create\SessionSpecificationBuilder::withIbvOptions
305+
* @covers \Yoti\DocScan\Session\Create\SessionSpecificationBuilder::build
306+
*/
307+
public function shouldReturnCorrectJsonStringWithIbvOptions()
308+
{
309+
$sessionSpecification = (new SessionSpecificationBuilder())
310+
->withIbvOptions($this->ibvOptionsMock)
311+
->build();
312+
313+
$this->assertJsonStringEqualsJsonString(
314+
json_encode([
315+
'requested_checks' => [],
316+
'requested_tasks' => [],
317+
'required_documents' => [],
318+
'ibv_options' => $this->ibvOptionsMock,
319+
]),
320+
json_encode($sessionSpecification)
321+
);
322+
}
276323
}

0 commit comments

Comments
 (0)