Skip to content

Commit c3a1be4

Browse files
LuborRodRodion Liuborets
andauthored
SDK-2010 Add support for Relying Business to trigger IBV email notification (#256)
Co-authored-by: Rodion Liuborets <[email protected]>
1 parent f3f7c42 commit c3a1be4

File tree

4 files changed

+143
-0
lines changed

4 files changed

+143
-0
lines changed

src/DocScan/DocScanClient.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,4 +231,17 @@ public function fetchInstructionsContactProfile(string $sessionId): ContactProfi
231231
{
232232
return $this->docScanService->fetchInstructionsContactProfile($sessionId);
233233
}
234+
235+
/**
236+
* Triggers an email notification for the IBV instructions at-home flow.
237+
* This will be one of:
238+
* - an email sent directly to the end user, using the email provided in the ContactProfile
239+
* - if requested, a backend notification using the configured notification endpoint
240+
*
241+
* @throws Exception\DocScanException
242+
*/
243+
public function triggerIbvEmailNotification(string $sessionId): void
244+
{
245+
$this->docScanService->triggerIbvEmailNotification($sessionId);
246+
}
234247
}

src/DocScan/Service.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -378,6 +378,23 @@ public function fetchInstructionsContactProfile(string $sessionId): ContactProfi
378378
return new ContactProfileResponse($result);
379379
}
380380

381+
/**
382+
* @param string $sessionId
383+
* @throws DocScanException
384+
*/
385+
public function triggerIbvEmailNotification(string $sessionId): void
386+
{
387+
$response = (new RequestBuilder($this->config))
388+
->withBaseUrl($this->apiUrl)
389+
->withPemFile($this->pemFile)
390+
->withEndpoint(sprintf('/sessions/%s/instructions/email', $sessionId))
391+
->withPost()
392+
->build()
393+
->execute();
394+
395+
self::assertResponseIsSuccess($response);
396+
}
397+
381398
/**
382399
* @param ResponseInterface $response
383400
*

tests/DocScan/DocScanClientTest.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -452,4 +452,28 @@ public function testFetchInstructionsContactProfile()
452452
TestData::DOC_SCAN_SESSION_ID
453453
);
454454
}
455+
456+
/**
457+
* @test
458+
* @covers ::triggerIbvEmailNotification
459+
*/
460+
public function testTriggerIbvEmailNotification()
461+
{
462+
$response = $this->createMock(ResponseInterface::class);
463+
$response->method('getBody')->willReturn(json_encode((object)[]));
464+
$response->method('getStatusCode')->willReturn(200);
465+
466+
$httpClient = $this->createMock(ClientInterface::class);
467+
$httpClient->expects($this->exactly(1))
468+
->method('sendRequest')
469+
->willReturn($response);
470+
471+
$docScanClient = new DocScanClient(TestData::SDK_ID, TestData::PEM_FILE, [
472+
Config::HTTP_CLIENT => $httpClient,
473+
]);
474+
475+
$docScanClient->triggerIbvEmailNotification(
476+
TestData::DOC_SCAN_SESSION_ID
477+
);
478+
}
455479
}

tests/DocScan/ServiceTest.php

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1304,4 +1304,93 @@ function (RequestInterface $requestMessage) {
13041304

13051305
$docScanService->fetchInstructionsContactProfile(TestData::DOC_SCAN_SESSION_ID);
13061306
}
1307+
1308+
/**
1309+
* @test
1310+
* @covers ::__construct
1311+
* @covers ::triggerIbvEmailNotification
1312+
* @covers ::assertResponseIsSuccess
1313+
*/
1314+
public function triggerIbvEmailNotificationShouldNotThrowExceptionOnSuccessfulCall()
1315+
{
1316+
$httpClient = $this->createMock(ClientInterface::class);
1317+
$httpClient->expects($this->exactly(1))
1318+
->method('sendRequest')
1319+
->with(
1320+
$this->callback(
1321+
function (RequestInterface $requestMessage) {
1322+
$expectedPathPattern = sprintf(
1323+
'~^%s/sessions/%s/instructions/email.*?~',
1324+
TestData::DOC_SCAN_BASE_URL,
1325+
TestData::DOC_SCAN_SESSION_ID
1326+
);
1327+
1328+
$this->assertEquals('POST', $requestMessage->getMethod());
1329+
$this->assertMatchesRegularExpression($expectedPathPattern, (string)$requestMessage->getUri());
1330+
return true;
1331+
}
1332+
)
1333+
)
1334+
->willReturn($this->createResponse(200));
1335+
1336+
$docScanService = new Service(
1337+
TestData::SDK_ID,
1338+
PemFile::fromFilePath(TestData::PEM_FILE),
1339+
new Config(
1340+
[
1341+
Config::HTTP_CLIENT => $httpClient,
1342+
]
1343+
)
1344+
);
1345+
1346+
$docScanService->triggerIbvEmailNotification(
1347+
TestData::DOC_SCAN_SESSION_ID
1348+
);
1349+
}
1350+
1351+
/**
1352+
* @test
1353+
* @covers ::__construct
1354+
* @covers ::triggerIbvEmailNotification
1355+
* @covers ::assertResponseIsSuccess
1356+
*/
1357+
public function triggerIbvEmailNotificationShouldThrowExceptionOnFailedCall()
1358+
{
1359+
$httpClient = $this->createMock(ClientInterface::class);
1360+
$httpClient->expects($this->exactly(1))
1361+
->method('sendRequest')
1362+
->with(
1363+
$this->callback(
1364+
function (RequestInterface $requestMessage) {
1365+
$expectedPathPattern = sprintf(
1366+
'~^%s/sessions/%s/instructions/email.*?~',
1367+
TestData::DOC_SCAN_BASE_URL,
1368+
TestData::DOC_SCAN_SESSION_ID
1369+
);
1370+
1371+
$this->assertEquals('POST', $requestMessage->getMethod());
1372+
$this->assertMatchesRegularExpression($expectedPathPattern, (string)$requestMessage->getUri());
1373+
return true;
1374+
}
1375+
)
1376+
)
1377+
->willReturn($this->createResponse(404));
1378+
1379+
$docScanService = new Service(
1380+
TestData::SDK_ID,
1381+
PemFile::fromFilePath(TestData::PEM_FILE),
1382+
new Config(
1383+
[
1384+
Config::HTTP_CLIENT => $httpClient,
1385+
]
1386+
)
1387+
);
1388+
1389+
$this->expectException(DocScanException::class);
1390+
$this->expectExceptionMessage("Server responded with 404");
1391+
1392+
$docScanService->triggerIbvEmailNotification(
1393+
TestData::DOC_SCAN_SESSION_ID
1394+
);
1395+
}
13071396
}

0 commit comments

Comments
 (0)