Skip to content

Commit

Permalink
Merge pull request #74 from Judopay/ChallengeAndScaInThreeDSecure-JR-…
Browse files Browse the repository at this point in the history
…6388

ChallengeAndScaInThreeDSecure-JR-6388
  • Loading branch information
chrisurun authored Jun 24, 2022
2 parents eca0d4b + 6031579 commit f360ffa
Show file tree
Hide file tree
Showing 8 changed files with 80 additions and 55 deletions.
69 changes: 36 additions & 33 deletions src/Judopay/DataType.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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();
}
Expand Down
3 changes: 0 additions & 3 deletions src/Judopay/Model/CardPayment.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
3 changes: 0 additions & 3 deletions src/Judopay/Model/CheckCard.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 2 additions & 0 deletions src/Judopay/Model/Inner/ThreeDSecureTwo.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 0 additions & 3 deletions src/Judopay/Model/TokenPayment.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
12 changes: 6 additions & 6 deletions tests/Base/ThreeDSecureTwoTests.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -54,7 +54,7 @@ public function testPaymentWithThreedSecureTwoInvalidAuthenticationSource()
}
}

public function testPaymentWithThreedSecureTwoInvalidMethodCompletion()
public function testPaymentWithThreeDSecureTwoInvalidMethodCompletion()
{
// Build a threeDSecureTwo payment with an invalid attribute
$threeDSecureTwo = array(
Expand All @@ -78,7 +78,7 @@ public function testPaymentWithThreedSecureTwoInvalidMethodCompletion()
}
}

public function testPaymentWithThreedSecureTwoRequiresDeviceDetailsCheck()
public function testPaymentWithThreeDSecureTwoRequiresDeviceDetailsCheck()
{
// Build a threeDSecureTwo payment
$threeDSecureTwo = array(
Expand All @@ -104,7 +104,7 @@ public function testPaymentWithThreedSecureTwoRequiresDeviceDetailsCheck()
AssertionHelper::assertRequiresThreeDSecureTwoDeviceDetails($paymentResult);
}

public function testPaymentWithThreedSecureTwoResumeTransaction()
public function testPaymentWithThreeDSecureTwoResumeTransaction()
{
// Build a threeDSecureTwo payment
$threeDSecureTwo = array(
Expand Down Expand Up @@ -149,7 +149,7 @@ public function testPaymentWithThreedSecureTwoResumeTransaction()
AssertionHelper::assertRequiresThreeDSecureTwoChallengeCompletion($resumeResult);
}

public function testPaymentWithThreedSecureTwoResumeTransactionNoCv2()
public function testPaymentWithThreeDSecureTwoResumeTransactionNoCv2()
{
// Build a threeDSecureTwo payment
$threeDSecureTwo = array(
Expand Down Expand Up @@ -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')
Expand Down
2 changes: 1 addition & 1 deletion tests/Builders/CardPaymentBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
41 changes: 35 additions & 6 deletions tests/PaymentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.');
Expand All @@ -76,22 +82,36 @@ 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) {
$this->fail('No exception should have been raised.');
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.');
Expand All @@ -104,15 +124,24 @@ 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) {
$this->fail('No exception should have been raised.');
return;
}

Assert::assertEquals("trustedBeneficiary", $cardPayment->getAttributeValues()["scaExemption"]);
Assert::assertEquals(
"trustedBeneficiary",
$cardPayment->getAttributeValues()["threeDSecure"]["scaExemption"]
);
}
}

0 comments on commit f360ffa

Please sign in to comment.