Skip to content

Commit f3f7c42

Browse files
LuborRodRodion Liuborets
andauthored
Sdk 1958 Allow Relying Business to fetch contact profile (#253)
* SDK-1956 Add main logic * SDK-1956 Add several tests * SDK-1956 Add more tests * SDK-1956 Add last tests * SDK-1957 Add logic and tests * SDK-1957 Small fixes for 7.1 and 7.2 * SDK-1957 Remove code smells * SDK-1958 Add logic and tests * SDK-1958 Add several tests * SDK-1958 Add comments to DocScanClient Co-authored-by: Rodion Liuborets <[email protected]>
1 parent b7caee3 commit f3f7c42

File tree

7 files changed

+249
-2
lines changed

7 files changed

+249
-2
lines changed

src/DocScan/DocScanClient.php

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
use Yoti\DocScan\Session\Instructions\Instructions;
1313
use Yoti\DocScan\Session\Retrieve\Configuration\SessionConfigurationResponse;
1414
use Yoti\DocScan\Session\Retrieve\GetSessionResult;
15+
use Yoti\DocScan\Session\Retrieve\Instructions\ContactProfileResponse;
1516
use Yoti\DocScan\Session\Retrieve\Instructions\InstructionsResponse;
1617
use Yoti\DocScan\Support\SupportedDocumentsResponse;
1718
use Yoti\Media\Media;
@@ -196,6 +197,8 @@ public function putIbvInstructions(string $sessionId, Instructions $instructions
196197
}
197198

198199
/**
200+
* Fetches any currently set instructions for an IBV session.
201+
*
199202
* @param string $sessionId
200203
* @return InstructionsResponse
201204
* @throws Exception\DocScanException
@@ -205,8 +208,9 @@ public function getIbvInstructions(string $sessionId): InstructionsResponse
205208
return $this->docScanService->getIbvInstructions($sessionId);
206209
}
207210

208-
209211
/**
212+
* Fetches the instructions PDF associated with an In-Branch Verification session.
213+
*
210214
* @param string $sessionId
211215
* @return Media
212216
* @throws Exception\DocScanException
@@ -215,4 +219,16 @@ public function getIbvInstructionsPdf(string $sessionId): Media
215219
{
216220
return $this->docScanService->getIbvInstructionsPdf($sessionId);
217221
}
222+
223+
/**
224+
* Fetches the associated instructions contact profile for the given In-Branch Verification session
225+
*
226+
* @param string $sessionId
227+
* @return ContactProfileResponse
228+
* @throws Exception\DocScanException
229+
*/
230+
public function fetchInstructionsContactProfile(string $sessionId): ContactProfileResponse
231+
{
232+
return $this->docScanService->fetchInstructionsContactProfile($sessionId);
233+
}
218234
}

src/DocScan/Service.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use Yoti\DocScan\Session\Retrieve\Configuration\SessionConfigurationResponse;
1616
use Yoti\DocScan\Session\Retrieve\CreateFaceCaptureResourceResponse;
1717
use Yoti\DocScan\Session\Retrieve\GetSessionResult;
18+
use Yoti\DocScan\Session\Retrieve\Instructions\ContactProfileResponse;
1819
use Yoti\DocScan\Session\Retrieve\Instructions\InstructionsResponse;
1920
use Yoti\DocScan\Support\SupportedDocumentsResponse;
2021
use Yoti\Http\Payload;
@@ -355,6 +356,28 @@ public function getIbvInstructionsPdf(string $sessionId): Media
355356
return new Media($mimeType, $content);
356357
}
357358

