Skip to content

Commit

Permalink
Breaking: Remove url argument for *GetBanks*
Browse files Browse the repository at this point in the history
+ SoCommunicator::BaseUrl
+ SoCommunicator constructor with test mode flag
  • Loading branch information
hakito committed Jun 20, 2020
1 parent 88efdd8 commit eba9968
Show file tree
Hide file tree
Showing 5 changed files with 98 additions and 41 deletions.
48 changes: 28 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
@@ -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:

Expand All @@ -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:

Expand All @@ -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.
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,5 @@
"psr-4": {
"at\\externet\\eps_bank_transfer\\": "src/"
}
}
}
}
}
19 changes: 14 additions & 5 deletions samples/eps_start.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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;
Expand Down
40 changes: 26 additions & 14 deletions src/SoCommunicator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
{
Expand All @@ -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)
{
Expand All @@ -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)
Expand All @@ -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();
Expand Down
28 changes: 28 additions & 0 deletions tests/unit/at/externet/eps_bank_transfer/SoCommunicatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit eba9968

Please sign in to comment.