diff --git a/src/Verify2/Request/SMSRequest.php b/src/Verify2/Request/SMSRequest.php index 8ea790e3..f01ca601 100644 --- a/src/Verify2/Request/SMSRequest.php +++ b/src/Verify2/Request/SMSRequest.php @@ -3,11 +3,14 @@ namespace Vonage\Verify2\Request; use InvalidArgumentException; +use Vonage\Verify2\Traits\CustomTemplateTrait; use Vonage\Verify2\VerifyObjects\VerificationLocale; use Vonage\Verify2\VerifyObjects\VerificationWorkflow; class SMSRequest extends BaseVerifyRequest { + use CustomTemplateTrait; + public function __construct( protected string $to, protected string $brand, @@ -36,6 +39,12 @@ public function __construct( public function toArray(): array { - return $this->getBaseVerifyUniversalOutputArray(); + $return = $this->getBaseVerifyUniversalOutputArray(); + + if (!is_null($this->getTemplateId())) { + $return['template_id'] = $this->getTemplateId(); + } + + return $return; } } diff --git a/src/Verify2/Request/VoiceRequest.php b/src/Verify2/Request/VoiceRequest.php index 9a70e5e9..607905fc 100644 --- a/src/Verify2/Request/VoiceRequest.php +++ b/src/Verify2/Request/VoiceRequest.php @@ -3,11 +3,14 @@ namespace Vonage\Verify2\Request; use InvalidArgumentException; +use Vonage\Verify2\Traits\CustomTemplateTrait; use Vonage\Verify2\VerifyObjects\VerificationLocale; use Vonage\Verify2\VerifyObjects\VerificationWorkflow; class VoiceRequest extends BaseVerifyRequest { + use CustomTemplateTrait; + public function __construct( protected string $to, protected string $brand, diff --git a/src/Verify2/Traits/CustomTemplateTrait.php b/src/Verify2/Traits/CustomTemplateTrait.php new file mode 100644 index 00000000..26ee84cf --- /dev/null +++ b/src/Verify2/Traits/CustomTemplateTrait.php @@ -0,0 +1,18 @@ +templateId; + } + + public function setTemplateId(string $templateId): string + { + return $this->templateId = $templateId; + } +} \ No newline at end of file diff --git a/test/Verify2/ClientTest.php b/test/Verify2/ClientTest.php index 4c81bbe8..94a758ee 100644 --- a/test/Verify2/ClientTest.php +++ b/test/Verify2/ClientTest.php @@ -126,6 +126,38 @@ public function testCanRequestSMS(): void $this->assertArrayHasKey('request_id', $result); } + public function testCanRequestSmsWithCustomTemplate(): void + { + $payload = [ + 'to' => '07785254785', + 'client_ref' => 'my-verification', + 'brand' => 'my-brand', + 'from' => 'vonage' + ]; + + $smsVerification = new SMSRequest($payload['to'], $payload['brand'], null, $payload['from']); + $smsVerification->setTemplateId('33945c03-71c6-4aaf-954d-750a9b480def'); + + $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('template_id', '33945c03-71c6-4aaf-954d-750a9b480def', $request); + $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 testWillPopulateEntityIdAndContentId(): void { $payload = [ @@ -1026,4 +1058,20 @@ public function timeoutProvider(): array [921, false], ]; } +// +// public function testIntegration() +// { +// $credentials = new Client\Credentials\Keypair( +// file_get_contents('/Users/JSeconde/Sites/vonage-php-sdk-core/test/Verify2/private.key'), +// '4a875f7e-2559-4fb5-84f6-f8b144f6e9f6' +// ); +// +// $liveClient = new Client($credentials); +// +// $response = $liveClient->verify2()->createCustomTemplate('example-template'); + +// $smsRequest = new SMSRequest('447738066610', 'VONAGE', null, '447738066610'); +// $response = $liveClient->verify2()->startVerification($smsRequest); +// var_dump($response); +// } }