359+
/**
360+
* @param string $sessionId
361+
* @return ContactProfileResponse
362+
* @throws DocScanException
363+
*/
364+
public function fetchInstructionsContactProfile(string $sessionId): ContactProfileResponse
365+
{
366+
$response = (new RequestBuilder($this->config))
367+
->withBaseUrl($this->apiUrl)
368+
->withPemFile($this->pemFile)
369+
->withEndpoint(sprintf('/sessions/%s/instructions/contact-profile', $sessionId))
370+
->withGet()
371+
->build()
372+
->execute();
373+
374+
self::assertResponseIsSuccess($response);
375+
376+
$result = Json::decode((string)$response->getBody());
377+
378+
return new ContactProfileResponse($result);
379+
}
380+
358381
/**
359382
* @param ResponseInterface $response
360383
*
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
<?php
2+
3+
namespace Yoti\DocScan\Session\Retrieve\Instructions;
4+
5+
class ContactProfileResponse
6+
{
7+
/**
8+
* @var string|null
9+
*/
10+
private $firstName;
11+
12+
/**
13+
* @var string|null
14+
*/
15+
private $lastName;
16+
17+
/**
18+
* @var string|null
19+
*/
20+
private $email;
21+
22+
/**
23+
* @param string[] $contactProfileData
24+
*/
25+
public function __construct(array $contactProfileData)
26+
{
27+
$this->firstName = $contactProfileData['first_name'] ?? null;
28+
$this->lastName = $contactProfileData['last_name'] ?? null;
29+
$this->email = $contactProfileData['email'] ?? null;
30+
}
31+
32+
/**
33+
* @return string|null
34+
*/
35+
public function getFirstName(): ?string
36+
{
37+
return $this->firstName;
38+
}
39+
40+
/**
41+
* @return string|null
42+
*/
43+
public function getLastName(): ?string
44+
{
45+
return $this->lastName;
46+
}
47+
48+
/**
49+
* @return string|null
50+
*/
51+
public function getEmail(): ?string
52+
{
53+
return $this->email;
54+
}
55+
}

tests/DocScan/DocScanClientTest.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -428,4 +428,28 @@ public function testGetIbvInstructionsPdf()
428428
TestData::DOC_SCAN_SESSION_ID
429429
);
430430
}
431+
432+
/**
433+
* @test
434+
* @covers ::fetchInstructionsContactProfile
435+
*/
436+
public function testFetchInstructionsContactProfile()
437+
{
438+
$response = $this->createMock(ResponseInterface::class);
439+
$response->method('getBody')->willReturn(json_encode((object)[]));
440+
$response->method('getStatusCode')->willReturn(200);
441+
442+
$httpClient = $this->createMock(ClientInterface::class);
443+
$httpClient->expects($this->exactly(1))
444+
->method('sendRequest')
445+
->willReturn($response);
446+
447+
$docScanClient = new DocScanClient(TestData::SDK_ID, TestData::PEM_FILE, [
448+
Config::HTTP_CLIENT => $httpClient,
449+
]);
450+
451+
$docScanClient->fetchInstructionsContactProfile(
452+
TestData::DOC_SCAN_SESSION_ID
453+
);
454+
}
431455
}

