Skip to content

Commit 5021494

Browse files
authored
Add ability to add optional redirect url (#454)
1 parent bac6ebc commit 5021494

File tree

3 files changed

+54
-2
lines changed

3 files changed

+54
-2
lines changed

src/Verify2/Request/SilentAuthRequest.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,14 @@ class SilentAuthRequest extends BaseVerifyRequest
99
public function __construct(
1010
protected string $to,
1111
protected string $brand,
12+
protected ?string $redirectUrl = null
1213
) {
1314
$workflow = new VerificationWorkflow(VerificationWorkflow::WORKFLOW_SILENT_AUTH, $to);
15+
16+
if ($this->redirectUrl) {
17+
$workflow->setCustomKeys(['redirect_url' => $this->redirectUrl]);
18+
}
19+
1420
$this->addWorkflow($workflow);
1521
}
1622

@@ -21,4 +27,4 @@ public function toArray(): array
2127
'workflow' => $this->getWorkflows()
2228
];
2329
}
24-
}
30+
}

src/Verify2/VerifyObjects/VerificationWorkflow.php

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ class VerificationWorkflow implements ArrayHydrateInterface
2525
public function __construct(
2626
protected string $channel,
2727
protected string $to,
28-
protected string $from = ''
28+
protected string $from = '',
29+
protected array $customKeys = []
2930
) {
3031
if (! in_array($channel, $this->allowedWorkflows, true)) {
3132
throw new \InvalidArgumentException($this->channel . ' is not a valid workflow');
@@ -91,6 +92,24 @@ public function toArray(): array
9192
$returnArray['from'] = $this->getFrom();
9293
}
9394

95+
if (!empty($this->customKeys)) {
96+
foreach ($this->customKeys as $key => $value) {
97+
$returnArray[$key] = $value;
98+
}
99+
}
100+
94101
return $returnArray;
95102
}
103+
104+
public function getCustomKeys(): array
105+
{
106+
return $this->customKeys;
107+
}
108+
109+
public function setCustomKeys(array $customKeys): self
110+
{
111+
$this->customKeys = $customKeys;
112+
113+
return $this;
114+
}
96115
}

test/Verify2/ClientTest.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -393,6 +393,33 @@ public function testCanRequestSilentAuth(): void
393393
$this->assertEquals('https://api.nexmo.com/v2/verify/c11236f4-00bf-4b89-84ba-88b25df97315/silent-auth/redirect', $result['check_url']);
394394
}
395395

396+
public function testCanRequestSilentAuthWithRedirectUrl(): void
397+
{
398+
$payload = [
399+
'to' => '07784587411',
400+
'brand' => 'my-brand',
401+
'redirect_url' => 'https://my-app-endpoint/webhook'
402+
];
403+
404+
$silentAuthRequest = new SilentAuthRequest($payload['to'], $payload['brand'], $payload['redirect_url']);
405+
406+
$this->vonageClient->send(Argument::that(function (Request $request) use ($payload) {
407+
$this->assertRequestJsonBodyContains('brand', $payload['brand'], $request);
408+
$this->assertRequestJsonBodyContains('to', $payload['to'], $request, true);
409+
$this->assertRequestJsonBodyContains('channel', 'silent_auth', $request, true);
410+
$this->assertRequestJsonBodyContains('redirect_url', 'https://my-app-endpoint/webhook', $request, true);
411+
$this->assertEquals('POST', $request->getMethod());
412+
413+
return true;
414+
}))->willReturn($this->getResponse('verify-silent-auth-request-success', 202));
415+
416+
$result = $this->verify2Client->startVerification($silentAuthRequest);
417+
$this->assertIsArray($result);
418+
$this->assertArrayHasKey('request_id', $result);
419+
$this->assertArrayHasKey('check_url', $result);
420+
$this->assertEquals('https://api.nexmo.com/v2/verify/c11236f4-00bf-4b89-84ba-88b25df97315/silent-auth/redirect', $result['check_url']);
421+
}
422+
396423
public function testCannotSendConcurrentVerifications(): void
397424
{
398425
$this->expectException(Client\Exception\Request::class);

0 commit comments

Comments
 (0)