From 9f0f6eb1841c6b80bbef659c215576523c0c72f5 Mon Sep 17 00:00:00 2001 From: Christophe Surun Date: Fri, 22 Jan 2021 18:21:23 +0000 Subject: [PATCH] Setting correct ressourcePath for OneUseTokenPayment + new model for OneUseTokenPreauth + added OneUseTokenPreauthBuilder + Test cards expiry date update --- spec/fixtures/transactions/check_card.json | 2 +- spec/fixtures/transactions/register_card.json | 2 +- spec/fixtures/transactions/save_card.json | 2 +- .../transactions/voidtransaction.json | 2 +- src/Judopay/Model/OneUseTokenPayment.php | 2 +- src/Judopay/Model/OneUseTokenPreauth.php | 9 +++++ tests/AdditionsPaymentTest.php | 37 ++++++++++++++++++- tests/Builders/CardPaymentBuilder.php | 4 +- tests/Builders/EncryptDetailsBuilder.php | 2 +- tests/Builders/OneUseTokenPreauthBuilder.php | 16 ++++++++ tests/Builders/SaveCardBuilder.php | 2 +- 11 files changed, 70 insertions(+), 10 deletions(-) create mode 100644 src/Judopay/Model/OneUseTokenPreauth.php create mode 100644 tests/Builders/OneUseTokenPreauthBuilder.php diff --git a/spec/fixtures/transactions/check_card.json b/spec/fixtures/transactions/check_card.json index b5aab62..097459a 100644 --- a/spec/fixtures/transactions/check_card.json +++ b/spec/fixtures/transactions/check_card.json @@ -15,7 +15,7 @@ "currency": "GBP", "cardDetails": { "cardLastfour": "3436", - "endDate": "1220", + "endDate": "1225", "cardToken": "123123123", "cardType": 1 }, diff --git a/spec/fixtures/transactions/register_card.json b/spec/fixtures/transactions/register_card.json index 4185126..3dd06b1 100644 --- a/spec/fixtures/transactions/register_card.json +++ b/spec/fixtures/transactions/register_card.json @@ -15,7 +15,7 @@ "currency": "GBP", "cardDetails": { "cardLastfour": "3436", - "endDate": "1220", + "endDate": "1225", "cardToken": "123123123", "cardType": 1 }, diff --git a/spec/fixtures/transactions/save_card.json b/spec/fixtures/transactions/save_card.json index cf9ca84..d40dc5e 100644 --- a/spec/fixtures/transactions/save_card.json +++ b/spec/fixtures/transactions/save_card.json @@ -14,7 +14,7 @@ "currency": "GBP", "cardDetails": { "cardLastfour": "3436", - "endDate": "1220", + "endDate": "1225", "cardToken": "abc", "cardType": 1 }, diff --git a/spec/fixtures/transactions/voidtransaction.json b/spec/fixtures/transactions/voidtransaction.json index 69fe9c6..290f1e0 100644 --- a/spec/fixtures/transactions/voidtransaction.json +++ b/spec/fixtures/transactions/voidtransaction.json @@ -16,7 +16,7 @@ "currency": "GBP", "cardDetails": { "cardLastfour": "3436", - "endDate": "1220", + "endDate": "1225", "cardToken": "xxxxxxxxxxxxxxxxxxxx", "cardType": 1 }, diff --git a/src/Judopay/Model/OneUseTokenPayment.php b/src/Judopay/Model/OneUseTokenPayment.php index 304aebc..3f95406 100644 --- a/src/Judopay/Model/OneUseTokenPayment.php +++ b/src/Judopay/Model/OneUseTokenPayment.php @@ -7,7 +7,7 @@ class OneUseTokenPayment extends Model { - protected $resourcePath = 'transactions/preauths'; + protected $resourcePath = 'transactions/payments'; protected $validApiMethods = array('create'); protected $attributes = array( diff --git a/src/Judopay/Model/OneUseTokenPreauth.php b/src/Judopay/Model/OneUseTokenPreauth.php new file mode 100644 index 0000000..4eee789 --- /dev/null +++ b/src/Judopay/Model/OneUseTokenPreauth.php @@ -0,0 +1,9 @@ +makePaymentWithOneUseToken($oneUseToken); $this->assertEquals('Success', $tokenPaymentResult['result']); - # Try and fail to make second payment with one use token + # Try and fail to make a second payment with one use token try { $this->makePaymentWithOneUseToken($oneUseToken); } catch (\Exception $e) { @@ -34,6 +35,27 @@ public function testOneUseTokenPayment() $this->fail('An expected ApiException has not been raised.'); } + public function testOneUseTokenPreauth() + { + # Generate one use token + $encryptionResult = $this->generateOneUseToken(); + $oneUseToken = $encryptionResult['oneUseToken']; + $this->assertNotEmpty($oneUseToken); + + # Make successful preauth with one use token + $tokenPreauthResult = $this->makePreauthWithOneUseToken($oneUseToken); + $this->assertEquals('Success', $tokenPreauthResult['result']); + + # Try and fail to make a second preauth with one use token + try { + $this->makePreauthWithOneUseToken($oneUseToken); + } catch (\Exception $e) { + AssertionHelper::assertApiExceptionWithModelErrors($e, 0, 153, 400, 1); + return; + } + $this->fail('An expected ApiException has not been raised.'); + } + public function testOneUseTokenSaveCard() { # Generate one use token @@ -124,6 +146,11 @@ protected function tokenPaymentRequestBuilder() return new OneUseTokenPaymentBuilder(); } + protected function tokenPreauthRequestBuilder() + { + return new OneUseTokenPreauthBuilder(); + } + protected function saveEncryptedCardRequestBuilder() { return new SaveEncryptedCardBuilder(); @@ -148,6 +175,14 @@ protected function makePaymentWithOneUseToken($token) return $tokenPayment->create(); } + protected function makePreauthWithOneUseToken($token) + { + $tokenPreauth = $this->tokenPreauthRequestBuilder() + ->setAttribute('oneUseToken', $token) + ->build(ConfigHelper::getConfig()); + return $tokenPreauth->create(); + } + protected function saveCardWithOneUseToken($token) { $encryptedSaveCard = $this->saveEncryptedCardRequestBuilder() diff --git a/tests/Builders/CardPaymentBuilder.php b/tests/Builders/CardPaymentBuilder.php index 60904ed..02c2c28 100644 --- a/tests/Builders/CardPaymentBuilder.php +++ b/tests/Builders/CardPaymentBuilder.php @@ -34,7 +34,7 @@ public function compile() case self::VALID_VISA_CARD: $this->attributeValues += array( 'cardNumber' => '4976000000003436', - 'expiryDate' => '12/20', + 'expiryDate' => '12/25', 'cv2' => 452, ); break; @@ -42,7 +42,7 @@ public function compile() case self::INVALID_VISA_CARD: $this->attributeValues += array( 'cardNumber' => '4221690000004963', - 'expiryDate' => '12/20', + 'expiryDate' => '12/25', 'cv2' => 125, ); break; diff --git a/tests/Builders/EncryptDetailsBuilder.php b/tests/Builders/EncryptDetailsBuilder.php index 7170258..be22fd8 100644 --- a/tests/Builders/EncryptDetailsBuilder.php +++ b/tests/Builders/EncryptDetailsBuilder.php @@ -8,7 +8,7 @@ public function __construct() { $this->attributeValues = array( 'cardNumber' => '4976000000003436', - 'expiryDate' => '12/20', + 'expiryDate' => '12/25', 'cv2' => 452, ); } diff --git a/tests/Builders/OneUseTokenPreauthBuilder.php b/tests/Builders/OneUseTokenPreauthBuilder.php new file mode 100644 index 0000000..33e3280 --- /dev/null +++ b/tests/Builders/OneUseTokenPreauthBuilder.php @@ -0,0 +1,16 @@ +attributeValues = array( + 'yourConsumerReference' => 'oneUseTokenPhpTestConsumer', + 'yourPaymentReference' => substr(md5(rand()), 0, 7), + 'amount' => 1.01, + 'currency' => 'GBP' + ); + } +} diff --git a/tests/Builders/SaveCardBuilder.php b/tests/Builders/SaveCardBuilder.php index f2419be..1231869 100644 --- a/tests/Builders/SaveCardBuilder.php +++ b/tests/Builders/SaveCardBuilder.php @@ -9,7 +9,7 @@ public function __construct() $this->attributeValues = array( 'yourConsumerReference' => '12345', 'cardNumber' => '4976000000003436', - 'expiryDate' => '12/20', + 'expiryDate' => '12/25', 'cv2' => 452, ); }