diff --git a/src/Judopay/DataType.php b/src/Judopay/DataType.php index f5bd2a3..fd94712 100644 --- a/src/Judopay/DataType.php +++ b/src/Judopay/DataType.php @@ -22,8 +22,6 @@ class DataType const TYPE_GOOGLE_PAY_WALLET = 'google_pay_wallet'; const TYPE_PRIMARY_ACCOUNT_DETAILS = 'primary_account_details'; const TYPE_RECURRING_TYPE = 'recurring_type'; - const TYPE_CHALLENGE_INDICATOR = 'challenge_indicator'; - const TYPE_SCA_EXEMPTION = 'sca_exemption'; const TYPE_THREE_D_SECURE_TWO = 'three_d_secure_two'; public static function coerce($targetDataType, $value) @@ -81,46 +79,51 @@ public static function coerce($targetDataType, $value) $primaryAccountDetails = PrimaryAccountDetails::factory($value); return $primaryAccountDetails->toObject(); - case static::TYPE_CHALLENGE_INDICATOR: - // Check that the provided value is part of the challenge request indicator enum - if (strcasecmp($value, "noPreference") != 0 - && strcasecmp($value, "noChallenge") != 0 - && strcasecmp($value, "challengePreferred") != 0 - && strcasecmp($value, "challengeAsMandate") != 0 - ) { - throw new ValidationError('Invalid challenge indicator value'); - } - return $value; - - case static::TYPE_SCA_EXEMPTION: - // Check that the provided value is part of the SCA exemption enum - if (strcasecmp($value, "lowValue") != 0 - && strcasecmp($value, "secureCorporate") != 0 - && strcasecmp($value, "trustedBeneficiary") != 0 - && strcasecmp($value, "transactionRiskAnalysis") != 0 - ) { - throw new ValidationError('Invalid SCA exemption value'); - } - return $value; - case static::TYPE_THREE_D_SECURE_TWO: - // Provided value for mandatory authenticationSource part of the enum - if (strcasecmp($value['authenticationSource'], "Browser") != 0 - && strcasecmp($value['authenticationSource'], "Stored_Recurring") != 0 - && strcasecmp($value['authenticationSource'], "Mobile_Sdk") != 0 - ) { + $authenticationSourceValues = array( + "browser", + "stored_recurring", + "mobile_sdk"); + $methodCompletionValues = array( + "yes", + "no", + "unavailable"); + $challengeRequestIndicatorValues = array( + "nopreference", + "nochallenge", + "challengepreferred", + "challengeasmandate"); + $scaExemptionValues = array( + "lowvalue", + "securecorporate", + "trustedbeneficiary", + "transactionriskanalysis"); + + if (!in_array(strtolower($value['authenticationSource']), $authenticationSourceValues)) { throw new ValidationError('Invalid authenticationSource value'); } + // If present, provided value for methodCompletion part of the enum if (array_key_exists('methodCompletion', $value)) { - if (strcasecmp($value['methodCompletion'], "Yes") != 0 - && strcasecmp($value['methodCompletion'], "No") != 0 - && strcasecmp($value['methodCompletion'], "Unavailable") != 0 - ) { + if (!in_array(strtolower($value['methodCompletion']), $methodCompletionValues)) { throw new ValidationError('Invalid methodCompletion value'); } } + // If present, provided value for challengeRequestIndicator part of the enum + if (array_key_exists('challengeRequestIndicator', $value)) { + if (!in_array(strtolower($value['challengeRequestIndicator']), $challengeRequestIndicatorValues)) { + throw new ValidationError('Invalid challenge indicator value'); + } + } + + // If present, provided value for scaExemption part of the enum + if (array_key_exists('scaExemption', $value)) { + if (!in_array(strtolower($value['scaExemption']), $scaExemptionValues)) { + throw new ValidationError('Invalid SCA exemption value'); + } + } + $threeDSecureTwo = ThreeDSecureTwo::factory($value); return $threeDSecureTwo->toObject(); } diff --git a/src/Judopay/Model/CardPayment.php b/src/Judopay/Model/CardPayment.php index 363d3d9..62b6711 100644 --- a/src/Judopay/Model/CardPayment.php +++ b/src/Judopay/Model/CardPayment.php @@ -34,9 +34,6 @@ class CardPayment extends Model 'relatedReceiptId' => DataType::TYPE_STRING, 'recurringPaymentType' => DataType::TYPE_RECURRING_TYPE, - 'challengeRequestIndicator' => DataType::TYPE_CHALLENGE_INDICATOR, - 'scaExemption' => DataType::TYPE_SCA_EXEMPTION, - // Inner objects 'primaryAccountDetails' => DataType::TYPE_PRIMARY_ACCOUNT_DETAILS, 'threeDSecure' => DataType::TYPE_THREE_D_SECURE_TWO, diff --git a/src/Judopay/Model/CheckCard.php b/src/Judopay/Model/CheckCard.php index 8125cff..012119d 100644 --- a/src/Judopay/Model/CheckCard.php +++ b/src/Judopay/Model/CheckCard.php @@ -25,9 +25,6 @@ class CheckCard extends Model 'emailAddress' => DataType::TYPE_STRING, 'initialRecurringPayment' => DataType::TYPE_BOOLEAN, - 'challengeRequestIndicator' => DataType::TYPE_CHALLENGE_INDICATOR, - 'scaExemption' => DataType::TYPE_SCA_EXEMPTION, - // Inner objects 'primaryAccountDetails' => DataType::TYPE_PRIMARY_ACCOUNT_DETAILS, 'threeDSecure' => DataType::TYPE_THREE_D_SECURE_TWO, diff --git a/src/Judopay/Model/Inner/ThreeDSecureTwo.php b/src/Judopay/Model/Inner/ThreeDSecureTwo.php index c065fc4..7eb0c6f 100644 --- a/src/Judopay/Model/Inner/ThreeDSecureTwo.php +++ b/src/Judopay/Model/Inner/ThreeDSecureTwo.php @@ -13,6 +13,8 @@ class ThreeDSecureTwo extends TransmittedField 'methodCompletion' => DataType::TYPE_STRING, 'methodNotificationUrl' => DataType::TYPE_STRING, 'challengeNotificationUrl' => DataType::TYPE_STRING, + 'challengeRequestIndicator' => DataType::TYPE_STRING, + 'scaExemption' => DataType::TYPE_STRING, ); protected $requiredAttributes diff --git a/src/Judopay/Model/TokenPayment.php b/src/Judopay/Model/TokenPayment.php index 2d37c32..a77701e 100644 --- a/src/Judopay/Model/TokenPayment.php +++ b/src/Judopay/Model/TokenPayment.php @@ -30,9 +30,6 @@ class TokenPayment extends Model 'relatedReceiptId' => DataType::TYPE_STRING, 'recurringPaymentType' => DataType::TYPE_RECURRING_TYPE, - 'challengeRequestIndicator' => DataType::TYPE_CHALLENGE_INDICATOR, - 'scaExemption' => DataType::TYPE_SCA_EXEMPTION, - // Inner objects 'primaryAccountDetails' => DataType::TYPE_PRIMARY_ACCOUNT_DETAILS, 'threeDSecure' => DataType::TYPE_THREE_D_SECURE_TWO, diff --git a/tests/Base/ThreeDSecureTwoTests.php b/tests/Base/ThreeDSecureTwoTests.php index 81c0c5a..511b954 100644 --- a/tests/Base/ThreeDSecureTwoTests.php +++ b/tests/Base/ThreeDSecureTwoTests.php @@ -30,7 +30,7 @@ protected function getCompleteThreeDSecureTwoBuilder($receiptId) return new CompleteThreeDSecureTwoBuilder($receiptId); } - public function testPaymentWithThreedSecureTwoInvalidAuthenticationSource() + public function testPaymentWithThreeDSecureTwoInvalidAuthenticationSource() { // Build a threeDSecureTwo payment with an invalid attribute $threeDSecureTwo = array( @@ -54,7 +54,7 @@ public function testPaymentWithThreedSecureTwoInvalidAuthenticationSource() } } - public function testPaymentWithThreedSecureTwoInvalidMethodCompletion() + public function testPaymentWithThreeDSecureTwoInvalidMethodCompletion() { // Build a threeDSecureTwo payment with an invalid attribute $threeDSecureTwo = array( @@ -78,7 +78,7 @@ public function testPaymentWithThreedSecureTwoInvalidMethodCompletion() } } - public function testPaymentWithThreedSecureTwoRequiresDeviceDetailsCheck() + public function testPaymentWithThreeDSecureTwoRequiresDeviceDetailsCheck() { // Build a threeDSecureTwo payment $threeDSecureTwo = array( @@ -104,7 +104,7 @@ public function testPaymentWithThreedSecureTwoRequiresDeviceDetailsCheck() AssertionHelper::assertRequiresThreeDSecureTwoDeviceDetails($paymentResult); } - public function testPaymentWithThreedSecureTwoResumeTransaction() + public function testPaymentWithThreeDSecureTwoResumeTransaction() { // Build a threeDSecureTwo payment $threeDSecureTwo = array( @@ -149,7 +149,7 @@ public function testPaymentWithThreedSecureTwoResumeTransaction() AssertionHelper::assertRequiresThreeDSecureTwoChallengeCompletion($resumeResult); } - public function testPaymentWithThreedSecureTwoResumeTransactionNoCv2() + public function testPaymentWithThreeDSecureTwoResumeTransactionNoCv2() { // Build a threeDSecureTwo payment $threeDSecureTwo = array( @@ -198,7 +198,7 @@ public function testPaymentWithThreedSecureTwoResumeTransactionNoCv2() /* * This cannot run as a full automated test because of a step involving a web browser */ - public function testPaymentWithThreedSecureTwoCompleteTransaction() + public function testPaymentWithThreeDSecureTwoCompleteTransaction() { // Build the Complete3d request for the payment after its ACS challenge happened $completeThreeDSecureTwo = $this->getCompleteThreeDSecureTwoBuilder('12345678') diff --git a/tests/Builders/CardPaymentBuilder.php b/tests/Builders/CardPaymentBuilder.php index 95c9229..cef6503 100644 --- a/tests/Builders/CardPaymentBuilder.php +++ b/tests/Builders/CardPaymentBuilder.php @@ -62,7 +62,7 @@ public function compile() case self::THREEDS_VISA_CARD: $this->attributeValues += array( 'cardNumber' => '4976350000006891', - 'expiryDate' => '12/21', + 'expiryDate' => '12/25', 'cv2' => 341, ); break; diff --git a/tests/PaymentTest.php b/tests/PaymentTest.php index f8c9dad..fb95b1e 100644 --- a/tests/PaymentTest.php +++ b/tests/PaymentTest.php @@ -62,8 +62,14 @@ public function testBuildRecurringValidTypeAttribute() public function testPaymentWithInvalidChallengeRequestIndicator() { + $threeDSecureTwo = array( + 'authenticationSource' => "Browser", + 'challengeRequestIndicator' => "test" + ); + $cardPayment = $this->getBuilder() - ->setAttribute('challengeRequestIndicator', "test"); + ->setThreeDSecureTwoFields($threeDSecureTwo); + try { $cardPayment->build(ConfigHelper::getCybersourceConfig()); $this->fail('An expected ValidationError has not been raised.'); @@ -76,8 +82,14 @@ public function testPaymentWithInvalidChallengeRequestIndicator() public function testPaymentWithValidChallengeRequestIndicator() { + $threeDSecureTwo = array( + 'authenticationSource' => "Browser", + 'challengeRequestIndicator' => "noPreference" + ); + $cardPayment = $this->getBuilder() - ->setAttribute('challengeRequestIndicator', "noPreference"); + ->setThreeDSecureTwoFields($threeDSecureTwo); + try { $cardPayment->build(ConfigHelper::getCybersourceConfig()); } catch (\Exception $e) { @@ -85,13 +97,21 @@ public function testPaymentWithValidChallengeRequestIndicator() return; } - Assert::assertEquals("noPreference", $cardPayment->getAttributeValues()["challengeRequestIndicator"]); + Assert::assertEquals( + "noPreference", + $cardPayment->getAttributeValues()["threeDSecure"]["challengeRequestIndicator"] + ); } public function testPaymentWithInvalidScaExemption() { + $threeDSecureTwo = array( + 'authenticationSource' => "Browser", + 'scaExemption' => "test" + ); + $cardPayment = $this->getBuilder() - ->setAttribute('scaExemption', "test"); + ->setThreeDSecureTwoFields($threeDSecureTwo); try { $cardPayment->build(ConfigHelper::getCybersourceConfig()); $this->fail('An expected ValidationError has not been raised.'); @@ -104,8 +124,14 @@ public function testPaymentWithInvalidScaExemption() public function testPaymentWithValidScaExemption() { + $threeDSecureTwo = array( + 'authenticationSource' => "Browser", + 'scaExemption' => "trustedBeneficiary" + ); + $cardPayment = $this->getBuilder() - ->setAttribute('scaExemption', "trustedBeneficiary"); + ->setThreeDSecureTwoFields($threeDSecureTwo); + try { $cardPayment->build(ConfigHelper::getCybersourceConfig()); } catch (\Exception $e) { @@ -113,6 +139,9 @@ public function testPaymentWithValidScaExemption() return; } - Assert::assertEquals("trustedBeneficiary", $cardPayment->getAttributeValues()["scaExemption"]); + Assert::assertEquals( + "trustedBeneficiary", + $cardPayment->getAttributeValues()["threeDSecure"]["scaExemption"] + ); } }