Skip to content

Commit e93c02d

Browse files
LuborRodRodion Liuborets
andauthored
SDK-1895 Add new logic (#264)
Co-authored-by: Rodion Liuborets <[email protected]>
1 parent 94f05ea commit e93c02d

File tree

6 files changed

+243
-3
lines changed

6 files changed

+243
-3
lines changed

src/DocScan/Constants.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,4 +51,7 @@ class Constants
5151
public const END_USER = 'END_USER';
5252
public const RELYING_BUSINESS = 'RELYING_BUSINESS';
5353
public const IBV = 'IBV';
54+
55+
public const RECLASSIFICATION = "RECLASSIFICATION";
56+
public const GENERIC = "GENERIC";
5457
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
3+
namespace Yoti\DocScan\Session\Create;
4+
5+
class AttemptsConfiguration
6+
{
7+
/**
8+
* JsonProperty "ID_DOCUMENT_TEXT_DATA_EXTRACTION"
9+
*
10+
* @var array<string, int>
11+
*/
12+
public $idDocumentTextDataExtraction;
13+
14+
/**
15+
* @param array<string, int> $idDocumentTextDataExtraction
16+
*/
17+
public function __construct(array $idDocumentTextDataExtraction)
18+
{
19+
$this->idDocumentTextDataExtraction = $idDocumentTextDataExtraction;
20+
}
21+
22+
/**
23+
* @return array<string, int>
24+
*/
25+
public function getIdDocumentTextDataExtraction(): array
26+
{
27+
return $this->idDocumentTextDataExtraction;
28+
}
29+
}

src/DocScan/Session/Create/SdkConfig.php

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,24 @@ class SdkConfig implements \JsonSerializable
5858
*/
5959
private $allowHandoff;
6060

61+
/**
62+
* @var AttemptsConfiguration|null
63+
*/
64+
private $attemptsConfiguration;
65+
66+
/**
67+
* @param string|null $allowedCaptureMethods
68+
* @param string|null $primaryColour
69+
* @param string|null $secondaryColour
70+
* @param string|null $fontColour
71+
* @param string|null $locale
72+
* @param string|null $presetIssuingCountry
73+
* @param string|null $successUrl
74+
* @param string|null $errorUrl
75+
* @param string|null $privacyPolicyUrl
76+
* @param bool|null $allowHandoff
77+
* @param array<string, int>|null $idDocumentTextDataExtractionRetriesConfig
78+
*/
6179
public function __construct(
6280
?string $allowedCaptureMethods,
6381
?string $primaryColour,
@@ -68,7 +86,8 @@ public function __construct(
6886
?string $successUrl,
6987
?string $errorUrl,
7088
?string $privacyPolicyUrl = null,
71-
?bool $allowHandoff = null
89+
?bool $allowHandoff = null,
90+
?array $idDocumentTextDataExtractionRetriesConfig = null
7291
) {
7392
$this->allowedCaptureMethods = $allowedCaptureMethods;
7493
$this->primaryColour = $primaryColour;
@@ -80,14 +99,17 @@ public function __construct(
8099
$this->errorUrl = $errorUrl;
81100
$this->privacyPolicyUrl = $privacyPolicyUrl;
82101
$this->allowHandoff = $allowHandoff;
102+
if (!is_null($idDocumentTextDataExtractionRetriesConfig)) {
103+
$this->attemptsConfiguration = new AttemptsConfiguration($idDocumentTextDataExtractionRetriesConfig);
104+
}
83105
}
84106

85107
/**
86108
* @return \stdClass
87109
*/
88110
public function jsonSerialize(): \stdClass
89111
{
90-
return (object) Json::withoutNullValues([
112+
return (object)Json::withoutNullValues([
91113
'allowed_capture_methods' => $this->getAllowedCaptureMethods(),
92114
'primary_colour' => $this->getPrimaryColour(),
93115
'secondary_colour' => $this->getSecondaryColour(),
@@ -98,6 +120,7 @@ public function jsonSerialize(): \stdClass
98120
'error_url' => $this->getErrorUrl(),
99121
'privacy_policy_url' => $this->getPrivacyPolicyUrl(),
100122
'allow_handoff' => $this->getAllowHandoff(),
123+
'attempts_configuration' => $this->getAttemptsConfiguration(),
101124
]);
102125
}
103126

@@ -180,4 +203,12 @@ public function getAllowHandoff(): ?bool
180203
{
181204
return $this->allowHandoff;
182205
}
206+
207+
/**
208+
* @return AttemptsConfiguration|null
209+
*/
210+
public function getAttemptsConfiguration(): ?AttemptsConfiguration
211+
{
212+
return $this->attemptsConfiguration;
213+
}
183214
}

src/DocScan/Session/Create/SdkConfigBuilder.php

Lines changed: 56 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
namespace Yoti\DocScan\Session\Create;
66

7+
use Yoti\DocScan\Constants;
8+
79
class SdkConfigBuilder
810
{
911
private const CAMERA = 'CAMERA';
@@ -59,6 +61,11 @@ class SdkConfigBuilder
5961
*/
6062
private $allowHandoff;
6163

64+
/**
65+
* @var array<string,int>|null
66+
*/
67+
private $idDocumentTextDataExtractionRetriesConfig;
68+
6269
public function withAllowsCamera(): self
6370
{
6471
return $this->withAllowedCaptureMethod(self::CAMERA);
@@ -129,6 +136,53 @@ public function withAllowHandoff(bool $allowHandoff): self
129136
return $this;
130137
}
131138

139+
/**
140+
* Allows configuring the number of attempts permitted for text extraction on an ID document
141+
*
142+
* The category for the retries number
143+
* @param string $category
144+
* The number of retries for the category specified
145+
* @param int $retries
146+
* @return SdkConfigBuilder
147+
*/
148+
public function withIdDocumentTextExtractionCategoryRetries(string $category, int $retries): self
149+
{
150+
$this->idDocumentTextDataExtractionRetriesConfig[$category] = $retries;
151+
152+
return $this;
153+
}
154+
155+
/**
156+
* Allows configuring the number of 'Reclassification' attempts permitted for text extraction on an ID document
157+
*
158+
* The number of retries for reclassification
159+
* @param int $reclassificationRetries
160+
* @return $this
161+
*/
162+
public function withIdDocumentTextExtractionReclassificationRetries(int $reclassificationRetries): self
163+
{
164+
$this->withIdDocumentTextExtractionCategoryRetries(
165+
Constants::RECLASSIFICATION,
166+
$reclassificationRetries
167+
);
168+
169+
return $this;
170+
}
171+
172+
/**
173+
* Allows configuring the number of 'Generic' attempts permitted for text extraction on an ID document
174+
*
175+
* The number of generic retries
176+
* @param int $genericRetries
177+
* @return $this
178+
*/
179+
public function withIdDocumentTextExtractionGenericRetries(int $genericRetries): self
180+
{
181+
$this->withIdDocumentTextExtractionCategoryRetries(Constants::GENERIC, $genericRetries);
182+
return $this;
183+
}
184+
185+
132186
public function build(): SdkConfig
133187
{
134188
return new SdkConfig(
@@ -141,7 +195,8 @@ public function build(): SdkConfig
141195
$this->successUrl,
142196
$this->errorUrl,
143197
$this->privacyPolicyUrl,
144-
$this->allowHandoff
198+
$this->allowHandoff,
199+
$this->idDocumentTextDataExtractionRetriesConfig
145200
);
146201
}
147202
}

tests/DocScan/Session/Create/SdkConfigBuilderTest.php

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace Yoti\Test\DocScan\Session\Create;
44

5+
use Yoti\DocScan\Constants;
56
use Yoti\DocScan\Session\Create\SdkConfigBuilder;
67
use Yoti\Test\TestCase;
78

@@ -19,6 +20,8 @@ class SdkConfigBuilderTest extends TestCase
1920
private const SOME_SUCCESS_URL = 'someSuccessUrl';
2021
private const SOME_ERROR_URL = 'someErrorUrl';
2122
private const SOME_PRIVACY_POLICY_URL = 'somePrivacyPolicyUrl';
23+
private const SOME_CATEGORY = 'someCategory';
24+
private const SOME_NUMBER_RETRIES = 5;
2225

2326
/**
2427
* @test
@@ -162,4 +165,122 @@ public function allowHandoffShouldBeNullWhenItIsNotSet()
162165

163166
$this->assertNull($result->getAllowHandoff());
164167
}
168+
169+
/**
170+
* @test
171+
* @covers ::build
172+
* @covers ::withIdDocumentTextExtractionCategoryRetries
173+
* @covers \Yoti\DocScan\Session\Create\SdkConfig::getAttemptsConfiguration
174+
* @covers \Yoti\DocScan\Session\Create\SdkConfig::__construct
175+
* @covers \Yoti\DocScan\Session\Create\AttemptsConfiguration::__construct
176+
* @covers \Yoti\DocScan\Session\Create\AttemptsConfiguration::getIdDocumentTextDataExtraction
177+
*/
178+
public function shouldBuildWithIdDocumentTextExtractionCategoryRetries(): void
179+
{
180+
$data = [
181+
self::SOME_CATEGORY => self::SOME_NUMBER_RETRIES
182+
];
183+
184+
$sdkConfig = (new SdkConfigBuilder())
185+
->withIdDocumentTextExtractionCategoryRetries(self::SOME_CATEGORY, self::SOME_NUMBER_RETRIES)
186+
->build();
187+
188+
$this->assertEquals($data, $sdkConfig->getAttemptsConfiguration()->getIdDocumentTextDataExtraction());
189+
}
190+
191+
/**
192+
* @test
193+
* @covers ::build
194+
* @covers \Yoti\DocScan\Session\Create\SdkConfig::getAttemptsConfiguration
195+
* @covers \Yoti\DocScan\Session\Create\SdkConfig::__construct
196+
*/
197+
public function attemptsConfigurationShouldBeNullIfNotSet(): void
198+
{
199+
$sdkConfig = (new SdkConfigBuilder())
200+
->build();
201+
202+
$this->assertNull($sdkConfig->getAttemptsConfiguration());
203+
}
204+
205+
/**
206+
* @test
207+
* @covers ::build
208+
* @covers ::withIdDocumentTextExtractionCategoryRetries
209+
* @covers ::withIdDocumentTextExtractionReclassificationRetries
210+
* @covers \Yoti\DocScan\Session\Create\SdkConfig::getAttemptsConfiguration
211+
* @covers \Yoti\DocScan\Session\Create\SdkConfig::__construct
212+
* @covers \Yoti\DocScan\Session\Create\AttemptsConfiguration::__construct
213+
* @covers \Yoti\DocScan\Session\Create\AttemptsConfiguration::getIdDocumentTextDataExtraction
214+
*/
215+
public function attemptsConfigurationShouldResetSameValueWithRepeatedCalls(): void
216+
{
217+
$data = [
218+
Constants::RECLASSIFICATION => 4
219+
];
220+
221+
$sdkConfig = (new SdkConfigBuilder())
222+
->withIdDocumentTextExtractionReclassificationRetries(2)
223+
->withIdDocumentTextExtractionReclassificationRetries(3)
224+
->withIdDocumentTextExtractionReclassificationRetries(4)
225+
->build();
226+
227+
$this->assertCount(1, $sdkConfig->getAttemptsConfiguration()->getIdDocumentTextDataExtraction());
228+
$this->assertEquals($data, $sdkConfig->getAttemptsConfiguration()->getIdDocumentTextDataExtraction());
229+
}
230+
231+
/**
232+
* @test
233+
* @covers ::build
234+
* @covers ::withIdDocumentTextExtractionCategoryRetries
235+
* @covers ::withIdDocumentTextExtractionReclassificationRetries
236+
* @covers ::withIdDocumentTextExtractionGenericRetries
237+
* @covers \Yoti\DocScan\Session\Create\SdkConfig::getAttemptsConfiguration
238+
* @covers \Yoti\DocScan\Session\Create\SdkConfig::__construct
239+
* @covers \Yoti\DocScan\Session\Create\AttemptsConfiguration::__construct
240+
* @covers \Yoti\DocScan\Session\Create\AttemptsConfiguration::getIdDocumentTextDataExtraction
241+
*/
242+
public function attemptsConfigurationShouldAllowMultipleCategories(): void
243+
{
244+
$numberOfGenericRetries = 3;
245+
$numberOfReclassificationRetries = 1;
246+
247+
$sdkConfig = (new SdkConfigBuilder())
248+
->withIdDocumentTextExtractionReclassificationRetries($numberOfReclassificationRetries)
249+
->withIdDocumentTextExtractionGenericRetries($numberOfGenericRetries)
250+
->withIdDocumentTextExtractionCategoryRetries(self::SOME_CATEGORY, self::SOME_NUMBER_RETRIES)
251+
->build();
252+
253+
$this->assertCount(3, $sdkConfig->getAttemptsConfiguration()->getIdDocumentTextDataExtraction());
254+
$this->assertArrayHasKey(
255+
Constants::RECLASSIFICATION,
256+
$sdkConfig->getAttemptsConfiguration()
257+
->getIdDocumentTextDataExtraction()
258+
);
259+
$this->assertArrayHasKey(
260+
Constants::GENERIC,
261+
$sdkConfig->getAttemptsConfiguration()
262+
->getIdDocumentTextDataExtraction()
263+
);
264+
$this->assertArrayHasKey(
265+
self::SOME_CATEGORY,
266+
$sdkConfig->getAttemptsConfiguration()
267+
->getIdDocumentTextDataExtraction()
268+
);
269+
270+
$this->assertContains(
271+
$numberOfGenericRetries,
272+
$sdkConfig->getAttemptsConfiguration()
273+
->getIdDocumentTextDataExtraction()
274+
);
275+
$this->assertContains(
276+
$numberOfReclassificationRetries,
277+
$sdkConfig->getAttemptsConfiguration()
278+
->getIdDocumentTextDataExtraction()
279+
);
280+
$this->assertContains(
281+
self::SOME_NUMBER_RETRIES,
282+
$sdkConfig->getAttemptsConfiguration()
283+
->getIdDocumentTextDataExtraction()
284+
);
285+
}
165286
}

tests/Profile/ActivityDetailsTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
namespace Yoti\Test\Profile;
66

7+
use Yoti\Aml\Profile;
78
use Yoti\Media\Image;
89
use Yoti\Profile\ActivityDetails;
910
use Yoti\Profile\ApplicationProfile;

0 commit comments

Comments
 (0)