Skip to content

Commit

Permalink
Merge origin/master
Browse files Browse the repository at this point in the history
  • Loading branch information
nemiah committed Oct 8, 2019
2 parents 93dc123 + a9a13c6 commit 4960ce2
Show file tree
Hide file tree
Showing 9 changed files with 660 additions and 572 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
language: php
install: composer install
script:
- ./disallowtabs.sh
- ./phplint.sh ./lib/
- ./vendor/bin/phpunit
php:
Expand Down
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,22 @@ A PHP library implementing the following functions of the FinTS/HBCI protocol:
* Execute direct debit
* Execute transfer

Forked from https://github.com/mschindler83/fints-hbci-php
Forked from [mschindler83/fints-hbci-php](https://github.com/mschindler83/fints-hbci-php)

## Getting Started

Install via composer:

   composer require nemiah/php-fints

```
composer require nemiah/php-fints
```

## Usage

See the examples in the "Samples" folder.<br>
Fill out the required configuration and execute the file.
Before using this library, you have to register your software with [Die Deutsche Kreditwirtschaft](https://www.hbci-zka.de/register/hersteller.htm) in order to get your registration number.
See the examples in the "[Samples](/Samples)" folder. Fill out the required configuration and execute the file.

Server details can be obtained here after registration:
https://www.hbci-zka.de
Server details can be obtained at [www.hbci-zka.de](https://www.hbci-zka.de) after registration.

## Special usage

Expand Down
37 changes: 37 additions & 0 deletions disallowtabs.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!/bin/bash
#
# When this is run as part of a Travis test for a pull request, then it ensures that none of the added lines (compared
# to the base branch of the pull request) use tabs for indentations.
# Adapted from https://github.com/mrc/git-hook-library/blob/master/pre-commit.no-tabs

# Abort if any of the inner commands (particularly the git commands) fails.
set -e
set -o pipefail

if [ -z ${TRAVIS_PULL_REQUEST} ]; then
echo "Expected environment variable TRAVIS_PULL_REQUEST"
exit 2
elif [ "${TRAVIS_PULL_REQUEST}" == "false" ]; then
echo "Not a Travis pull request, skipping."
exit 0
fi

# Make sure that we have a local copy of the relevant commits (otherwise git diff won't work).
git remote set-branches --add origin ${TRAVIS_BRNACH}
git fetch

# Compute the diff from the PR's target branch to its HEAD commit.
target_branch="origin/${TRAVIS_BRANCH}"
the_diff=$(git diff "${target_branch}...HEAD")

# Make sure that there are no tabs in the indentation part of added lines.
if echo "${the_diff}" | egrep '^\+\s* ' >/dev/null; then
echo -e "\e[31mError: The changes contain a tab for indentation\e[0m, which is against this repo's policy."
echo "Target branch: origin/${TRAVIS_BRANCH}"
echo "Commit range: ${TRAVIS_COMMIT_RANGE}"
echo "The following tabs were detected:"
echo "${the_diff}" | egrep '^(\+\s* |\+\+\+|@@)'
exit 1
else
echo "No new tabs detected."
fi
10 changes: 4 additions & 6 deletions lib/Fhp/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,13 @@
namespace Fhp;

use Fhp\Message\AbstractMessage;
use Fhp\CurlException;

/**
* Class Connection
* @package Fhp
*/
class Connection
{

/**
* @var string
*/
Expand Down Expand Up @@ -54,12 +53,11 @@ public function __construct($host, $port, $timeoutConnect = 15, $timeoutResponse
{
if (!is_integer($port) || (int) $port <= 0)
throw new CurlException('Invalid port number');


$this->host = (string) $host;
$this->port = (int) $port;
$this->timeoutConnect = (int) $timeoutConnect;
$this->timeResponse = (int) $timeoutResponse;
$this->timeoutResponse = (int) $timeoutResponse;

#$this->adapter = new Curl($server, $port, $timeout);
}
Expand All @@ -76,7 +74,6 @@ public function send(AbstractMessage $message)
return $this->sendCurl($message);
}


public function getCurlHandle(){
return $this->curlHandle;
}
Expand All @@ -95,7 +92,7 @@ private function connect(){
curl_setopt($this->curlHandle, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
curl_setopt($this->curlHandle, CURLOPT_ENCODING, '');
curl_setopt($this->curlHandle, CURLOPT_MAXREDIRS, 0);
curl_setopt($this->curlHandle, CURLOPT_TIMEOUT, $this->timeResponse);
curl_setopt($this->curlHandle, CURLOPT_TIMEOUT, $this->timeoutResponse);
curl_setopt($this->curlHandle, CURLOPT_HTTPHEADER, array("cache-control: no-cache", 'Content-Type: text/plain'));
}

Expand All @@ -105,6 +102,7 @@ private function connect(){
* @throws CurlException
*/
public function sendCurl(AbstractMessage $message) {

if(!$this->curlHandle)
$this->connect();

Expand Down
2 changes: 2 additions & 0 deletions lib/Fhp/Dialog/Dialog.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,8 @@ public function __construct(
$this->logger = $logger;
$this->productName = $productName;
$this->productVersion = $productVersion;

$this->logger->debug('New Dialog constructed');
}

/**
Expand Down
71 changes: 68 additions & 3 deletions lib/Fhp/FinTs.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class FinTs extends FinTsInternal
/** @var int */
protected $tanMechanism;
/** @var Dialog */
protected $dialog;
protected $dialog = null;
/** @var string */
protected $productName;
/** @var string */
Expand Down Expand Up @@ -144,6 +144,8 @@ public function setTimeouts($connect, $response)
*/
public function getAccounts(\Closure $tanCallback = null)
{
$this->logger->debug(__CLASS__ . ':' . __FUNCTION__ . ' called');

$dialog = $this->getDialog(false);
$dialog->syncDialog($this->tanMechanism, $this->tanMediaName);
$dialog->endDialog();
Expand Down Expand Up @@ -173,6 +175,8 @@ public function getAccounts(\Closure $tanCallback = null)

public function finishAccounts(Response $response, $tan = null)
{
$this->logger->debug(__CLASS__ . ':' . __FUNCTION__ . ' called');

$dialog = $response->getDialog();
$this->dialog = $dialog;

Expand Down Expand Up @@ -207,6 +211,8 @@ public function finishAccounts(Response $response, $tan = null)
*/
public function getSEPAAccounts(\Closure $tanCallback = null)
{
$this->logger->debug(__CLASS__ . ':' . __FUNCTION__ . ' called');

$dialog = $this->getDialog(false);#, $this->tanMechanism);
#$dialog->endDialog(); //probably not required
$dialog->syncDialog($this->tanMechanism, $this->tanMediaName);
Expand All @@ -232,6 +238,8 @@ public function getSEPAAccounts(\Closure $tanCallback = null)

public function getVariables()
{
$this->logger->debug(__CLASS__ . ':' . __FUNCTION__ . ' called');

$dialog = $this->getDialog(false);
$response = $dialog->syncDialog();
// $this->end();
Expand All @@ -242,6 +250,8 @@ public function getVariables()

public function getTANRequest()
{
$this->logger->debug(__CLASS__ . ':' . __FUNCTION__ . ' called');

$dialog = $this->getDialog(false);
$response = $dialog->syncDialog();
if ($response->isTANRequest()) {
Expand Down Expand Up @@ -288,14 +298,16 @@ public function getBankName()
*/
public function getStatementOfAccount(SEPAAccount $account, \DateTime $from, \DateTime $to, \Closure $tanCallback = null, $interval = 1)
{
$this->logger->debug(__CLASS__ . ':' . __FUNCTION__ . ' called');

$this->logger->info('');
$this->logger->info('HKKAZ (statement of accounts) initialize');
$this->logger->info('Start date: ' . $from->format('Y-m-d'));
$this->logger->info('End date : ' . $to->format('Y-m-d'));

$dialog = $this->getDialog();
#$dialog->syncDialog();
#$dialog->initDialog();
#$dialog->syncDialog();
#$dialog->initDialog();

$message = $this->createStateOfAccountMessage($dialog, $account, $from, $to, null);
$response = $dialog->sendMessage($message, $this->getUsedPinTanMechanism($dialog), $tanCallback, $interval);
Expand All @@ -309,6 +321,8 @@ public function getStatementOfAccount(SEPAAccount $account, \DateTime $from, \Da

public function finishStatementOfAccount(Response $response, SEPAAccount $account, \DateTime $from, \DateTime $to, $tan = null)
{
$this->logger->debug(__CLASS__ . ':' . __FUNCTION__ . ' called');

$dialog = $response->getDialog();
$this->dialog = $dialog;

Expand Down Expand Up @@ -378,6 +392,8 @@ public function finishStatementOfAccount(Response $response, SEPAAccount $accoun
*/
public function getBankToCustomerAccountReportAsRawXML(SEPAAccount $account, \DateTime $from, \DateTime $to)
{
$this->logger->debug(__CLASS__ . ':' . __FUNCTION__ . ' called');

$responses = [];

$this->logger->info('');
Expand Down Expand Up @@ -426,6 +442,8 @@ public function getBankToCustomerAccountReportAsRawXML(SEPAAccount $account, \Da
*/
public function getSaldo(SEPAAccount $account)
{
$this->logger->debug(__CLASS__ . ':' . __FUNCTION__ . ' called');

$dialog = $this->getDialog();
#$dialog->syncDialog();
#$dialog->initDialog();
Expand Down Expand Up @@ -493,6 +511,8 @@ public function getSaldo(SEPAAccount $account)

public function finishSEPATAN(GetTANRequest $tanRequest, $tan)
{
$this->logger->debug(__CLASS__ . ':' . __FUNCTION__ . ' called');

if ($tan == '') {
throw new TANException('No TAN received!');
}
Expand All @@ -513,6 +533,8 @@ public function finishSEPATAN(GetTANRequest $tanRequest, $tan)
*/
public function executeSEPATransfer(SEPAAccount $account, $painMessage, \Closure $tanCallback = null)
{
$this->logger->debug(__CLASS__ . ':' . __FUNCTION__ . ' called');

$response = $this->startSEPATransfer($account, $painMessage);

if ($tanCallback === null) {
Expand All @@ -537,6 +559,8 @@ public function executeSEPATransfer(SEPAAccount $account, $painMessage, \Closure

public function executeSEPADirectDebit(SEPAAccount $account, $painMessage, \Closure $tanCallback, $interval = 1)
{
$this->logger->debug(__CLASS__ . ':' . __FUNCTION__ . ' called');

$painMessage = $this->clearXML($painMessage);


Expand Down Expand Up @@ -616,6 +640,8 @@ public function executeSEPADirectDebit(SEPAAccount $account, $painMessage, \Clos
*/
public function deleteSEPAStandingOrder(SEPAAccount $account, SEPAStandingOrder $order, \Closure $tanCallback = null)
{
$this->logger->debug(__CLASS__ . ':' . __FUNCTION__ . ' called');

$response = $this->startDeleteSEPAStandingOrder($account, $order);

if ($tanCallback === null) {
Expand All @@ -640,6 +666,8 @@ public function deleteSEPAStandingOrder(SEPAAccount $account, SEPAStandingOrder

public function getSEPAStandingOrders(SEPAAccount $account)
{
$this->logger->debug(__CLASS__ . ':' . __FUNCTION__ . ' called');

$dialog = $this->getDialog();
#$dialog->syncDialog(false);
#$dialog->initDialog();
Expand Down Expand Up @@ -678,4 +706,41 @@ public function getSEPAStandingOrders(SEPAAccount $account)

return $response->getSEPAStandingOrdersArray();
}

/**
* Retrieve a pre configured dialog object.
*
* @param boolean
* @return Dialog
* @throws \Exception
*/
protected function getDialog($sync = true)
{
if ($this->dialog !== null) {
return $this->dialog;
}

if ($this->connection === null) {
$this->connection = new Connection($this->url, $this->port, $this->timeoutConnect, $this->timeoutResponse);
}

$dialog = new Dialog(
$this->connection,
$this->bankCode,
$this->username,
$this->pin,
$this->systemId,
$this->logger,
$this->productName,
$this->productVersion
);

if ($sync) {
$dialog->syncDialog();
}

$this->dialog = $dialog;

return $this->dialog;
}
}
Loading

0 comments on commit 4960ce2

Please sign in to comment.