Skip to content

Commit

Permalink
+TestMode support
Browse files Browse the repository at this point in the history
  • Loading branch information
hakito committed Jun 20, 2020
1 parent 11beca4 commit 48e7351
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 20 deletions.
16 changes: 9 additions & 7 deletions README.md
Expand Up @@ -41,20 +41,22 @@ In your app.local.php add an entry for EpsBankTransfer

```php
[
'EpsBankTransfer', [
'EpsBankTransfer',
[
// required parameters
'userid' => 'AKLJS231534', // Eps "Händler" id
'secret' => 'topSecret', // Secret for authentication
'iban' => 'AT611904300234573201', // IBAN code of bank account where money will be sent to
'bic' => 'GAWIATW1XXX', // BIC code of bank account where money will be sent to
'userid' => 'AKLJS231534', // Eps "Händler" id
'secret' => 'topSecret', // Secret for authentication
'iban' => 'AT611904300234573201', // IBAN code of bank account where money will be sent to
'bic' => 'GAWIATW1XXX', // BIC code of bank account where money will be sent to
'account_owner' => 'John Q. Public', // Name of the account owner where money will be sent to

// Encryption key for sending encrypted remittance identifier as encrypted string
'encryptionKey' => 'A_SECRET_KEY_MUST_BE_32_BYTES_LONG',

//// optional parameters
//'ObscuritySuffixLength' => 8, // Number of hash chars appended to remittance identifier
//'ObscuritySeed' => 'SOME RANDOM STRING', // Seed for the random remittance identifier suffix. REQUIRED when ObscuritySuffixLength > 0 provided
//'ObscuritySuffixLength' => 8, // Number of hash chars appended to remittance identifier
//'ObscuritySeed' => 'SOME RANDOM STRING', // Seed for the random remittance identifier suffix. REQUIRED when ObscuritySuffixLength > 0 provided
//'TestMode' => true // Use EPS test mode URL endpoint
]
];
```
Expand Down
3 changes: 2 additions & 1 deletion composer.json
Expand Up @@ -30,6 +30,7 @@
"installer-name": "EpsBankTransfer"
},
"require-dev": {
"phpunit/phpunit": "^6.0"
"phpunit/phpunit": "^6.0",
"hakito/publisher": "^1.3"
}
}
7 changes: 5 additions & 2 deletions src/Controller/Component/EpsComponent.php
Expand Up @@ -38,11 +38,12 @@ public function initialize(array $config)
$defaults = array(
'ObscuritySuffixLength' => 8,
'ObscuritySeed' => 'c2af496ecf4b9f095447a7b9f5c02d20924252bd',
'TestMode' => false
);

$config = array_merge($defaults, Configure::read('EpsBankTransfer'));

$SoCommunicator = Plugin::GetSoCommunicator();
$SoCommunicator = Plugin::GetSoCommunicator($config['TestMode']);
$SoCommunicator->ObscuritySuffixLength = $config['ObscuritySuffixLength'];
$SoCommunicator->ObscuritySeed = $config['ObscuritySeed'];

Expand Down Expand Up @@ -132,7 +133,8 @@ public function PaymentRedirect($remittanceIdentifier, $TransactionOkUrl, $Trans
$logPrefix = 'SendPaymentOrder [' . $referenceIdentifier . '] ConfUrl: ' . $confirmationUrl;

Plugin::WriteLog($logPrefix . ' over ' . $transferInitiatorDetails->InstructedAmount);
$plain = Plugin::GetSoCommunicator()->SendTransferInitiatorDetails($transferInitiatorDetails);
$testMode = !empty($config['TestMode']);
$plain = Plugin::GetSoCommunicator($testMode)->SendTransferInitiatorDetails($transferInitiatorDetails);
$xml = new \SimpleXMLElement($plain);
$soAnswer = $xml->children(eps_bank_transfer\XMLNS_epsp);
/** @noinspection PhpUndefinedFieldInspection */
Expand Down Expand Up @@ -211,6 +213,7 @@ public function HandleConfirmationUrl($eRemittanceIdentifier, $rawPostStream = '
return !empty($result['handled']);
};

$testMode = !empty($config['TestMode']);
try {
Plugin::GetSoCommunicator()->HandleConfirmationUrl(
$confirmationCallbackWrapper,
Expand Down
19 changes: 10 additions & 9 deletions src/Plugin.php
Expand Up @@ -11,8 +11,8 @@
*/
class Plugin extends BasePlugin
{
/** @var SoCommunicator */
public static $SoCommunicator;
/** @var SoCommunicator[] */
private static $SoCommunicator = [];

/** @var string prefix for caching keys in this component */
public static $CacheKeyPrefix = 'EpsBankTransfer';
Expand All @@ -30,13 +30,13 @@ public static function Base64Decode($s)
return base64_decode(str_replace(array(',', '-'), array('\\', '/'), $s));
}

public static function GetBanksArray($invalidateCache, $config = 'default')
public static function GetBanksArray($invalidateCache, $config = 'default', $testMode = false)
{
$key = self::$CacheKeyPrefix . 'BanksArray';
$banks = Cache::read($key, $config);
if (!$banks || $invalidateCache)
{
$banks = Plugin::GetSoCommunicator()->TryGetBanksArray();
$banks = Plugin::GetSoCommunicator($testMode)->TryGetBanksArray();
if (!empty($banks))
Cache::write($key, $banks, $config);
}
Expand All @@ -47,14 +47,15 @@ public static function GetBanksArray($invalidateCache, $config = 'default')
* Get scheme operator instance
* @return \at\externet\eps_bank_transfer\SoCommunicator
*/
public static function GetSoCommunicator()
public static function GetSoCommunicator($testMode = false)
{
if (self::$SoCommunicator == null)
$index = empty($testMode) ? 'live' : 'test';
if (empty(self::$SoCommunicator[$index]))
{
self::$SoCommunicator = new \at\externet\eps_bank_transfer\SoCommunicator();
self::$SoCommunicator->LogCallback = [Plugin::class, 'WriteLog'];
self::$SoCommunicator[$index] = new \at\externet\eps_bank_transfer\SoCommunicator($testMode);
self::$SoCommunicator[$index]->LogCallback = [Plugin::class, 'WriteLog'];
}
return self::$SoCommunicator;
return self::$SoCommunicator[$index];
}

public static function WriteLog($message)
Expand Down
3 changes: 2 additions & 1 deletion tests/TestCase/Controller/Component/EpsComponentTest.php
Expand Up @@ -43,7 +43,8 @@ public function setUp()
$event = new Event('Controller.startup', $this->Controller);
$this->Eps->startup($event);

Plugin::$SoCommunicator = $this->getMockBuilder('at\externet\eps_bank_transfer\SoCommunicator')
$published = new \hakito\Publisher\StaticPublished(Plugin::class);
$published->SoCommunicator['live'] = $this->getMockBuilder('at\externet\eps_bank_transfer\SoCommunicator')
->getMock();
Plugin::$EnableLogging = false;
Cache::clear();
Expand Down

0 comments on commit 48e7351

Please sign in to comment.