Skip to content

Commit

Permalink
Merge pull request #76 from Judopay/3dsResumeCompleteAccountDetails-J…
Browse files Browse the repository at this point in the history
…R-6384

3dsResumeCompleteAccountDetails-JR-6384
  • Loading branch information
chrisurun authored Jun 28, 2022
2 parents ec7a093 + 8cd5692 commit d8ebd40
Show file tree
Hide file tree
Showing 11 changed files with 76 additions and 26 deletions.
5 changes: 4 additions & 1 deletion src/Judopay/Model/CompleteThreeDSecureTwo.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions src/Judopay/Model/ResumeThreeDSecureTwo.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions tests/Builders/ResumeThreeDSecureTwoBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,10 @@ public function setThreeDSecureTwoMethodCompletion($methodCompletion)
$this->setAttribute('methodCompletion', $methodCompletion);
return $this;
}

public function setThreeDSecureTwoPrimaryAccountDetails($primaryAccountDetails)
{
$this->setAttribute('primaryAccountDetails', $primaryAccountDetails);
return $this;
}
}
4 changes: 2 additions & 2 deletions tests/CheckCardTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

namespace Tests;

use Tests\Base\ThreeDSecureTwoTests;
use PHPUnit\Framework\TestCase;
use Tests\Builders\CheckCardBuilder;
use Tests\Helpers\AssertionHelper;
use Tests\Helpers\ConfigHelper;

class CheckCardTest extends ThreeDSecureTwoTests
class CheckCardTest extends TestCase
{
protected function getBuilder()
{
Expand Down
4 changes: 2 additions & 2 deletions tests/PaymentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@

namespace Tests;

use PHPUnit\Framework\TestCase;
use PHPUnit_Framework_Assert as Assert;
use Tests\Base\ThreeDSecureTwoTests;
use Tests\Builders\CardPaymentBuilder;
use Tests\Builders\GetTransactionBuilder;
use Tests\Helpers\AssertionHelper;
use Tests\Helpers\ConfigHelper;

class PaymentTest extends ThreeDSecureTwoTests
class PaymentTest extends TestCase
{
protected function getBuilder()
{
Expand Down
14 changes: 0 additions & 14 deletions tests/PreauthTest.php

This file was deleted.

2 changes: 1 addition & 1 deletion tests/RefundTest.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Tests\Base;
namespace Tests;

use PHPUnit\Framework\Assert;
use PHPUnit\Framework\TestCase;
Expand Down
4 changes: 2 additions & 2 deletions tests/RegisterCardTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

namespace Tests;

use Tests\Base\ThreeDSecureTwoTests;
use PHPUnit\Framework\TestCase;
use Tests\Builders\RegisterCardBuilder;
use Tests\Helpers\AssertionHelper;
use Tests\Helpers\ConfigHelper;

class RegisterCardTest extends ThreeDSecureTwoTests
class RegisterCardTest extends TestCase
{
protected function getBuilder()
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Tests\Base;
namespace Tests;

use GuzzleHttp\Exception\BadResponseException;
use Judopay\Exception\ApiException;
Expand All @@ -13,7 +13,7 @@
use Tests\Helpers\AssertionHelper;
use Tests\Helpers\ConfigHelper;

abstract class ThreeDSecureTwoTests extends PaymentTests
class ThreeDSecureTwoTest extends TestCase
{
protected function getPaymentBuilder()
{
Expand Down Expand Up @@ -195,6 +195,59 @@ public function testPaymentWithThreeDSecureTwoResumeTransactionNoCv2()
}
}

public function testPaymentWithThreeDSecureTwoResumeTransactionAccountDetails()
{
// 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);

$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
*/
Expand Down
2 changes: 1 addition & 1 deletion tests/VoidTest.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Tests\Base;
namespace Tests;

use PHPUnit\Framework\TestCase;
use Tests\Builders\CardPaymentBuilder;
Expand Down
1 change: 0 additions & 1 deletion tests/WebPaymentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

use PHPUnit\Framework\TestCase;
use Tests\Builders\CardPaymentBuilder;
use Tests\Builders\GetTransactionBuilder;
use Tests\Builders\WebPayments\PaymentBuilder;
use Tests\Helpers\AssertionHelper;
use Tests\Helpers\ConfigHelper;
Expand Down

0 comments on commit d8ebd40

Please sign in to comment.