dolibarr.bankimport/vendor/nemiah/php-fints/lib/Fhp/Action/GetSEPAAccounts.php
data 014a943f78 feat: HKEKA-Implementierung, PDF-Bugfixes, Sortierung, Umsatz-Umbenennung
- HKEKA v3/v4/v5 Segmente fuer phpFinTS implementiert (VR Bank unterstuetzt kein HKEKP)
- GetElectronicStatement Action mit Base64-Erkennung und Quittungscode
- PDF-Deduplizierung per MD5 (Bank sendet identische Saldenmitteilungen)
- Saldenmitteilungen ohne Auszugsnummer werden uebersprungen
- Datums-Validierung: 30.02. (Bank-Konvention) wird auf 28.02. korrigiert
- Numerische Sortierung fuer statement_number (CAST statt String-Sort)
- Jahr-Filter: statement_year=0 ausgeschlossen
- Menue/Button: "Kontoauszuege" -> "Umsaetze" (statements.php zeigt MT940, nicht PDFs)
- Redirect nach FinTS-Abruf auf aktuelles Jahr statt year=0

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-06 07:10:59 +01:00

92 lines
2.8 KiB
PHP
Executable file

<?php
namespace Fhp\Action;
use Fhp\Model\SEPAAccount;
use Fhp\PaginateableAction;
use Fhp\Protocol\BPD;
use Fhp\Protocol\Message;
use Fhp\Protocol\UPD;
use Fhp\Segment\BaseSegment;
use Fhp\Segment\Common\Ktz;
use Fhp\Segment\HIRMS\Rueckmeldungscode;
use Fhp\Segment\SPA\HISPA;
use Fhp\Segment\SPA\HKSPAv1;
use Fhp\Segment\SPA\HKSPAv2;
use Fhp\Segment\SPA\HKSPAv3;
use Fhp\UnsupportedException;
/**
* Runs an HKSPA request to retrieve account details about the accounts that the user can access through FinTs.
*
* TODO In future, once all banks populate the BIC in HIUPD.erweiterungKontobezogen, or if we force library users to
* supply the BIC to us, we won't need to send an HKSPA anymore, but we can simply fulfil this action from the UPD.
*/
class GetSEPAAccounts extends PaginateableAction
{
// Empty request, in order to retrieve all accounts.
// Response
/** @var SEPAAccount[] */
private $accounts;
/**
* @return GetSEPAAccounts A new action instance.
*/
public static function create(): GetSEPAAccounts
{
return new GetSEPAAccounts();
}
/**
* @return SEPAAccount[]
*/
public function getAccounts(): array
{
$this->ensureDone();
return $this->accounts;
}
/** {@inheritdoc} */
protected function createRequest(BPD $bpd, ?UPD $upd)
{
/** @var BaseSegment $hispas */
$hispas = $bpd->requireLatestSupportedParameters('HISPAS');
switch ($hispas->getVersion()) {
case 1:
return HKSPAv1::createEmpty();
case 2:
return HKSPAv2::createEmpty();
case 3:
return HKSPAv3::createEmpty();
default:
throw new UnsupportedException('Unsupported HKSPA version: ' . $hispas->getVersion());
}
}
/** {@inheritdoc} */
public function processResponse(Message $response)
{
parent::processResponse($response);
// Banks send just 3010 and no HISPA in case there are no accounts (or at least none that the bank is able to
// report through HISPA).
if ($response->findRueckmeldung(Rueckmeldungscode::NICHT_VERFUEGBAR) !== null) {
$this->accounts = [];
return;
}
/** @var HISPA $hispa */
$hispa = $response->requireSegment(HISPA::class);
$this->accounts = array_map(function ($ktz) {
/** @var Ktz $ktz */
$account = new SEPAAccount();
$account->setIban($ktz->iban);
$account->setBic($ktz->bic);
$account->setAccountNumber($ktz->kontonummer);
$account->setSubAccount($ktz->unterkontomerkmal);
$account->setBlz($ktz->kreditinstitutskennung->kreditinstitutscode);
return $account;
}, $hispa->getSepaKontoverbindung());
}
}