From 9cc0d27da5a2b13347f984ade499327e52510d65 Mon Sep 17 00:00:00 2001 From: James Seconde Date: Wed, 17 May 2023 11:13:36 +0100 Subject: [PATCH] Only render fraud check if it's been set to false. True does not need to be rendered as it's default (#407) --- src/Verify2/Request/BaseVerifyRequest.php | 11 +++++++---- test/Verify2/ClientTest.php | 5 ++--- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/Verify2/Request/BaseVerifyRequest.php b/src/Verify2/Request/BaseVerifyRequest.php index 2b8f6e54..c74aaa8d 100644 --- a/src/Verify2/Request/BaseVerifyRequest.php +++ b/src/Verify2/Request/BaseVerifyRequest.php @@ -16,7 +16,7 @@ abstract class BaseVerifyRequest implements RequestInterface protected int $timeout = 300; - protected bool $fraudCheck = true; + protected ?bool $fraudCheck = null; protected ?string $clientRef = null; @@ -134,9 +134,9 @@ public function addWorkflow(VerificationWorkflow $verificationWorkflow): static return $this; } - public function getFraudCheck(): bool + public function getFraudCheck(): ?bool { - return $this->fraudCheck; + return $this->fraudCheck ?? null; } public function setFraudCheck(bool $fraudCheck): BaseVerifyRequest @@ -149,7 +149,6 @@ public function setFraudCheck(bool $fraudCheck): BaseVerifyRequest public function getBaseVerifyUniversalOutputArray(): array { $returnArray = [ - 'fraud_check' => $this->getFraudCheck(), 'locale' => $this->getLocale()->getCode(), 'channel_timeout' => $this->getTimeout(), 'code_length' => $this->getLength(), @@ -157,6 +156,10 @@ public function getBaseVerifyUniversalOutputArray(): array 'workflow' => $this->getWorkflows() ]; + if ($this->getFraudCheck() === false) { + $returnArray['fraud_check'] = $this->getFraudCheck(); + } + if ($this->getClientRef()) { $returnArray['client_ref'] = $this->getClientRef(); } diff --git a/test/Verify2/ClientTest.php b/test/Verify2/ClientTest.php index e9c8fa19..71f286f1 100644 --- a/test/Verify2/ClientTest.php +++ b/test/Verify2/ClientTest.php @@ -98,7 +98,7 @@ public function testCanRequestSMS(): void ); $this->assertRequestJsonBodyContains('locale', 'en-us', $request); - $this->assertRequestJsonBodyContains('fraud_check', true, $request); + $this->assertRequestJsonBodyMissing('fraud_check', $request); $this->assertRequestJsonBodyContains('channel_timeout', 300, $request); $this->assertRequestJsonBodyContains('client_ref', $payload['client_ref'], $request); $this->assertRequestJsonBodyContains('code_length', 4, $request); @@ -120,14 +120,13 @@ public function testCanBypassFraudCheck(): void { $payload = [ 'to' => '07785254785', - 'client_ref' => 'my-verification', 'brand' => 'my-brand', ]; $smsVerification = new SMSRequest($payload['to'], $payload['brand']); $smsVerification->setFraudCheck(false); - $this->vonageClient->send(Argument::that(function (Request $request) use ($payload) { + $this->vonageClient->send(Argument::that(function (Request $request) { $this->assertRequestJsonBodyContains('fraud_check', false, $request); return true;