tests/DocScan/ServiceTest.php

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@
1818
use Yoti\DocScan\Session\Retrieve\Configuration\SessionConfigurationResponse;
1919
use Yoti\DocScan\Session\Retrieve\CreateFaceCaptureResourceResponse;
2020
use Yoti\DocScan\Session\Retrieve\GetSessionResult;
21+
use Yoti\DocScan\Session\Retrieve\Instructions\ContactProfileResponse;
2122
use Yoti\DocScan\Support\SupportedDocumentsResponse;
23+
use Yoti\Exception\PemFileException;
2224
use Yoti\Media\Media;
2325
use Yoti\Test\TestCase;
2426
use Yoti\Test\TestData;
@@ -1213,4 +1215,93 @@ function (RequestInterface $requestMessage) {
12131215

12141216
$docScanService->getIbvInstructionsPdf(TestData::DOC_SCAN_SESSION_ID);
12151217
}
1218+
1219+
/**
1220+
* @test
1221+
* @covers ::__construct
1222+
* @covers ::fetchInstructionsContactProfile
1223+
* @covers ::assertResponseIsSuccess
1224+
* @throws DocScanException|PemFileException
1225+
*/
1226+
public function fetchInstructionsContactProfileShouldReturnContactProfileOnSuccessfulCall()
1227+
{
1228+
$httpClient = $this->createMock(ClientInterface::class);
1229+
$httpClient->expects($this->exactly(1))
1230+
->method('sendRequest')
1231+
->with(
1232+
$this->callback(
1233+
function (RequestInterface $requestMessage) {
1234+
$expectedPathPattern = sprintf(
1235+
'~^%s/sessions/%s/instructions/contact-profile.*?~',
1236+
TestData::DOC_SCAN_BASE_URL,
1237+
TestData::DOC_SCAN_SESSION_ID
1238+
);
1239+
1240+
$this->assertEquals('GET', $requestMessage->getMethod());
1241+
$this->assertMatchesRegularExpression($expectedPathPattern, (string)$requestMessage->getUri());
1242+
return true;
1243+
}
1244+
)
1245+
)
1246+
->willReturn($this->createResponse(200, json_encode((object)[])));
1247+
1248+
$docScanService = new Service(
1249+
TestData::SDK_ID,
1250+
PemFile::fromFilePath(TestData::PEM_FILE),
1251+
new Config(
1252+
[
1253+
Config::HTTP_CLIENT => $httpClient,
1254+
]
1255+
)
1256+
);
1257+
1258+
$this->assertInstanceOf(
1259+
ContactProfileResponse::class,
1260+
$docScanService->fetchInstructionsContactProfile(TestData::DOC_SCAN_SESSION_ID)
1261+
);
1262+
}
1263+
1264+
/**
1265+
* @test
1266+
* @covers ::__construct
1267+
* @covers ::fetchInstructionsContactProfile
1268+
* @covers ::assertResponseIsSuccess
1269+
*/
1270+
public function fetchInstructionsContactProfileShouldThrowExceptionOnFailedCall()
1271+
{
1272+
$httpClient = $this->createMock(ClientInterface::class);
1273+
$httpClient->expects($this->exactly(1))
1274+
->method('sendRequest')
1275+
->with(
1276+
$this->callback(
1277+
function (RequestInterface $requestMessage) {
1278+
$expectedPathPattern = sprintf(
1279+
'~^%s/sessions/%s/instructions/contact-profile.*?~',
1280+
TestData::DOC_SCAN_BASE_URL,
1281+
TestData::DOC_SCAN_SESSION_ID
1282+
);
1283+
1284+
$this->assertEquals('GET', $requestMessage->getMethod());
1285+
$this->assertMatchesRegularExpression($expectedPathPattern, (string)$requestMessage->getUri());
1286+
return true;
1287+
}
1288+
)
1289+
)
1290+
->willReturn($this->createResponse(404));
1291+
1292+
$docScanService = new Service(
1293+
TestData::SDK_ID,
1294+
PemFile::fromFilePath(TestData::PEM_FILE),
1295+
new Config(
1296+
[
1297+
Config::HTTP_CLIENT => $httpClient,
1298+
]
1299+
)
1300+
);
1301+
1302+
$this->expectException(DocScanException::class);
1303+
$this->expectExceptionMessage("Server responded with 404");
1304+
1305+
$docScanService->fetchInstructionsContactProfile(TestData::DOC_SCAN_SESSION_ID);
1306+
}
12161307
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?php
2+
3+
namespace Yoti\Test\DocScan\Session\Retrieve\Instructions;
4+
5+
use Yoti\DocScan\Session\Retrieve\Instructions\ContactProfileResponse;
6+
use Yoti\Test\TestCase;
7+
8+
/**
9+
* @coversDefaultClass \Yoti\DocScan\Session\Retrieve\Instructions\ContactProfileResponse
10+
*/
11+
class ContactProfileResponseTest extends TestCase
12+
{
13+
private const SOME_FIRST_NAME = 'SOME_FIRST_NAME';
14+
private const SOME_LAST_NAME = 'SOME_LAST_NAME';
15+
private const SOME_EMAIL = 'SOME_EMAIL';
16+
17+
/**
18+
* @test
19+
* @covers ::__construct
20+
* @covers ::getFirstName
21+
* @covers ::getEmail
22+
* @covers ::getLastName
23+
*/
24+
public function shouldBuildCorrectly(): void
25+
{
26+
$data = [
27+
'first_name' => self::SOME_FIRST_NAME,
28+
'last_name' => self::SOME_LAST_NAME,
29+
'email' => self::SOME_EMAIL,
30+
];
31+
32+
$result = new ContactProfileResponse($data);
33+
34+
$this->assertEquals(self::SOME_FIRST_NAME, $result->getFirstName());
35+
$this->assertEquals(self::SOME_LAST_NAME, $result->getLastName());
36+
$this->assertEquals(self::SOME_EMAIL, $result->getEmail());
37+
}
38+
}

tests/DocScan/Session/Retrieve/Instructions/InstructionsResponseTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
namespace Yoti\Test\DocScan\Session\Retrieve\Instructions;
44

55
use Yoti\DocScan\Constants;
6+
use Yoti\DocScan\Session\Retrieve\Instructions\Branch\BranchResponse;
67
use Yoti\DocScan\Session\Retrieve\Instructions\Branch\UkPostOfficeBranchResponse;
78
use Yoti\DocScan\Session\Retrieve\Instructions\Branch\UnknownBranchResponse;
8-
use Yoti\DocScan\Session\Retrieve\Instructions\Branch\BranchResponse;
99
use Yoti\DocScan\Session\Retrieve\Instructions\InstructionsResponse;
1010
use Yoti\Test\TestCase;
1111

0 commit comments

Comments
 (0)