Skip to content

Commit 3c6d784

Browse files
committed
Merge remote-tracking branch 'origin/main'
2 parents 0dc217b + a8f6c33 commit 3c6d784

File tree

5 files changed

+72
-5
lines changed

5 files changed

+72
-5
lines changed

src/Verify2/Client.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
namespace Vonage\Verify2;
44

5-
use Laminas\Diactoros\Request;
65
use Vonage\Client\APIClient;
76
use Vonage\Client\APIResource;
87
use Vonage\Client\Exception\Exception;
@@ -27,7 +26,7 @@ public function startVerification(BaseVerifyRequest $request): ?array
2726
public function check(string $requestId, $code): bool
2827
{
2928
try {
30-
$response = $this->getAPIResource()->create(['code' => $code], $requestId);
29+
$response = $this->getAPIResource()->create(['code' => $code], '/' . $requestId);
3130
} catch (Exception $e) {
3231
// For horrible reasons in the API Error Handler, throw the error unless it's a 409.
3332
if ($e->getCode() === 409) {
@@ -39,4 +38,11 @@ public function check(string $requestId, $code): bool
3938

4039
return true;
4140
}
41+
42+
public function cancelRequest(string $requestId): bool
43+
{
44+
$this->api->delete($requestId);
45+
46+
return true;
47+
}
4248
}

src/Verify2/ClientFactory.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public function __invoke(ContainerInterface $container): Client
1515
$api->setIsHAL(false)
1616
->setErrorsOn200(false)
1717
->setAuthHandler([new KeypairHandler(), new BasicHandler()])
18-
->setBaseUrl('https://api.nexmo.com/v2/verify/');
18+
->setBaseUrl('https://api.nexmo.com/v2/verify');
1919

2020
return new Client($api);
2121
}

src/Verify2/Request/BaseVerifyRequest.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ abstract class BaseVerifyRequest implements RequestInterface
1616

1717
protected int $timeout = 300;
1818

19+
protected bool $fraudCheck = true;
20+
1921
protected ?string $clientRef = null;
2022

2123
protected int $length = 4;
@@ -132,9 +134,22 @@ public function addWorkflow(VerificationWorkflow $verificationWorkflow): static
132134
return $this;
133135
}
134136

137+
public function getFraudCheck(): bool
138+
{
139+
return $this->fraudCheck;
140+
}
141+
142+
public function setFraudCheck(bool $fraudCheck): BaseVerifyRequest
143+
{
144+
$this->fraudCheck = $fraudCheck;
145+
146+
return $this;
147+
}
148+
135149
public function getBaseVerifyUniversalOutputArray(): array
136150
{
137151
$returnArray = [
152+
'fraud_check' => $this->getFraudCheck(),
138153
'locale' => $this->getLocale()->getCode(),
139154
'channel_timeout' => $this->getTimeout(),
140155
'code_length' => $this->getLength(),

test/Verify2/ClientTest.php

Lines changed: 48 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public function setUp(): void
4646
->setErrorsOn200(false)
4747
->setClient($this->vonageClient->reveal())
4848
->setAuthHandler([new Client\Credentials\Handler\BasicHandler(), new Client\Credentials\Handler\KeypairHandler()])
49-
->setBaseUrl('https://api.nexmo.com/v2/verify/');
49+
->setBaseUrl('https://api.nexmo.com/v2/verify');
5050

5151
$this->verify2Client = new Verify2Client($this->api);
5252
}
@@ -93,11 +93,12 @@ public function testCanRequestSMS(): void
9393
$uri = $request->getUri();
9494
$uriString = $uri->__toString();
9595
$this->assertEquals(
96-
'https://api.nexmo.com/v2/verify/',
96+
'https://api.nexmo.com/v2/verify',
9797
$uriString
9898
);
9999

100100
$this->assertRequestJsonBodyContains('locale', 'en-us', $request);
101+
$this->assertRequestJsonBodyContains('fraud_check', true, $request);
101102
$this->assertRequestJsonBodyContains('channel_timeout', 300, $request);
102103
$this->assertRequestJsonBodyContains('client_ref', $payload['client_ref'], $request);
103104
$this->assertRequestJsonBodyContains('code_length', 4, $request);
@@ -115,6 +116,29 @@ public function testCanRequestSMS(): void
115116
$this->assertArrayHasKey('request_id', $result);
116117
}
117118

119+
public function testCanBypassFraudCheck(): void
120+
{
121+
$payload = [
122+
'to' => '07785254785',
123+
'client_ref' => 'my-verification',
124+
'brand' => 'my-brand',
125+
];
126+
127+
$smsVerification = new SMSRequest($payload['to'], $payload['brand']);
128+
$smsVerification->setFraudCheck(false);
129+
130+
$this->vonageClient->send(Argument::that(function (Request $request) use ($payload) {
131+
$this->assertRequestJsonBodyContains('fraud_check', false, $request);
132+
133+
return true;
134+
}))->willReturn($this->getResponse('verify-request-success', 202));
135+
136+
$result = $this->verify2Client->startVerification($smsVerification);
137+
138+
$this->assertIsArray($result);
139+
$this->assertArrayHasKey('request_id', $result);
140+
}
141+
118142
/**
119143
* @dataProvider localeProvider
120144
*/
@@ -591,6 +615,28 @@ public function testCheckHandlesThrottle(): void
591615
$result = $this->verify2Client->check('c11236f4-00bf-4b89-84ba-88b25df97315', '24525');
592616
}
593617

618+
public function testWillCancelVerification(): void
619+
{
620+
$requestId = 'c11236f4-00bf-4b89-84ba-88b25df97315';
621+
622+
$this->vonageClient->send(Argument::that(function (Request $request) {
623+
$uri = $request->getUri();
624+
$uriString = $uri->__toString();
625+
$this->assertEquals(
626+
'https://api.nexmo.com/v2/verify/c11236f4-00bf-4b89-84ba-88b25df97315',
627+
$uriString
628+
);
629+
630+
$this->assertEquals('DELETE', $request->getMethod());
631+
632+
return true;
633+
}))->willReturn($this->getResponse('verify-cancel-success', 204));
634+
635+
$result = $this->verify2Client->cancelRequest($requestId);
636+
637+
$this->assertTrue($result);
638+
}
639+
594640
/**
595641
* This method gets the fixtures and wraps them in a Response object to mock the API
596642
*/

test/Verify2/Fixtures/Responses/verify-cancel-success.json

Whitespace-only changes.

0 commit comments

Comments
 (0)