Skip to content

Commit

Permalink
Merge pull request #56 from Judopay/OneUseTokenPaymentPreauth-JR-4564
Browse files Browse the repository at this point in the history
OneUseTokenPaymentPreauth-JR-4564
  • Loading branch information
chrisurun authored Jan 27, 2021
2 parents 8b7dd89 + 9f0f6eb commit ac1ff78
Show file tree
Hide file tree
Showing 11 changed files with 70 additions and 10 deletions.
2 changes: 1 addition & 1 deletion spec/fixtures/transactions/check_card.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"currency": "GBP",
"cardDetails": {
"cardLastfour": "3436",
"endDate": "1220",
"endDate": "1225",
"cardToken": "123123123",
"cardType": 1
},
Expand Down
2 changes: 1 addition & 1 deletion spec/fixtures/transactions/register_card.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"currency": "GBP",
"cardDetails": {
"cardLastfour": "3436",
"endDate": "1220",
"endDate": "1225",
"cardToken": "123123123",
"cardType": 1
},
Expand Down
2 changes: 1 addition & 1 deletion spec/fixtures/transactions/save_card.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"currency": "GBP",
"cardDetails": {
"cardLastfour": "3436",
"endDate": "1220",
"endDate": "1225",
"cardToken": "abc",
"cardType": 1
},
Expand Down
2 changes: 1 addition & 1 deletion spec/fixtures/transactions/voidtransaction.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"currency": "GBP",
"cardDetails": {
"cardLastfour": "3436",
"endDate": "1220",
"endDate": "1225",
"cardToken": "xxxxxxxxxxxxxxxxxxxx",
"cardType": 1
},
Expand Down
2 changes: 1 addition & 1 deletion src/Judopay/Model/OneUseTokenPayment.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

class OneUseTokenPayment extends Model
{
protected $resourcePath = 'transactions/preauths';
protected $resourcePath = 'transactions/payments';
protected $validApiMethods = array('create');
protected $attributes
= array(
Expand Down
9 changes: 9 additions & 0 deletions src/Judopay/Model/OneUseTokenPreauth.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

namespace Judopay\Model;

class OneUseTokenPreauth extends OneUseTokenPayment
{
protected $resourcePath = 'transactions/preauths';
protected $validApiMethods = array('create');
}
37 changes: 36 additions & 1 deletion tests/AdditionsPaymentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use PHPUnit\Framework\TestCase;
use Tests\Builders\EncryptDetailsBuilder;
use Tests\Builders\OneUseTokenPaymentBuilder;
use Tests\Builders\OneUseTokenPreauthBuilder;
use Tests\Builders\SaveEncryptedCardBuilder;
use Tests\Builders\RegisterEncryptedCardBuilder;
use Tests\Builders\CheckEncryptedCardBuilder;
Expand All @@ -24,7 +25,7 @@ public function testOneUseTokenPayment()
$tokenPaymentResult = $this->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) {
Expand All @@ -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
Expand Down Expand Up @@ -124,6 +146,11 @@ protected function tokenPaymentRequestBuilder()
return new OneUseTokenPaymentBuilder();
}

protected function tokenPreauthRequestBuilder()
{
return new OneUseTokenPreauthBuilder();
}

protected function saveEncryptedCardRequestBuilder()
{
return new SaveEncryptedCardBuilder();
Expand All @@ -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()
Expand Down
4 changes: 2 additions & 2 deletions tests/Builders/CardPaymentBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,15 @@ public function compile()
case self::VALID_VISA_CARD:
$this->attributeValues += array(
'cardNumber' => '4976000000003436',
'expiryDate' => '12/20',
'expiryDate' => '12/25',
'cv2' => 452,
);
break;

case self::INVALID_VISA_CARD:
$this->attributeValues += array(
'cardNumber' => '4221690000004963',
'expiryDate' => '12/20',
'expiryDate' => '12/25',
'cv2' => 125,
);
break;
Expand Down
2 changes: 1 addition & 1 deletion tests/Builders/EncryptDetailsBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public function __construct()
{
$this->attributeValues = array(
'cardNumber' => '4976000000003436',
'expiryDate' => '12/20',
'expiryDate' => '12/25',
'cv2' => 452,
);
}
Expand Down
16 changes: 16 additions & 0 deletions tests/Builders/OneUseTokenPreauthBuilder.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

namespace Tests\Builders;

class OneUseTokenPreauthBuilder extends AbstractModelBuilder
{
public function __construct()
{
$this->attributeValues = array(
'yourConsumerReference' => 'oneUseTokenPhpTestConsumer',
'yourPaymentReference' => substr(md5(rand()), 0, 7),
'amount' => 1.01,
'currency' => 'GBP'
);
}
}
2 changes: 1 addition & 1 deletion tests/Builders/SaveCardBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public function __construct()
$this->attributeValues = array(
'yourConsumerReference' => '12345',
'cardNumber' => '4976000000003436',
'expiryDate' => '12/20',
'expiryDate' => '12/25',
'cv2' => 452,
);
}
Expand Down

0 comments on commit ac1ff78

Please sign in to comment.