From c4123068931a232ec6522f85fb2a24db2b3b8467 Mon Sep 17 00:00:00 2001 From: James Seconde Date: Tue, 16 Jan 2024 15:10:13 +0000 Subject: [PATCH] Add entity_id and content_id (#464) --- src/Verify2/Request/SMSRequest.php | 9 +++++- test/Verify2/ClientTest.php | 45 +++++++++++++++++++++++++++++- 2 files changed, 52 insertions(+), 2 deletions(-) diff --git a/src/Verify2/Request/SMSRequest.php b/src/Verify2/Request/SMSRequest.php index 15be49cd..878378bb 100644 --- a/src/Verify2/Request/SMSRequest.php +++ b/src/Verify2/Request/SMSRequest.php @@ -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); } diff --git a/test/Verify2/ClientTest.php b/test/Verify2/ClientTest.php index 4a64657c..82b420cb 100644 --- a/test/Verify2/ClientTest.php +++ b/test/Verify2/ClientTest.php @@ -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 = [ @@ -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());