From eba996831db70bf7896def67bdda050462804474 Mon Sep 17 00:00:00 2001 From: Gerd Katzenbeisser Date: Sat, 20 Jun 2020 11:11:34 +0200 Subject: [PATCH] Breaking: Remove url argument for *GetBanks* + SoCommunicator::BaseUrl + SoCommunicator constructor with test mode flag --- README.md | 48 +++++++++++-------- composer.json | 4 +- samples/eps_start.php | 19 ++++++-- src/SoCommunicator.php | 40 ++++++++++------ .../eps_bank_transfer/SoCommunicatorTest.php | 28 +++++++++++ 5 files changed, 98 insertions(+), 41 deletions(-) diff --git a/README.md b/README.md index c85233b..e251c95 100644 --- a/README.md +++ b/README.md @@ -1,13 +1,11 @@ [![Build Status](https://travis-ci.org/hakito/PHP-Stuzza-EPS-BankTransfer.svg?branch=master)](https://travis-ci.org/hakito/PHP-Stuzza-EPS-BankTransfer) [![Coverage Status](https://coveralls.io/repos/hakito/PHP-Stuzza-EPS-BankTransfer/badge.png)](https://coveralls.io/r/hakito/PHP-Stuzza-EPS-BankTransfer) [![Latest Stable Version](https://poser.pugx.org/hakito/php-stuzza-eps-banktransfer/v/stable.svg)](https://packagist.org/packages/hakito/php-stuzza-eps-banktransfer) [![Total Downloads](https://poser.pugx.org/hakito/php-stuzza-eps-banktransfer/downloads.svg)](https://packagist.org/packages/hakito/php-stuzza-eps-banktransfer) [![Latest Unstable Version](https://poser.pugx.org/hakito/php-stuzza-eps-banktransfer/v/unstable.svg)](https://packagist.org/packages/hakito/php-stuzza-eps-banktransfer) [![License](https://poser.pugx.org/hakito/php-stuzza-eps-banktransfer/license.svg)](https://packagist.org/packages/hakito/php-stuzza-eps-banktransfer) -PHP-Stuzza-EPS-BankTransfer -=========================== +# PHP-Stuzza-EPS-BankTransfer -PHP implementation of the Austrian e-payment standard "eps" (Version 2.5), specified by Stuzza. See http://www.stuzza.at/de/component/k2/item/23-eps-ueberweisung.html or http://www.eps-ueberweisung.at/ +PHP implementation of the Austrian e-payment standard "eps" (Version 2.6), specified by Stuzza. See http://www.stuzza.at/de/component/k2/item/23-eps-ueberweisung.html or http://www.eps-ueberweisung.at/ -Installation ------------- +## Installation Create a copy of these folders in your project: @@ -16,13 +14,12 @@ Create a copy of these folders in your project: * XSD Or use composer: -``` + +```sh composer require hakito/php-stuzza-eps-banktransfer ``` - -Usage ------ +## Usage Look at the following files in the sample folder: @@ -31,21 +28,32 @@ Look at the following files in the sample folder: To run the tests, go to the parent folder of tests and execute: -``` +```sh phpunit ``` -Remarks -------- +## Migration from v1.x -The current implementation does not support XML certificates and signing. Make sure that the -confirmation url is not easily guessable. Think about adding unique security parameters to the -confirmation url for every transaction. +In v2.0 the SoCommunicator uses a common base URL for ApiCalls. This is set per default to +SoCommunicator::LIVE_MODE_URL in the constructor. -Donate ------- +```php +use at\externet\eps_bank_transfer\SoCommunicator; +$soCommunicator = new SoCommunicator(); +// $soCommunicator->BaseUrl == SoCommunicator::LIVE_MODE_URL; +$soCommunicator = new SoCommunicator(true); +// $soCommunicator->BaseUrl == SoCommunicator::TEST_MODE_URL; +// You can also set BaseUrl to a custom endpoint. +``` + +Because of this change the URL parameter has been removed for the functions: + +* TryGetBanksArray +* GetBanksArray +* GetBanks -Any donation is welcome +## Remarks -* PayPal: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=XPWL7H2NG3VVL -* Bitcoin: 1JUBqyAJg5igMABtzy1kRM6CLBmmvw5hmi +The current implementation does not support XML certificates and signing. Make sure that the +confirmation url is not easily guessable. Think about adding unique security parameters to the +confirmation url for every transaction. diff --git a/composer.json b/composer.json index f1704ea..c6b0c65 100644 --- a/composer.json +++ b/composer.json @@ -24,5 +24,5 @@ "psr-4": { "at\\externet\\eps_bank_transfer\\": "src/" } - } -} + } +} \ No newline at end of file diff --git a/samples/eps_start.php b/samples/eps_start.php index 5534d37..cba55b2 100644 --- a/samples/eps_start.php +++ b/samples/eps_start.php @@ -2,12 +2,11 @@ require_once('../vendor/autoloader.php'); use at\externet\eps_bank_transfer; -// Connection credentials. Override them for test mode. +// Connection credentials. Override them for test mode. $userID = 'AKLJS231534'; // Eps "Händler-ID"/UserID = epsp:UserId $pin = 'topSecret'; // Secret for authentication / PIN = part of epsp:MD5Fingerprint $bic = 'GAWIATW1XXX'; // BIC code of receiving bank account = epi:BfiBicIdentifier $iban = 'AT611904300234573201'; // IBAN code of receiving bank account = epi:BeneficiaryAccountIdentifier -$targetUrl = null; // Target URL to send TransferInitiatorDetails to. 'null' means: Use default URL. For test mode, insert: https://routing.eps.or.at/appl/epsSO-test/transinit/eps/v2_6 // Return urls $transferMsgDetails = new eps_bank_transfer\TransferMsgDetails( @@ -43,10 +42,20 @@ $transferInitiatorDetails->WebshopArticles[] = $article; // Send TransferInitiatorDetails to Scheme Operator -$soCommunicator = new eps_bank_transfer\SoCommunicator(); +$testMode = true; // To use live mode call the SoCommunicator constructor with $testMode = false +$soCommunicator = new eps_bank_transfer\SoCommunicator($testMode); + +// Optional: You can provide a bank selection on your payment site +// $bankList = $soCommunicator->GetBanksArray(); // Alternative: TryGetBanksArray + +// Optional: You can override the default URLs for test and live mode and specify your custom base URL +// $soCommunicator->BaseUrl = 'http://examplel.com/My/Eps/Test/Environment'; + +// Send transfer initiator details to default URL +$plain = $soCommunicator->SendTransferInitiatorDetails($transferInitiatorDetails); +// Optional: When using a preselected bank you can provide this URL as second parameter +// $plain = $soCommunicator->SendTransferInitiatorDetails($transferInitiatorDetails, $epsUrlFromGetBanksArray); -// Send transfer initiator details to $targetUrl -$plain = $soCommunicator->SendTransferInitiatorDetails($transferInitiatorDetails, $targetUrl); $xml = new \SimpleXMLElement($plain); $soAnswer = $xml->children(eps_bank_transfer\XMLNS_epsp); $errorDetails = $soAnswer->BankResponseDetails->ErrorDetails; diff --git a/src/SoCommunicator.php b/src/SoCommunicator.php index 3047d6f..8af0bec 100644 --- a/src/SoCommunicator.php +++ b/src/SoCommunicator.php @@ -7,6 +7,8 @@ */ class SoCommunicator { + const TEST_MODE_URL = 'https://routing.eps.or.at/appl/epsSO-test'; + const LIVE_MODE_URL = 'https://routing.eps.or.at/appl/epsSO'; /** * Optional function to send log messages to @@ -34,16 +36,30 @@ class SoCommunicator */ public $ObscuritySeed; + /** + * The base url SoCommunicator sends requests to + * Defaults to SoCommunicator::LIVE_MODE_URL when constructor is called with $testMode == false + * Defaults to SoCommunicator::TEST_MODE_URL when constructor is called with $testMode == true + */ + public $BaseUrl; + + /** + * Creates new Instance of SoCommunicator + */ + public function __construct($testMode = false) + { + $this->BaseUrl = $testMode ? self::TEST_MODE_URL : self::LIVE_MODE_URL; + } + /** * Failsafe version of GetBanksArray(). All Exceptions will be swallowed - * @param string $url Scheme operator URL for the banks list * @return null or result of GetBanksArray() */ - public function TryGetBanksArray($url = null) + public function TryGetBanksArray() { try { - return $this->GetBanksArray($url); + return $this->GetBanksArray(); } catch (\Exception $e) { @@ -55,13 +71,12 @@ public function TryGetBanksArray($url = null) /** * Get associative array of banks from Scheme Operator. The bank name (bezeichnung) * will be used as key. - * @param string $url Scheme operator URL for the banks list * @throws XmlValidationException when the returned BankList does not validate against XSD - * @return array of banks + * @return array of banks with bank name as key. The values are arrays with: bic, bezeichnung, land, epsUrl */ - public function GetBanksArray($url = null) + public function GetBanksArray() { - $xmlBanks = new \SimpleXMLElement($this->GetBanks(true, $url)); + $xmlBanks = new \SimpleXMLElement($this->GetBanks(true)); $banks = array(); foreach ($xmlBanks as $xmlBank) { @@ -80,15 +95,12 @@ public function GetBanksArray($url = null) * Get XML of banks from scheme operator. * Will throw an exception if data cannot be fetched, or XSD validation fails. * @param bool $validateXml validate against XSD - * @param string $url Scheme operator URL for the banks list * @throws XmlValidationException when the returned BankList does not validate against XSD and $validateXSD is set to TRUE * @return string */ - public function GetBanks($validateXml = true, $url = null) + public function GetBanks($validateXml = true) { - if ($url == null) - $url = 'https://routing.eps.or.at/appl/epsSO/data/haendler/v2_6'; - + $url = $this->BaseUrl . '/data/haendler/v2_6'; $body = $this->GetUrl($url, 'Requesting bank list'); if ($validateXml) @@ -112,8 +124,8 @@ public function SendTransferInitiatorDetails($transferInitiatorDetails, $targetU if ($transferInitiatorDetails->UnstructuredRemittanceIdentifier != null) $transferInitiatorDetails->UnstructuredRemittanceIdentifier = $this->AppendHash($transferInitiatorDetails->UnstructuredRemittanceIdentifier); - if ($targetUrl == null) - $targetUrl = 'https://routing.eps.or.at/appl/epsSO/transinit/eps/v2_6'; + if ($targetUrl === null) + $targetUrl = $this->BaseUrl . '/transinit/eps/v2_6'; $data = $transferInitiatorDetails->GetSimpleXml(); $xmlData = $data->asXML(); diff --git a/tests/unit/at/externet/eps_bank_transfer/SoCommunicatorTest.php b/tests/unit/at/externet/eps_bank_transfer/SoCommunicatorTest.php index ceccbb0..8e9de17 100644 --- a/tests/unit/at/externet/eps_bank_transfer/SoCommunicatorTest.php +++ b/tests/unit/at/externet/eps_bank_transfer/SoCommunicatorTest.php @@ -104,6 +104,34 @@ public function testSendTransferInitiatorDetailsToCorrectUrl() $this->assertEquals('https://routing.eps.or.at/appl/epsSO/transinit/eps/v2_6', $this->mTransport->lastUrl); } + public function testSendTransferInitiatorDetailsToTestUrl() + { + $this->target = new SoCommunicator(true); + $this->target->Transport = $this->mTransport; + $transferInitiatorDetails = $this->getMockedTransferInitiatorDetails(); + $this->mTransport->body = $this->GetEpsData('BankResponseDetails004.xml'); + + $this->target->SendTransferInitiatorDetails($transferInitiatorDetails); + + $this->assertEquals('https://routing.eps.or.at/appl/epsSO-test/transinit/eps/v2_6', $this->mTransport->lastUrl); + } + + public function testOverrideDefaultBaseUrl() + { + $this->target->BaseUrl = 'http://example.com'; + + $this->mTransport->body = $this->GetEpsData('BankListSample.xml'); + $this->target->GetBanksArray(); + $this->assertEquals('http://example.com/data/haendler/v2_6', $this->mTransport->lastUrl); + + $transferInitiatorDetails = $this->getMockedTransferInitiatorDetails(); + $this->mTransport->body = $this->GetEpsData('BankResponseDetails004.xml'); + + $this->target->SendTransferInitiatorDetails($transferInitiatorDetails); + $this->assertEquals('http://example.com/transinit/eps/v2_6', $this->mTransport->lastUrl); + + } + public function testSendTransferInitiatorDetailsThrowsExceptionOn404() { $transferInitiatorDetails = $this->getMockedTransferInitiatorDetails();