diff --git a/README.md b/README.md index ee724b2..3437d3c 100644 --- a/README.md +++ b/README.md @@ -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 ] ]; ``` diff --git a/composer.json b/composer.json index 766bc33..d457330 100644 --- a/composer.json +++ b/composer.json @@ -30,6 +30,7 @@ "installer-name": "EpsBankTransfer" }, "require-dev": { - "phpunit/phpunit": "^6.0" + "phpunit/phpunit": "^6.0", + "hakito/publisher": "^1.3" } } diff --git a/src/Controller/Component/EpsComponent.php b/src/Controller/Component/EpsComponent.php index 587cde4..99c9e65 100644 --- a/src/Controller/Component/EpsComponent.php +++ b/src/Controller/Component/EpsComponent.php @@ -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']; @@ -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 */ @@ -211,6 +213,7 @@ public function HandleConfirmationUrl($eRemittanceIdentifier, $rawPostStream = ' return !empty($result['handled']); }; + $testMode = !empty($config['TestMode']); try { Plugin::GetSoCommunicator()->HandleConfirmationUrl( $confirmationCallbackWrapper, diff --git a/src/Plugin.php b/src/Plugin.php index 0086c6b..040ec15 100644 --- a/src/Plugin.php +++ b/src/Plugin.php @@ -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'; @@ -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); } @@ -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) diff --git a/tests/TestCase/Controller/Component/EpsComponentTest.php b/tests/TestCase/Controller/Component/EpsComponentTest.php index a514dc8..b017a3e 100644 --- a/tests/TestCase/Controller/Component/EpsComponentTest.php +++ b/tests/TestCase/Controller/Component/EpsComponentTest.php @@ -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();