Skip to content

Commit

Permalink
2.0.5
Browse files Browse the repository at this point in the history
  • Loading branch information
dyd committed Dec 16, 2024
1 parent 264cea4 commit ed089e6
Show file tree
Hide file tree
Showing 18 changed files with 301 additions and 40 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
2.0.5
-----
**Features**:

* Added terminal token automatic configuration in the Notification class required by the initReconciliation action. There is no need for Terminal Token configuration during notification handling and Smart Router used.

**Fixes**:

* Fixed missing 404 page returned from the Gateway for the requests which require a terminal token. InvalidArgument exception is thrown with an empty token configuration.

2.0.4
-----
**Features**
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ Installation
composer.phar require genesisgateway/genesis_php
```

Note: If you want to use the package with PHP version lover than 7.4, you can use
Note: If you want to use the package with PHP version lower or equal to 7.4, you can use

```sh
composer.phar require genesisgateway/genesis_php --update-no-dev
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.0.4
2.0.5
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "genesisgateway/genesis_php",
"description": "PHP Client for Genesis Payment Processing Gateway",
"version": "2.0.4",
"version": "2.0.5",
"license": "MIT",
"keywords": [
"3ds_v2",
Expand Down
82 changes: 67 additions & 15 deletions spec/Genesis/Api/NotificationSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,43 +9,48 @@
class NotificationSpec extends ObjectBehavior
{
private $password;
private $terminal_token;
private $unique_id;
private $wpf_unique_id;

private $sample = array(
'api' => array(
'unique_id' => '',
'signature' => '',
'status' => 'approved',
'unique_id' => '',
'signature' => '',
'status' => 'approved',
'terminal_token' => ''
),
'wpf' => array(
'wpf_unique_id' => '',
'signature' => '',
'status' => 'approved',
'wpf_unique_id' => '',
'signature' => '',
'status' => 'approved',
'payment_transaction_terminal_token' => ''
)
);

public function __construct()
{
$this->password = Faker::getInstance()->uuid;
$this->password = Faker::getInstance()->uuid;
$this->terminal_token = Faker::getInstance()->uuid;

Config::setPassword($this->password);

for ($i=0; $i < mt_rand(32, 48); $i++) {
$this->sample['api']['unique_id'] .= chr(mt_rand(97, 122));
}

$this->sample['api']['signature'] = hash(
'sha1',
$this->sample['api']['unique_id'] . \Genesis\Config::getPassword()
);
$this->unique_id = $this->sample['api']['unique_id'];
$this->sample['api']['signature'] = hash('sha1', $this->unique_id . Config::getPassword());

for ($i=0; $i < mt_rand(32, 48); $i++) {
$this->sample['wpf']['wpf_unique_id'] .= chr(mt_rand(97, 122));
}

$this->sample['wpf']['signature'] = hash(
'sha1',
$this->sample['wpf']['wpf_unique_id'] . \Genesis\Config::getPassword()
);
$this->wpf_unique_id = $this->sample['wpf']['wpf_unique_id'];
$this->sample['wpf']['signature'] = hash('sha1', $this->wpf_unique_id . Config::getPassword());

$this->sample['api']['terminal_token'] = $this->terminal_token;
$this->sample['wpf']['payment_transaction_terminal_token'] = $this->terminal_token;
}

public function it_is_initializable()
Expand Down Expand Up @@ -275,6 +280,50 @@ public function it_can_render_wpf_response_correctly()
$this->generateResponse()->shouldBe(ob_get_clean());
}

public function it_when_transaction_with_terminal_token_assignment()
{
$this->parseNotification($this->sample['api']);

$this->getTerminalToken()->shouldBe($this->terminal_token);
}

public function it_when_transaction_with_unique_id_assignment()
{
$this->parseNotification($this->sample['api']);

$this->getUniqueId()->shouldBe($this->unique_id);
}

public function it_when_wpf_with_terminal_token_assignment()
{
$this->parseNotification($this->sample['wpf']);

$this->getTerminalToken()->shouldBe($this->terminal_token);
}

public function it_when_wpf_with_unique_id_assignment()
{
$this->parseNotification($this->sample['wpf']);

$this->getUniqueId()->shouldBe($this->wpf_unique_id);
}

public function it_when_transaction_with_token_configuration()
{
Config::setToken(null);
$this->parseNotification($this->sample['api']);

$this->shouldBeTokenConfiguredWith($this->terminal_token);
}

public function it_when_transaction_with_previously_defined_token()
{
Config::setToken('123456');
$this->parseNotification($this->sample['api']);

$this->shouldBeTokenConfiguredWith('123456');
}

public function getMatchers(): array
{
return array(
Expand All @@ -284,6 +333,9 @@ public function getMatchers(): array
'contain' => function ($subject, $arg) {
return (stripos($subject, $arg) !== false);
},
'beTokenConfiguredWith' => function($subject, $arg) {
return Config::getToken() === $arg;
}
);
}
}
16 changes: 16 additions & 0 deletions spec/Genesis/Api/Request/Base/FinancialSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,16 @@
use Genesis\Config;
use spec\Genesis\Api\Stubs\Base\Request\FinancialStub;
use spec\SharedExamples\Faker;
use spec\SharedExamples\Genesis\Api\MissingTerminalTokenExamples;
use spec\SharedExamples\Genesis\Api\Request\RequestExamples;

