-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #47 from Judopay/Add3dsModelAndPut-JR-3516
Add3dsModelAndPut-JR-3516
- Loading branch information
Showing
7 changed files
with
189 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?php | ||
namespace Judopay\Model; | ||
|
||
use Judopay\DataType; | ||
use Judopay\Model; | ||
|
||
class CompleteThreeD extends Model | ||
{ | ||
protected $resourcePath = 'transactions'; | ||
protected $validApiMethods = array('create', 'update'); | ||
|
||
protected $attributes | ||
= array( | ||
'ReceiptId' => DataType::TYPE_STRING, | ||
'MD' => DataType::TYPE_STRING, | ||
'PaRes' => DataType::TYPE_STRING | ||
); | ||
|
||
protected $requiredAttributes | ||
= array( | ||
'ReceiptId', | ||
'MD', | ||
'PaRes' | ||
); | ||
|
||
public function complete3DSecure() | ||
{ | ||
$this->checkApiMethodIsSupported(__FUNCTION__); | ||
$this->checkJudoId(); | ||
$this->checkRequiredAttributes($this->attributeValues); | ||
$this->resourcePath .= '/' . $this->attributeValues['ReceiptId']; | ||
$response = $this->request->put( | ||
$this->resourcePath, | ||
$this->attributeValues | ||
); | ||
return $this->getResponseArray($response); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<?php | ||
|
||
namespace Tests\Builders; | ||
|
||
class CompleteThreeDBuilder extends CardPaymentBuilder | ||
{ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
<?php | ||
|
||
namespace Tests; | ||
|
||
use PHPUnit\Framework\TestCase; | ||
use Tests\Builders\CardPaymentBuilder; | ||
use Tests\Builders\CompleteThreeDBuilder; | ||
use Tests\Helpers\AssertionHelper; | ||
use Tests\Helpers\ConfigHelper; | ||
use Judopay\Exception\ApiException as ApiException; | ||
|
||
class ThreeDSecureTest extends TestCase | ||
{ | ||
protected function getBuilder() | ||
{ | ||
return new CompleteThreeDBuilder(); | ||
} | ||
|
||
protected function getPaymentBuilder() | ||
{ | ||
return new CardPaymentBuilder(); | ||
} | ||
|
||
public function testUpdateThreeDSecurePayment() | ||
{ | ||
// Build a regular payment | ||
$cardPayment = $this->getPaymentBuilder() | ||
->setType(CardPaymentBuilder::THREEDS_VISA_CARD) | ||
->build(ConfigHelper::getConfig()); | ||
|
||
// Process the payment | ||
$paymentResult = $cardPayment->create(); | ||
|
||
// We should have a 3DS required message | ||
AssertionHelper::assertRequiresThreeDSecure($paymentResult); | ||
|
||
// Build the 3DS request | ||
$threeDSecureCompletion = $this->getBuilder() | ||
->setAttribute('ReceiptId', $paymentResult['receiptId']) | ||
->setAttribute('MD', $paymentResult['md']) | ||
->setAttribute('PaRes', "paResReturnedByTheAcsUrl") // The ACS URL needs to be visited by the consumer | ||
->build(ConfigHelper::getConfig()); | ||
|
||
// Update the existing payment with a PUT | ||
$threeDSecureResult = $threeDSecureCompletion->update(); | ||
|
||
// The payment has a successful status | ||
AssertionHelper::assertSuccessfulPayment($threeDSecureResult); | ||
} | ||
|
||
public function testUpdateWrongThreeDSecurePayment() | ||
{ | ||
// Build the 3DS request for a Receipt not linked to this account | ||
$threeDSecureCompletion = $this->getBuilder() | ||
->setAttribute('ReceiptId', "536586810336354304") | ||
->setAttribute('MD', "200120164510412101100951") | ||
->setAttribute('PaRes', "paResReturnedByTheAcsUrl") // The ACS URL needs to be visited by the consumer | ||
->build(ConfigHelper::getConfig()); | ||
|
||
try { | ||
// Update the existing payment with a PUT | ||
$threeDSecureResult = $threeDSecureCompletion->update(); | ||
} catch (\Exception $e) { | ||
AssertionHelper::assertApiExceptionWithModelErrors( | ||
$e, | ||
0, | ||
72, | ||
409, | ||
ApiException::CATEGORY_PROCESSING | ||
); | ||
|
||
return; | ||
} | ||
|
||
$this->fail('An expected ApiException has not been raised.'); | ||
} | ||
} |