Skip to content

Commit

Permalink
Add entity_id and content_id (#464)
Browse files Browse the repository at this point in the history
  • Loading branch information
SecondeJK authored Jan 16, 2024
1 parent c0cd476 commit c412306
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 2 deletions.
9 changes: 8 additions & 1 deletion src/Verify2/Request/SMSRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,19 @@ public function __construct(
protected string $brand,
protected ?VerificationLocale $locale = null,
protected string $from = '',
protected string $entityId = '',
protected string $contentId = ''
) {
if (!$this->locale) {
$this->locale = new VerificationLocale();
}

$workflow = new VerificationWorkflow(VerificationWorkflow::WORKFLOW_SMS, $to, $from);
$customKeys = array_filter([
'entity_id' => $this->entityId,
'content_id' => $this->contentId
]);

$workflow = new VerificationWorkflow(VerificationWorkflow::WORKFLOW_SMS, $to, $from, $customKeys);

$this->addWorkflow($workflow);
}
Expand Down
45 changes: 44 additions & 1 deletion test/Verify2/ClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,49 @@ public function testCanRequestSMS(): void
$this->assertArrayHasKey('request_id', $result);
}

public function testWillPopulateEntityIdAndContentId(): void
{
$payload = [
'to' => '07785254785',
'client_ref' => 'my-verification',
'brand' => 'my-brand',
'from' => 'vonage',
'entity_id' => '1101407360000017170',
'content_id' => '1107158078772563946'
];

$smsVerification = new SMSRequest(
$payload['to'],
$payload['brand'],
null,
$payload['from'],
$payload['entity_id'],
$payload['content_id']
);

$smsVerification->setClientRef($payload['client_ref']);

$this->vonageClient->send(Argument::that(function (Request $request) use ($payload) {
$uri = $request->getUri();
$uriString = $uri->__toString();
$this->assertEquals(
'https://api.nexmo.com/v2/verify',
$uriString
);

$this->assertRequestJsonBodyContains('entity_id', '1101407360000017170', $request, true);
$this->assertRequestJsonBodyContains('content_id', '1107158078772563946', $request, true);
$this->assertEquals('POST', $request->getMethod());

return true;
}))->willReturn($this->getResponse('verify-request-success', 202));

$result = $this->verify2Client->startVerification($smsVerification);

$this->assertIsArray($result);
$this->assertArrayHasKey('request_id', $result);
}

public function testCanBypassFraudCheck(): void
{
$payload = [
Expand Down Expand Up @@ -434,7 +477,7 @@ public function testCannotSendConcurrentVerifications(): void
];

$smsVerification = new SMSRequest($payload['to'], $payload['brand']);
$smsVerification->setClientRef( $payload['client_ref']);
$smsVerification->setClientRef($payload['client_ref']);

$this->vonageClient->send(Argument::that(function (Request $request) {
$this->assertEquals('POST', $request->getMethod());
Expand Down

0 comments on commit c412306

Please # to comment.