From a8c5c121ab0fc79ba50fb9bcf4de6542f04c1132 Mon Sep 17 00:00:00 2001 From: Norbert Huemmer Date: Fri, 12 Jun 2020 20:28:41 +0200 Subject: [PATCH 1/2] Added B2B support for SEPADirectDebit --- .../Action/GetSEPADirectDebitParameters.php | 41 +++++++++++-------- lib/Fhp/Action/SendSEPADirectDebit.php | 37 ++++++++--------- .../Model/StatementOfAccount/Transaction.php | 0 lib/Fhp/Segment/BME/HIBMESv1.php | 30 ++++++++++++++ lib/Fhp/Segment/BME/HIBMESv2.php | 30 ++++++++++++++ lib/Fhp/Segment/BME/HKBMEv1.php | 15 +++++++ lib/Fhp/Segment/BME/HKBMEv2.php | 13 ++++++ ...EPAFirmenSammellastschriftEinreichenV1.php | 17 ++++++++ ...EPAFirmenSammellastschriftEinreichenV2.php | 23 +++++++++++ ...ierteSEPASammellastschriftEinreichenV1.php | 17 ++++++++ ...ierteSEPASammellastschriftEinreichenV2.php | 23 +++++++++++ lib/Fhp/Segment/BSE/HIBSESv1.php | 30 ++++++++++++++ lib/Fhp/Segment/BSE/HIBSESv2.php | 30 ++++++++++++++ lib/Fhp/Segment/BSE/HKBSEv1.php | 15 +++++++ lib/Fhp/Segment/BSE/HKBSEv2.php | 13 ++++++ ...EPAFirmenEinzellastschriftEinreichenV1.php | 28 +++++++++++++ ...EPAFirmenEinzellastschriftEinreichenV2.php | 12 ++++++ ...ierteSEPAFirmenLastschriftEinreichenV2.php | 22 ++++++++++ lib/Fhp/Segment/DME/HIDMESv1.php | 8 ++++ lib/Fhp/Segment/DME/HIDMESv2.php | 10 ++++- ...ierteSEPASammellastschriftEinreichenV2.php | 2 + lib/Fhp/Segment/DSE/HIDSESv1.php | 8 +++- lib/Fhp/Segment/DSE/HIDSESv2.php | 10 +++-- lib/Fhp/Segment/{DME => DSE}/HIDXES.php | 5 ++- .../MinimaleVorlaufzeitSEPALastschrift.php | 21 ++++++++-- ...ierteSEPAEinzellastschriftEinreichenV1.php | 2 - ...ierteSEPAEinzellastschriftEinreichenV2.php | 2 - ...TerminierteSEPALastschriftEinreichenV2.php | 2 +- ...SEPADirectDebitMinimalLeadTimeProvider.php | 2 +- 29 files changed, 412 insertions(+), 56 deletions(-) mode change 100755 => 100644 lib/Fhp/Model/StatementOfAccount/Transaction.php create mode 100644 lib/Fhp/Segment/BME/HIBMESv1.php create mode 100644 lib/Fhp/Segment/BME/HIBMESv2.php create mode 100644 lib/Fhp/Segment/BME/HKBMEv1.php create mode 100644 lib/Fhp/Segment/BME/HKBMEv2.php create mode 100644 lib/Fhp/Segment/BME/ParameterTerminierteSEPAFirmenSammellastschriftEinreichenV1.php create mode 100644 lib/Fhp/Segment/BME/ParameterTerminierteSEPAFirmenSammellastschriftEinreichenV2.php create mode 100755 lib/Fhp/Segment/BME/ParameterTerminierteSEPASammellastschriftEinreichenV1.php create mode 100755 lib/Fhp/Segment/BME/ParameterTerminierteSEPASammellastschriftEinreichenV2.php create mode 100644 lib/Fhp/Segment/BSE/HIBSESv1.php create mode 100644 lib/Fhp/Segment/BSE/HIBSESv2.php create mode 100644 lib/Fhp/Segment/BSE/HKBSEv1.php create mode 100644 lib/Fhp/Segment/BSE/HKBSEv2.php create mode 100644 lib/Fhp/Segment/BSE/ParameterTerminierteSEPAFirmenEinzellastschriftEinreichenV1.php create mode 100644 lib/Fhp/Segment/BSE/ParameterTerminierteSEPAFirmenEinzellastschriftEinreichenV2.php create mode 100755 lib/Fhp/Segment/BSE/ParameterTerminierteSEPAFirmenLastschriftEinreichenV2.php rename lib/Fhp/Segment/{DME => DSE}/HIDXES.php (51%) rename lib/Fhp/Segment/{DME => DSE}/MinimaleVorlaufzeitSEPALastschrift.php (73%) rename lib/Fhp/Segment/{DME => DSE}/ParameterTerminierteSEPALastschriftEinreichenV2.php (95%) mode change 100644 => 100755 rename lib/Fhp/Segment/{DME => DSE}/SEPADirectDebitMinimalLeadTimeProvider.php (87%) diff --git a/lib/Fhp/Action/GetSEPADirectDebitParameters.php b/lib/Fhp/Action/GetSEPADirectDebitParameters.php index a1c2f1e0..386204d7 100644 --- a/lib/Fhp/Action/GetSEPADirectDebitParameters.php +++ b/lib/Fhp/Action/GetSEPADirectDebitParameters.php @@ -5,8 +5,8 @@ use Fhp\BaseAction; use Fhp\Protocol\BPD; use Fhp\Protocol\UPD; -use Fhp\Segment\DME\HIDXES; -use Fhp\Segment\DME\MinimaleVorlaufzeitSEPALastschrift; +use Fhp\Segment\DSE\HIDXES; +use Fhp\Segment\DSE\MinimaleVorlaufzeitSEPALastschrift; /** * Retrieves information about SEPA Direct Debit Requests @@ -14,7 +14,7 @@ class GetSEPADirectDebitParameters extends BaseAction { const SEQUENCE_TYPES = ['FRST', 'OOFF', 'FNAL', 'RCUR']; - const CORE_TYPES = ['CORE', 'COR1']; + const CORE_TYPES = ['CORE', 'COR1', 'B2B']; /** @var string */ private $coreType; @@ -25,8 +25,8 @@ class GetSEPADirectDebitParameters extends BaseAction /** @var bool */ private $singleDirectDebit; - /** @var MinimaleVorlaufzeitSEPALastschrift|null */ - private $minimalLeadTime; + /** @var HIDXES */ + private $hidxes; public static function create(string $seqType, bool $singleDirectDebit, string $coreType = 'CORE') { @@ -40,24 +40,30 @@ public static function create(string $seqType, bool $singleDirectDebit, string $ $result->coreType = $coreType; $result->seqType = $seqType; $result->singleDirectDebit = $singleDirectDebit; - return $result; } + public static function getHixxesSegmentName(string $coreType, bool $singleDirectDebit): string + { + switch ($coreType) { + case 'CORE': + case 'COR1': + return $singleDirectDebit ? 'HIDSES' : 'HIDMES'; + case 'B2B': + return $singleDirectDebit ? 'HIBSES' : 'HIBMES'; + default: + throw new \InvalidArgumentException('Unknown CORE type, possible values are ' . implode(', ', self::CORE_TYPES)); + } + } + /** {@inheritdoc} */ protected function createRequest(BPD $bpd, ?UPD $upd) { - $type = $this->singleDirectDebit ? 'HIDSES' : 'HIDMES'; - - /** @var HIDXES $hidxes */ - $hidxes = $bpd->requireLatestSupportedParameters($type); - - $this->minimalLeadTime = $hidxes->getParameter()->getMinimalLeadTime($this->seqType, $this->coreType); - + $this->hidxes = $bpd->requireLatestSupportedParameters(static::getHixxesSegmentName($this->coreType, $this->singleDirectDebit)); + $this->isDone = true; - - // No request to the bank required - return []; + + return []; // No request to the bank required } /** @@ -65,7 +71,6 @@ protected function createRequest(BPD $bpd, ?UPD $upd) */ public function getMinimalLeadTime(): ?MinimaleVorlaufzeitSEPALastschrift { - //$this->ensureDone(); - return $this->minimalLeadTime; + return $this->hidxes->getParameter()->getMinimalLeadTime($this->seqType, $this->coreType); } } diff --git a/lib/Fhp/Action/SendSEPADirectDebit.php b/lib/Fhp/Action/SendSEPADirectDebit.php index f78224c9..d47bc720 100644 --- a/lib/Fhp/Action/SendSEPADirectDebit.php +++ b/lib/Fhp/Action/SendSEPADirectDebit.php @@ -11,12 +11,8 @@ use Fhp\Segment\Common\Kti; use Fhp\Segment\DME\HIDMESv1; use Fhp\Segment\DME\HIDMESv2; -use Fhp\Segment\DME\HIDXES; -use Fhp\Segment\DME\HKDMEv1; -use Fhp\Segment\DME\HKDMEv2; use Fhp\Segment\DSE\HIDSESv2; -use Fhp\Segment\DSE\HKDSEv1; -use Fhp\Segment\DSE\HKDSEv2; +use Fhp\Segment\DSE\HIDXES; use Fhp\Segment\SPA\HISPAS; use Fhp\Syntax\Bin; use Fhp\UnsupportedException; @@ -44,6 +40,9 @@ class SendSEPADirectDebit extends BaseAction /** @var bool */ protected $tryToUseControlSumForSingleTransactions = false; + /** @var string */ + private $coreType; + public static function create(SEPAAccount $account, string $painMessage, bool $tryToUseControlSumForSingleTransactions = false): SendSEPADirectDebit { if (preg_match('/xmlns="(?[^"]+)"/s', $painMessage, $matches) === 1) { @@ -56,10 +55,16 @@ public static function create(SEPAAccount $account, string $painMessage, bool $t $nbOfTxs = substr_count($painMessage, ''); $ctrlSum = null; - if (preg_match('/.*(?[.0-9]+)<\/CtrlSum>.*<\/GrpHdr>/s', $painMessage, $matches) === 1) { + if (preg_match('@.*(?[.0-9]+).*@s', $painMessage, $matches) === 1) { $ctrlSum = $matches['ctrlsum']; } + if (preg_match('@.*.*(?CORE|COR1|B2B).*.*@s', $painMessage, $matches) === 1) { + $coreType = $matches['coretype']; + } else { + throw new \InvalidArgumentException('The type CORE/COR1/B2B is missing in PAIN message'); + } + if ($nbOfTxs > 1 && is_null($ctrlSum)) { throw new \InvalidArgumentException('The control sum aka "xx" is missing in PAIN message'); } @@ -69,6 +74,7 @@ public static function create(SEPAAccount $account, string $painMessage, bool $t $result->painMessage = $painMessage; $result->painNamespace = $painNamespace; $result->ctrlSum = $ctrlSum; + $result->coreType = $coreType; $result->singleDirectDebit = $nbOfTxs === 1; @@ -86,8 +92,8 @@ protected function createRequest(BPD $bpd, ?UPD $upd) $useSingleDirectDebit = false; } - /** @var HIDXES|BaseSegment $hidxes */ - $hidxes = $bpd->requireLatestSupportedParameters($useSingleDirectDebit ? 'HIDSES' : 'HIDMES'); + /* @var HIDXES|BaseSegment $hidxes */ + $hidxes = $bpd->requireLatestSupportedParameters(GetSEPADirectDebitParameters::getHixxesSegmentName($this->coreType, $useSingleDirectDebit)); $supportedPainNamespaces = null; @@ -108,19 +114,8 @@ protected function createRequest(BPD $bpd, ?UPD $upd) . implode(', ', $supportedPainNamespaces)); } - /** @var HKDMEv1|HKDSEv1 $hkdxe */ - $hkdxe = null; - switch ($hidxes->getVersion()) { - case 1: - $hkdxe = $useSingleDirectDebit ? HKDSEv1::createEmpty() : HKDMEv1::createEmpty(); - break; - case 2: - $hkdxe = $useSingleDirectDebit ? HKDSEv2::createEmpty() : HKDMEv2::createEmpty(); - break; - default: - throw new UnsupportedException('Unsupported HKDME or HKDSE version: ' . $hidxes->getVersion()); - } - + /** @var mixed $hkdxe */ // TODO Put a new interface type here. + $hkdxe = $hidxes->createRequestSegment(); $hkdxe->kontoverbindungInternational = Kti::fromAccount($this->account); $hkdxe->sepaDescriptor = $this->painNamespace; $hkdxe->sepaPainMessage = new Bin($this->painMessage); diff --git a/lib/Fhp/Model/StatementOfAccount/Transaction.php b/lib/Fhp/Model/StatementOfAccount/Transaction.php old mode 100755 new mode 100644 diff --git a/lib/Fhp/Segment/BME/HIBMESv1.php b/lib/Fhp/Segment/BME/HIBMESv1.php new file mode 100644 index 00000000..bb9cec34 --- /dev/null +++ b/lib/Fhp/Segment/BME/HIBMESv1.php @@ -0,0 +1,30 @@ +parameter; + } + + public function createRequestSegment(): BaseSegment + { + return HKBMEv1::createEmpty(); + } +} diff --git a/lib/Fhp/Segment/BME/HIBMESv2.php b/lib/Fhp/Segment/BME/HIBMESv2.php new file mode 100644 index 00000000..6d73b0ef --- /dev/null +++ b/lib/Fhp/Segment/BME/HIBMESv2.php @@ -0,0 +1,30 @@ +parameter; + } + + public function createRequestSegment(): BaseSegment + { + return HKBMEv2::createEmpty(); + } +} diff --git a/lib/Fhp/Segment/BME/HKBMEv1.php b/lib/Fhp/Segment/BME/HKBMEv1.php new file mode 100644 index 00000000..7139d5a0 --- /dev/null +++ b/lib/Fhp/Segment/BME/HKBMEv1.php @@ -0,0 +1,15 @@ +parameter; + } + + public function createRequestSegment(): BaseSegment + { + return HKBSEv1::createEmpty(); + } +} diff --git a/lib/Fhp/Segment/BSE/HIBSESv2.php b/lib/Fhp/Segment/BSE/HIBSESv2.php new file mode 100644 index 00000000..4ca4ceed --- /dev/null +++ b/lib/Fhp/Segment/BSE/HIBSESv2.php @@ -0,0 +1,30 @@ +parameter; + } + + public function createRequestSegment(): BaseSegment + { + return HKBSEv2::createEmpty(); + } +} diff --git a/lib/Fhp/Segment/BSE/HKBSEv1.php b/lib/Fhp/Segment/BSE/HKBSEv1.php new file mode 100644 index 00000000..9f2be81a --- /dev/null +++ b/lib/Fhp/Segment/BSE/HKBSEv1.php @@ -0,0 +1,15 @@ + 1 */ + public $minimaleVorlaufzeitFNALRCUR; + + /** @var int */ + public $maximaleVorlaufzeitFNALRCUR; + + /** @var int Must be => 1 */ + public $minimaleVorlaufzeitFRSTOOFF; + + /** @var int */ + public $maximaleVorlaufzeitFRSTOOFF; + + public function getMinimalLeadTime(string $seqType, string $coreType = 'B2B'): ?MinimaleVorlaufzeitSEPALastschrift + { + $leadTime = in_array($seqType, ['FRST', 'OOFF']) ? $this->minimaleVorlaufzeitFRSTOOFF : $this->minimaleVorlaufzeitFNALRCUR; + return MinimaleVorlaufzeitSEPALastschrift::create($leadTime, '235959'); + } +} diff --git a/lib/Fhp/Segment/BSE/ParameterTerminierteSEPAFirmenEinzellastschriftEinreichenV2.php b/lib/Fhp/Segment/BSE/ParameterTerminierteSEPAFirmenEinzellastschriftEinreichenV2.php new file mode 100644 index 00000000..3a9ea609 --- /dev/null +++ b/lib/Fhp/Segment/BSE/ParameterTerminierteSEPAFirmenEinzellastschriftEinreichenV2.php @@ -0,0 +1,12 @@ +minimaleVorlaufzeitCodiert); + return $parsed[$seqType] ?? null; + } +} diff --git a/lib/Fhp/Segment/DME/HIDMESv1.php b/lib/Fhp/Segment/DME/HIDMESv1.php index 2738109d..e6ed5aa5 100644 --- a/lib/Fhp/Segment/DME/HIDMESv1.php +++ b/lib/Fhp/Segment/DME/HIDMESv1.php @@ -3,6 +3,9 @@ namespace Fhp\Segment\DME; use Fhp\Segment\BaseGeschaeftsvorfallparameter; +use Fhp\Segment\BaseSegment; +use Fhp\Segment\DSE\HIDXES; +use Fhp\Segment\DSE\SEPADirectDebitMinimalLeadTimeProvider; /** * Segment: Terminierte SEPA-Sammellastschrift einreichen Parameter @@ -19,4 +22,9 @@ public function getParameter(): SEPADirectDebitMinimalLeadTimeProvider { return $this->parameter; } + + public function createRequestSegment(): BaseSegment + { + return HKDMEv1::createEmpty(); + } } diff --git a/lib/Fhp/Segment/DME/HIDMESv2.php b/lib/Fhp/Segment/DME/HIDMESv2.php index dca9633f..4884df40 100644 --- a/lib/Fhp/Segment/DME/HIDMESv2.php +++ b/lib/Fhp/Segment/DME/HIDMESv2.php @@ -3,12 +3,15 @@ namespace Fhp\Segment\DME; use Fhp\Segment\BaseGeschaeftsvorfallparameter; +use Fhp\Segment\BaseSegment; +use Fhp\Segment\DSE\HIDXES; +use Fhp\Segment\DSE\SEPADirectDebitMinimalLeadTimeProvider; /** * Segment: Terminierte SEPA-Sammellastschrift einreichen Parameter * * @link https://www.hbci-zka.de/dokumente/spezifikation_deutsch/fintsv3/FinTS_3.0_Messages_Geschaeftsvorfaelle_2015-08-07_final_version.pdf - * Section: C.10.3.2.2.1 c) + * Section: C.10.3.2.2.2 c) */ class HIDMESv2 extends BaseGeschaeftsvorfallparameter implements HIDXES { @@ -19,4 +22,9 @@ public function getParameter(): SEPADirectDebitMinimalLeadTimeProvider { return $this->parameter; } + + public function createRequestSegment(): BaseSegment + { + return HKDMEv2::createEmpty(); + } } diff --git a/lib/Fhp/Segment/DME/ParameterTerminierteSEPASammellastschriftEinreichenV2.php b/lib/Fhp/Segment/DME/ParameterTerminierteSEPASammellastschriftEinreichenV2.php index 560871c2..b9df30de 100644 --- a/lib/Fhp/Segment/DME/ParameterTerminierteSEPASammellastschriftEinreichenV2.php +++ b/lib/Fhp/Segment/DME/ParameterTerminierteSEPASammellastschriftEinreichenV2.php @@ -2,6 +2,8 @@ namespace Fhp\Segment\DME; +use Fhp\Segment\DSE\ParameterTerminierteSEPALastschriftEinreichenV2; + class ParameterTerminierteSEPASammellastschriftEinreichenV2 extends ParameterTerminierteSEPALastschriftEinreichenV2 { /** @var int */ diff --git a/lib/Fhp/Segment/DSE/HIDSESv1.php b/lib/Fhp/Segment/DSE/HIDSESv1.php index 3772fc2a..e9d97c74 100644 --- a/lib/Fhp/Segment/DSE/HIDSESv1.php +++ b/lib/Fhp/Segment/DSE/HIDSESv1.php @@ -3,8 +3,7 @@ namespace Fhp\Segment\DSE; use Fhp\Segment\BaseGeschaeftsvorfallparameter; -use Fhp\Segment\DME\HIDXES; -use Fhp\Segment\DME\SEPADirectDebitMinimalLeadTimeProvider; +use Fhp\Segment\BaseSegment; /** * Segment: Terminierte SEPA-Einzellastschrift einreichen Parameter @@ -21,4 +20,9 @@ public function getParameter(): SEPADirectDebitMinimalLeadTimeProvider { return $this->parameter; } + + public function createRequestSegment(): BaseSegment + { + return HKDSEv1::createEmpty(); + } } diff --git a/lib/Fhp/Segment/DSE/HIDSESv2.php b/lib/Fhp/Segment/DSE/HIDSESv2.php index 8857ef9a..4ef39e0b 100644 --- a/lib/Fhp/Segment/DSE/HIDSESv2.php +++ b/lib/Fhp/Segment/DSE/HIDSESv2.php @@ -3,14 +3,13 @@ namespace Fhp\Segment\DSE; use Fhp\Segment\BaseGeschaeftsvorfallparameter; -use Fhp\Segment\DME\HIDXES; -use Fhp\Segment\DME\SEPADirectDebitMinimalLeadTimeProvider; +use Fhp\Segment\BaseSegment; /** * Segment: Terminierte SEPA-Einzellastschrift einreichen Parameter * * @link https://www.hbci-zka.de/dokumente/spezifikation_deutsch/fintsv3/FinTS_3.0_Messages_Geschaeftsvorfaelle_2015-08-07_final_version.pdf - * Section: C.10.2.5.4.1 c) + * Section: C.10.2.5.4.2 c) */ class HIDSESv2 extends BaseGeschaeftsvorfallparameter implements HIDXES { @@ -21,4 +20,9 @@ public function getParameter(): SEPADirectDebitMinimalLeadTimeProvider { return $this->parameter; } + + public function createRequestSegment(): BaseSegment + { + return HKDSEv2::createEmpty(); + } } diff --git a/lib/Fhp/Segment/DME/HIDXES.php b/lib/Fhp/Segment/DSE/HIDXES.php similarity index 51% rename from lib/Fhp/Segment/DME/HIDXES.php rename to lib/Fhp/Segment/DSE/HIDXES.php index e3366030..f0fe7571 100644 --- a/lib/Fhp/Segment/DME/HIDXES.php +++ b/lib/Fhp/Segment/DSE/HIDXES.php @@ -1,10 +1,13 @@ unterstuetzteSEPALastschriftartenCodiert = $unterstuetzteSEPALastschriftartenCodiert; @@ -63,4 +63,17 @@ public static function parseCoded(string $coded): array } return $result; } + + /** @return MinimaleVorlaufzeitSEPALastschrift[]|array */ + public static function parseCodedB2B(string $coded): array + { + $result = []; + foreach (array_chunk(explode(';', $coded), 3) as list($sequenceTypeCodiert, $minimaleSEPAVorlaufzeit, $cutOffZeit)) { + $seqTypes = self::SEQUENCE_TYPE_CODIERT[$sequenceTypeCodiert] ?? []; + foreach ($seqTypes as $seqType) { + $result[$seqType] = MinimaleVorlaufzeitSEPALastschrift::create($minimaleSEPAVorlaufzeit, $cutOffZeit, null, $sequenceTypeCodiert); + } + } + return $result; + } } diff --git a/lib/Fhp/Segment/DSE/ParameterTerminierteSEPAEinzellastschriftEinreichenV1.php b/lib/Fhp/Segment/DSE/ParameterTerminierteSEPAEinzellastschriftEinreichenV1.php index 1e02f9cc..e205ad04 100644 --- a/lib/Fhp/Segment/DSE/ParameterTerminierteSEPAEinzellastschriftEinreichenV1.php +++ b/lib/Fhp/Segment/DSE/ParameterTerminierteSEPAEinzellastschriftEinreichenV1.php @@ -3,8 +3,6 @@ namespace Fhp\Segment\DSE; use Fhp\Segment\BaseDeg; -use Fhp\Segment\DME\MinimaleVorlaufzeitSEPALastschrift; -use Fhp\Segment\DME\SEPADirectDebitMinimalLeadTimeProvider; class ParameterTerminierteSEPAEinzellastschriftEinreichenV1 extends BaseDeg implements SEPADirectDebitMinimalLeadTimeProvider { diff --git a/lib/Fhp/Segment/DSE/ParameterTerminierteSEPAEinzellastschriftEinreichenV2.php b/lib/Fhp/Segment/DSE/ParameterTerminierteSEPAEinzellastschriftEinreichenV2.php index 0b413bb9..faf23075 100644 --- a/lib/Fhp/Segment/DSE/ParameterTerminierteSEPAEinzellastschriftEinreichenV2.php +++ b/lib/Fhp/Segment/DSE/ParameterTerminierteSEPAEinzellastschriftEinreichenV2.php @@ -2,8 +2,6 @@ namespace Fhp\Segment\DSE; -use Fhp\Segment\DME\ParameterTerminierteSEPALastschriftEinreichenV2; - class ParameterTerminierteSEPAEinzellastschriftEinreichenV2 extends ParameterTerminierteSEPALastschriftEinreichenV2 { /** @var string|null Max Length: 4096 */ diff --git a/lib/Fhp/Segment/DME/ParameterTerminierteSEPALastschriftEinreichenV2.php b/lib/Fhp/Segment/DSE/ParameterTerminierteSEPALastschriftEinreichenV2.php old mode 100644 new mode 100755 similarity index 95% rename from lib/Fhp/Segment/DME/ParameterTerminierteSEPALastschriftEinreichenV2.php rename to lib/Fhp/Segment/DSE/ParameterTerminierteSEPALastschriftEinreichenV2.php index 72f480a0..66f535b6 --- a/lib/Fhp/Segment/DME/ParameterTerminierteSEPALastschriftEinreichenV2.php +++ b/lib/Fhp/Segment/DSE/ParameterTerminierteSEPALastschriftEinreichenV2.php @@ -1,6 +1,6 @@ Date: Tue, 14 Jul 2020 20:06:32 +0200 Subject: [PATCH 2/2] Optimized code --- .../Action/GetSEPADirectDebitParameters.php | 30 ++++++++++--------- ...ierteSEPASammellastschriftEinreichenV1.php | 17 ----------- ...ierteSEPASammellastschriftEinreichenV2.php | 23 -------------- ...EPAFirmenEinzellastschriftEinreichenV1.php | 2 +- ...ierteSEPAFirmenLastschriftEinreichenV2.php | 8 +++-- .../MinimaleVorlaufzeitSEPALastschrift.php | 4 +-- ...ierteSEPAEinzellastschriftEinreichenV1.php | 2 +- ...TerminierteSEPALastschriftEinreichenV2.php | 7 +++-- ...SEPADirectDebitMinimalLeadTimeProvider.php | 3 +- 9 files changed, 31 insertions(+), 65 deletions(-) delete mode 100755 lib/Fhp/Segment/BME/ParameterTerminierteSEPASammellastschriftEinreichenV1.php delete mode 100755 lib/Fhp/Segment/BME/ParameterTerminierteSEPASammellastschriftEinreichenV2.php diff --git a/lib/Fhp/Action/GetSEPADirectDebitParameters.php b/lib/Fhp/Action/GetSEPADirectDebitParameters.php index 386204d7..c953b504 100644 --- a/lib/Fhp/Action/GetSEPADirectDebitParameters.php +++ b/lib/Fhp/Action/GetSEPADirectDebitParameters.php @@ -14,10 +14,10 @@ class GetSEPADirectDebitParameters extends BaseAction { const SEQUENCE_TYPES = ['FRST', 'OOFF', 'FNAL', 'RCUR']; - const CORE_TYPES = ['CORE', 'COR1', 'B2B']; + const DIRECT_DEBIT_TYPES = ['CORE', 'COR1', 'B2B']; /** @var string */ - private $coreType; + private $directDebitType; /** @var string */ private $seqType; @@ -28,49 +28,51 @@ class GetSEPADirectDebitParameters extends BaseAction /** @var HIDXES */ private $hidxes; - public static function create(string $seqType, bool $singleDirectDebit, string $coreType = 'CORE') + public static function create(string $seqType, bool $singleDirectDebit, string $directDebitType = 'CORE') { - if (!in_array($coreType, self::CORE_TYPES)) { - throw new \InvalidArgumentException('Unknown CORE type, possible values are ' . implode(', ', self::CORE_TYPES)); + if (!in_array($directDebitType, self::DIRECT_DEBIT_TYPES)) { + throw new \InvalidArgumentException('Unknown CORE type, possible values are ' . implode(', ', self::DIRECT_DEBIT_TYPES)); } if (!in_array($seqType, self::SEQUENCE_TYPES)) { throw new \InvalidArgumentException('Unknown SEPA sequence type, possible values are ' . implode(', ', self::SEQUENCE_TYPES)); } $result = new GetSEPADirectDebitParameters(); - $result->coreType = $coreType; + $result->directDebitType = $directDebitType; $result->seqType = $seqType; $result->singleDirectDebit = $singleDirectDebit; return $result; } - public static function getHixxesSegmentName(string $coreType, bool $singleDirectDebit): string + public static function getHixxesSegmentName(string $directDebitType, bool $singleDirectDebit): string { - switch ($coreType) { + switch ($directDebitType) { case 'CORE': case 'COR1': return $singleDirectDebit ? 'HIDSES' : 'HIDMES'; case 'B2B': return $singleDirectDebit ? 'HIBSES' : 'HIBMES'; default: - throw new \InvalidArgumentException('Unknown CORE type, possible values are ' . implode(', ', self::CORE_TYPES)); + throw new \InvalidArgumentException('Unknown DirectDebitTypes type, possible values are ' . implode(', ', self::DIRECT_DEBIT_TYPES)); } } /** {@inheritdoc} */ protected function createRequest(BPD $bpd, ?UPD $upd) { - $this->hidxes = $bpd->requireLatestSupportedParameters(static::getHixxesSegmentName($this->coreType, $this->singleDirectDebit)); - + $this->hidxes = $bpd->requireLatestSupportedParameters(static::getHixxesSegmentName($this->directDebitType, $this->singleDirectDebit)); $this->isDone = true; - return []; // No request to the bank required } /** - * @return MinimaleVorlaufzeitSEPALastschrift|null The information about the lead time for the given Sequence Type and Core Type + * @return MinimaleVorlaufzeitSEPALastschrift|null The information about the lead time for the given Sequence Type and Direct Debit Type */ public function getMinimalLeadTime(): ?MinimaleVorlaufzeitSEPALastschrift { - return $this->hidxes->getParameter()->getMinimalLeadTime($this->seqType, $this->coreType); + $parsed = $this->hidxes->getParameter()->getMinimalLeadTime($this->seqType); + if ($parsed instanceof MinimaleVorlaufzeitSEPALastschrift) { + return $parsed; + } + return $parsed[$this->directDebitType] ?? null; } } diff --git a/lib/Fhp/Segment/BME/ParameterTerminierteSEPASammellastschriftEinreichenV1.php b/lib/Fhp/Segment/BME/ParameterTerminierteSEPASammellastschriftEinreichenV1.php deleted file mode 100755 index eb497406..00000000 --- a/lib/Fhp/Segment/BME/ParameterTerminierteSEPASammellastschriftEinreichenV1.php +++ /dev/null @@ -1,17 +0,0 @@ -minimaleVorlaufzeitFRSTOOFF : $this->minimaleVorlaufzeitFNALRCUR; return MinimaleVorlaufzeitSEPALastschrift::create($leadTime, '235959'); diff --git a/lib/Fhp/Segment/BSE/ParameterTerminierteSEPAFirmenLastschriftEinreichenV2.php b/lib/Fhp/Segment/BSE/ParameterTerminierteSEPAFirmenLastschriftEinreichenV2.php index 79c4f7bc..022c1754 100755 --- a/lib/Fhp/Segment/BSE/ParameterTerminierteSEPAFirmenLastschriftEinreichenV2.php +++ b/lib/Fhp/Segment/BSE/ParameterTerminierteSEPAFirmenLastschriftEinreichenV2.php @@ -14,9 +14,11 @@ abstract class ParameterTerminierteSEPAFirmenLastschriftEinreichenV2 extends Bas /** @var string */ public $maximaleVorlaufzeitCodiert; - public function getMinimalLeadTime(string $seqType, string $coreType = 'CORE'): ?MinimaleVorlaufzeitSEPALastschrift + /** @return MinimaleVorlaufzeitSEPALastschrift[] */ + public function getMinimalLeadTime(string $seqType) { - $parsed = MinimaleVorlaufzeitSEPALastschrift::parseCodedB2B($this->minimaleVorlaufzeitCodiert); - return $parsed[$seqType] ?? null; + return array_map(function ($value) use ($seqType) { + return $value[$seqType] ?? null; + }, MinimaleVorlaufzeitSEPALastschrift::parseCodedB2B($this->minimaleVorlaufzeitCodiert)); } } diff --git a/lib/Fhp/Segment/DSE/MinimaleVorlaufzeitSEPALastschrift.php b/lib/Fhp/Segment/DSE/MinimaleVorlaufzeitSEPALastschrift.php index f33277d1..1a673a4b 100644 --- a/lib/Fhp/Segment/DSE/MinimaleVorlaufzeitSEPALastschrift.php +++ b/lib/Fhp/Segment/DSE/MinimaleVorlaufzeitSEPALastschrift.php @@ -64,14 +64,14 @@ public static function parseCoded(string $coded): array return $result; } - /** @return MinimaleVorlaufzeitSEPALastschrift[]|array */ + /** @return MinimaleVorlaufzeitSEPALastschrift[][]|array */ public static function parseCodedB2B(string $coded): array { $result = []; foreach (array_chunk(explode(';', $coded), 3) as list($sequenceTypeCodiert, $minimaleSEPAVorlaufzeit, $cutOffZeit)) { $seqTypes = self::SEQUENCE_TYPE_CODIERT[$sequenceTypeCodiert] ?? []; foreach ($seqTypes as $seqType) { - $result[$seqType] = MinimaleVorlaufzeitSEPALastschrift::create($minimaleSEPAVorlaufzeit, $cutOffZeit, null, $sequenceTypeCodiert); + $result['B2B'][$seqType] = MinimaleVorlaufzeitSEPALastschrift::create($minimaleSEPAVorlaufzeit, $cutOffZeit, null, $sequenceTypeCodiert); } } return $result; diff --git a/lib/Fhp/Segment/DSE/ParameterTerminierteSEPAEinzellastschriftEinreichenV1.php b/lib/Fhp/Segment/DSE/ParameterTerminierteSEPAEinzellastschriftEinreichenV1.php index e205ad04..b03bfb84 100644 --- a/lib/Fhp/Segment/DSE/ParameterTerminierteSEPAEinzellastschriftEinreichenV1.php +++ b/lib/Fhp/Segment/DSE/ParameterTerminierteSEPAEinzellastschriftEinreichenV1.php @@ -18,7 +18,7 @@ class ParameterTerminierteSEPAEinzellastschriftEinreichenV1 extends BaseDeg impl /** @var int */ public $maximaleVorlaufzeitFRSTOOFF; - public function getMinimalLeadTime(string $seqType, string $coreType = 'CORE'): ?MinimaleVorlaufzeitSEPALastschrift + public function getMinimalLeadTime(string $seqType): ?MinimaleVorlaufzeitSEPALastschrift { $leadTime = in_array($seqType, ['FRST', 'OOFF']) ? $this->minimaleVorlaufzeitFRSTOOFF : $this->minimaleVorlaufzeitFNALRCUR; return MinimaleVorlaufzeitSEPALastschrift::create($leadTime, '235959'); diff --git a/lib/Fhp/Segment/DSE/ParameterTerminierteSEPALastschriftEinreichenV2.php b/lib/Fhp/Segment/DSE/ParameterTerminierteSEPALastschriftEinreichenV2.php index 66f535b6..fc982cc5 100755 --- a/lib/Fhp/Segment/DSE/ParameterTerminierteSEPALastschriftEinreichenV2.php +++ b/lib/Fhp/Segment/DSE/ParameterTerminierteSEPALastschriftEinreichenV2.php @@ -12,9 +12,10 @@ abstract class ParameterTerminierteSEPALastschriftEinreichenV2 extends BaseDeg i /** @var string */ public $maximaleVorlaufzeitCodiert; - public function getMinimalLeadTime(string $seqType, string $coreType = 'CORE'): ?MinimaleVorlaufzeitSEPALastschrift + public function getMinimalLeadTime(string $seqType) { - $parsed = MinimaleVorlaufzeitSEPALastschrift::parseCoded($this->minimaleVorlaufzeitCodiert); - return $parsed[$coreType][$seqType] ?? null; + return array_map(function ($value) use ($seqType) { + return $value[$seqType] ?? null; + }, MinimaleVorlaufzeitSEPALastschrift::parseCoded($this->minimaleVorlaufzeitCodiert)); } } diff --git a/lib/Fhp/Segment/DSE/SEPADirectDebitMinimalLeadTimeProvider.php b/lib/Fhp/Segment/DSE/SEPADirectDebitMinimalLeadTimeProvider.php index 81be43e8..00c82dc6 100644 --- a/lib/Fhp/Segment/DSE/SEPADirectDebitMinimalLeadTimeProvider.php +++ b/lib/Fhp/Segment/DSE/SEPADirectDebitMinimalLeadTimeProvider.php @@ -4,5 +4,6 @@ interface SEPADirectDebitMinimalLeadTimeProvider { - public function getMinimalLeadTime(string $seqType, string $coreType = 'CORE'): ?MinimaleVorlaufzeitSEPALastschrift; + /** @return MinimaleVorlaufzeitSEPALastschrift|MinimaleVorlaufzeitSEPALastschrift[]*/ + public function getMinimalLeadTime(string $seqType); }