class FinancialSpec extends \PhpSpec\ObjectBehavior
{
use MissingTerminalTokenExamples;
use RequestExamples {
__construct as parentConstruct;
}

private $faker_uuid;

private $faker_usage;
Expand All @@ -17,6 +24,7 @@ class FinancialSpec extends \PhpSpec\ObjectBehavior

public function __construct()
{
$this->parentConstruct();
$this->faker_uuid = Faker::getInstance()->uuid;
$this->faker_usage = Faker::getInstance()->sentence;
$this->faker_remote_ip = Faker::getInstance()->ipv4;
Expand Down Expand Up @@ -53,6 +61,7 @@ public function it_should_init_proper_xml_configuration_without_smart_router()
{
Config::setToken($this->faker_uuid);
Config::setEndpoint(Endpoints::EMERCHANTPAY);
$this->setRequestParameters();

$this->getDocument();

Expand All @@ -65,6 +74,7 @@ public function it_should_init_proper_xml_configuration_with_smart_router()
{
Config::setToken(Faker::getInstance()->uuid);
Config::setEndpoint(Endpoints::EMERCHANTPAY);
$this->setRequestParameters();
$this->setUseSmartRouter(true);

$this->getDocument();
Expand All @@ -87,6 +97,12 @@ public function it_should_populate_proper_base_financial_structure()

public function it_should_populate_proper_transaction_structure()
{
$this->setRequestParameters();
$this->getDocument()->shouldContain('<stub>financial</stub>');
}

protected function setRequestParameters()
{
$this->setTransactionId(Faker::getInstance()->uuid);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Genesis\Builder;
use Genesis\Exceptions\ErrorParameter;
use PhpSpec\ObjectBehavior;
use spec\SharedExamples\Genesis\Api\MissingTerminalTokenExamples;
use spec\SharedExamples\Genesis\Api\Request\RequestExamples;

/**
Expand All @@ -15,6 +16,7 @@
*/
class RegisterAccountSpec extends ObjectBehavior
{
use MissingTerminalTokenExamples;
use RequestExamples;

public function it_is_initializable()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use Genesis\Utils\Country;
use DateTime;
use PhpSpec\ObjectBehavior;
use spec\SharedExamples\Genesis\Api\MissingTerminalTokenExamples;
use spec\SharedExamples\Genesis\Api\Request\RequestExamples;

/**
Expand All @@ -18,6 +19,7 @@
*/
class SelectAccountSpec extends ObjectBehavior
{
use MissingTerminalTokenExamples;
use RequestExamples;

public function it_is_initializable()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@
use Genesis\Api\Request\NonFinancial\Reconcile\DateRange;
use PhpSpec\ObjectBehavior;
use spec\SharedExamples\Faker;
use spec\SharedExamples\Genesis\Api\MissingTerminalTokenExamples;
use spec\SharedExamples\Genesis\Api\Request\RequestExamples;

class DateRangeSpec extends ObjectBehavior
{
use MissingTerminalTokenExamples;
use RequestExamples;

public function it_is_initializable()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@

use Genesis\Api\Request\NonFinancial\Reconcile\Transaction;
use PhpSpec\ObjectBehavior;
use spec\SharedExamples\Genesis\Api\MissingTerminalTokenExamples;
use spec\SharedExamples\Genesis\Api\Request\RequestExamples;

class TransactionSpec extends ObjectBehavior
{
use MissingTerminalTokenExamples;
use RequestExamples;

public function it_is_initializable()
Expand Down
22 changes: 22 additions & 0 deletions spec/Genesis/Api/Request/NonFinancial/Sca/CheckerSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,23 @@
use Genesis\Api\Constants\Transaction\Parameters\ScaExemptions;
use Genesis\Api\Request\NonFinancial\Sca\Checker;
use Genesis\Builder;
use Genesis\Config;
use Genesis\Exceptions\InvalidArgument;
use Genesis\Utils\Currency;
use PhpSpec\ObjectBehavior;
use spec\SharedExamples\Faker;
use spec\SharedExamples\Genesis\Api\MissingTerminalTokenExamples;
use spec\SharedExamples\Genesis\Api\Request\RequestExamples;

/**
* Class CheckerSpec
* @package spec\Genesis\Api\Request\NonFinancial\Sca
*/
class CheckerSpec extends ObjectBehavior
{
use MissingTerminalTokenExamples;
use RequestExamples;

/**
* @property Generator $faker
*/
Expand Down Expand Up @@ -218,6 +224,17 @@ public function it_should_fail_with_invalid_transaction_amount()
$this->shouldThrow(InvalidArgument::class)->during('setTransactionAmount', ['23,45']);
}

public function it_should_build_proper_url()
{
Config::setToken('123456');
Config::setEndpoint('emp');
Config::setEnvironment('staging');
$this->setRequestParameters();
$this->getDocument();

$this->getApiConfig('url')->shouldBe('https://staging.gate.emerchantpay.net:443/v1/sca/checker/123456/');
}

/**
* Helper Methods
*/
Expand Down Expand Up @@ -271,4 +288,9 @@ protected function getRandomExemption()

return $exemptions[array_rand($exemptions)];
}

protected function setRequestParameters()
{
$this->setDefaultRequestParameters();
}
}
8 changes: 8 additions & 0 deletions spec/Genesis/Api/Stubs/Base/Request/FinancialStub.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace spec\Genesis\Api\Stubs\Base\Request;

use Genesis\Api\Request\Base\Financial;
use Genesis\Utils\Common;

class FinancialStub extends Financial
{
Expand All @@ -15,4 +16,11 @@ protected function getPaymentTransactionStructure()
{
return ['stub' => 'financial'];
}

protected function setRequiredFields()
{
$requiredFields = ['transaction_id'];

$this->requiredFields = Common::createArrayObject($requiredFields);
}
}
26 changes: 26 additions & 0 deletions spec/SharedExamples/Genesis/Api/MissingTerminalTokenExamples.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

namespace spec\SharedExamples\Genesis\Api;

use Genesis\Config;
use Genesis\Exceptions\InvalidArgument;
use spec\SharedExamples\Faker;

trait MissingTerminalTokenExamples
{
public function it_should_throw_when_empty_terminal_token()
{
Config::setToken(null);
$this->setRequestParameters();

$this->shouldThrow(InvalidArgument::class)->during('getDocument');
}

public function it_should_not_throw_when_terminal_token()
{
Config::setToken(Faker::getInstance()->uuid);
$this->setRequestParameters();

$this->shouldNotThrow()->during('getDocument');
}
}
10 changes: 10 additions & 0 deletions spec/SharedExamples/Genesis/Api/Request/RequestExamples.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@

namespace spec\SharedExamples\Genesis\Api\Request;

use Genesis\Config;
use Genesis\Utils\Common;
use spec\SharedExamples\Faker;
use spec\SharedExamples\Genesis\Api\MissingTerminalTokenExamples;

/**
* Trait RequestExamples
Expand All @@ -13,6 +15,14 @@ trait RequestExamples
{
private static $faker;

public function __construct()
{
Config::setUsername(Faker::getInstance()->uuid);
Config::setPassword(Faker::getInstance()->uuid);
Config::setToken(Faker::getInstance()->uuid);
Config::setForceSmartRouting(false);
}

public function it_can_build_structure()
{
$this->setRequestParameters();
Expand Down
Loading

0 comments on commit ed089e6

Please sign in to comment.