From d6ba20b14ffedf320ba23ebe196ef2defd3f78eb Mon Sep 17 00:00:00 2001 From: Christophe Surun Date: Mon, 27 Jun 2022 15:21:54 +0100 Subject: [PATCH] 3dsResumeCompleteAccountDetails-JR-6384 - PrimaryAccountDetails added to Resume and Complete models - Tests refactoring --- src/Judopay/Model/CompleteThreeDSecureTwo.php | 5 +- src/Judopay/Model/ResumeThreeDSecureTwo.php | 3 + .../Builders/ResumeThreeDSecureTwoBuilder.php | 6 ++ tests/RefundTest.php | 2 +- ...reTwoTests.php => ThreeDSecureTwoTest.php} | 57 ++++++++++++++++++- tests/VoidTest.php | 2 +- 6 files changed, 70 insertions(+), 5 deletions(-) rename tests/{Base/ThreeDSecureTwoTests.php => ThreeDSecureTwoTest.php} (80%) diff --git a/src/Judopay/Model/CompleteThreeDSecureTwo.php b/src/Judopay/Model/CompleteThreeDSecureTwo.php index ddecdd1..124e5e7 100644 --- a/src/Judopay/Model/CompleteThreeDSecureTwo.php +++ b/src/Judopay/Model/CompleteThreeDSecureTwo.php @@ -12,7 +12,10 @@ class CompleteThreeDSecureTwo extends Model protected $attributes = array( 'receiptId' => DataType::TYPE_STRING, - 'cv2' => DataType::TYPE_STRING + 'cv2' => DataType::TYPE_STRING, + + // Inner objects + 'primaryAccountDetails' => DataType::TYPE_PRIMARY_ACCOUNT_DETAILS, ); protected $requiredAttributes diff --git a/src/Judopay/Model/ResumeThreeDSecureTwo.php b/src/Judopay/Model/ResumeThreeDSecureTwo.php index 776a311..f70ba81 100644 --- a/src/Judopay/Model/ResumeThreeDSecureTwo.php +++ b/src/Judopay/Model/ResumeThreeDSecureTwo.php @@ -14,6 +14,9 @@ class ResumeThreeDSecureTwo extends Model 'receiptId' => DataType::TYPE_STRING, 'cv2' => DataType::TYPE_STRING, 'methodCompletion' => DataType::TYPE_STRING, + + // Inner objects + 'primaryAccountDetails' => DataType::TYPE_PRIMARY_ACCOUNT_DETAILS, ); protected $requiredAttributes diff --git a/tests/Builders/ResumeThreeDSecureTwoBuilder.php b/tests/Builders/ResumeThreeDSecureTwoBuilder.php index 4b37d8d..7e058b2 100644 --- a/tests/Builders/ResumeThreeDSecureTwoBuilder.php +++ b/tests/Builders/ResumeThreeDSecureTwoBuilder.php @@ -22,4 +22,10 @@ public function setThreeDSecureTwoMethodCompletion($methodCompletion) $this->setAttribute('methodCompletion', $methodCompletion); return $this; } + + public function setThreeDSecureTwoPrimaryAccountDetails($primaryAccountDetails) + { + $this->setAttribute('primaryAccountDetails', $primaryAccountDetails); + return $this; + } } diff --git a/tests/RefundTest.php b/tests/RefundTest.php index 8c51991..58feeeb 100644 --- a/tests/RefundTest.php +++ b/tests/RefundTest.php @@ -1,6 +1,6 @@ "Browser", + 'methodNotificationUrl' => "https://www.test.com", + 'challengeNotificationUrl' => "https://www.test.com" + ); + + $cardPayment = $this->getPaymentBuilder() + ->setType(CardPaymentBuilder::THREEDSTWO_VISA_CARD) + ->setThreeDSecureTwoFields($threeDSecureTwo) + ->build(ConfigHelper::getSafeChargeConfig()); + + $paymentResult = []; + + try { + $paymentResult = $cardPayment->create(); + } catch (BadResponseException $e) { + $this->fail('The request was expected to be successful.'); // We do not expect any exception + } + + // We should have received a request for additional device data gathering + AssertionHelper::assertRequiresThreeDSecureTwoDeviceDetails($paymentResult); + + $primaryAccountDetailsFields = array( + 'name' => 'John Smith', + 'accountNumber' => '123456', + 'dateOfBirth' => '1980-01-01', + 'postCode' => 'EC2A 4DP', + ); + + // Build the Resume3d request for the payment after its device gathering happened + $resumeThreeDSecureTwo = $this->getResumeThreeDSecureTwoBuilder($paymentResult['receiptId']) + ->setThreeDSecureTwoMethodCompletion("Yes") + ->setThreeDSecureTwoPrimaryAccountDetails($primaryAccountDetailsFields) + ->build(ConfigHelper::getSafeChargeConfig()); + + Assert::assertNotNull($resumeThreeDSecureTwo); + + try { + $resumeResult = $resumeThreeDSecureTwo->update(); + $this->fail('The request was expected to raise an exception.'); // We do not expect any exception + } catch (BadResponseException $e) { + // We do not expect any model exception because CV2 is not a mandatory request parameter + $this->fail('The request was expected to raise an ApiException.'); + } catch (ApiException $e) { + // But we expect an API exception as this API key doesn't have optional CV2 + $expected = "Sorry, the security code entered is invalid. Please check your details and try again."; + assert::assertEquals($expected, $e->getFieldErrors()[0]->getMessage()); + } + } + /* * This cannot run as a full automated test because of a step involving a web browser */ diff --git a/tests/VoidTest.php b/tests/VoidTest.php index 3a53e34..919d954 100644 --- a/tests/VoidTest.php +++ b/tests/VoidTest.php @@ -1,6 +1,6 @@