Skip to content

Commit

Permalink
Merge pull request #72 from Judopay/ResumeComplete3dOptionalCv2-JR-5219
Browse files Browse the repository at this point in the history
ResumeComplete3dOptionalCv2-JR-5219
  • Loading branch information
chrisurun authored Jul 8, 2021
2 parents b5e0b62 + e57fdb2 commit eca0d4b
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 5 deletions.
3 changes: 1 addition & 2 deletions src/Judopay/Model/CompleteThreeDSecureTwo.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ class CompleteThreeDSecureTwo extends Model

protected $requiredAttributes
= array(
'receiptId',
'cv2'
'receiptId'
);
}
1 change: 0 additions & 1 deletion src/Judopay/Model/ResumeThreeDSecureTwo.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ class ResumeThreeDSecureTwo extends Model
protected $requiredAttributes
= array(
'receiptId',
'cv2',
'methodCompletion'
);
}
46 changes: 46 additions & 0 deletions tests/Base/ThreeDSecureTwoTests.php
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,52 @@ public function testPaymentWithThreedSecureTwoResumeTransaction()
AssertionHelper::assertRequiresThreeDSecureTwoChallengeCompletion($resumeResult);
}

public function testPaymentWithThreedSecureTwoResumeTransactionNoCv2()
{
// Build a threeDSecureTwo payment
$threeDSecureTwo = array(
'authenticationSource' => "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);

// Build the Resume3d request for the payment after its device gathering happened
// But without setting a CV2 as it is an optional value for that step
$resumeThreeDSecureTwo = $this->getResumeThreeDSecureTwoBuilder($paymentResult['receiptId'])
->setThreeDSecureTwoMethodCompletion("Yes")
->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
*/
Expand Down
4 changes: 2 additions & 2 deletions tests/ThreeDSecureTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ public function testUpdateThreeDSecurePayment()
// Update the existing payment with a PUT
$threeDSecureResult = $threeDSecureCompletion->update();

// The payment has a successful status
AssertionHelper::assertSuccessfulPayment($threeDSecureResult);
// The payment has a declined status because the PaRes is not the correct one
AssertionHelper::assertDeclinedPayment($threeDSecureResult);
}

public function testUpdateWrongThreeDSecurePayment()
Expand Down

0 comments on commit eca0d4b

Please sign in to comment.