Skip to content

Commit 20adce7

Browse files
authored
Merge pull request nemiah#495 from ampaze/better-schema-check
Better schema check
2 parents e800766 + 43d321c commit 20adce7

File tree

3 files changed

+42
-8
lines changed

3 files changed

+42
-8
lines changed

lib/Fhp/Action/SendSEPADirectDebit.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,16 @@ protected function createRequest(BPD $bpd, ?UPD $upd)
148148
$supportedPainNamespaces = $hispas->getParameter()->getUnterstuetzteSepaDatenformate();
149149
}
150150

151-
if (!in_array($this->painNamespace, $supportedPainNamespaces)) {
151+
// Sometimes the Bank reports supported schemas with a "_GBIC_X" postfix.
152+
// GIBC_X stands for German Banking Industry Committee and a version counter.
153+
$xmlSchema = $this->painNamespace;
154+
$matchingSchemas = array_filter($supportedPainNamespaces, function($value) use ($xmlSchema) {
155+
// For example urn:iso:std:iso:20022:tech:xsd:pain.008.001.08 from the xml matches
156+
// urn:iso:std:iso:20022:tech:xsd:pain.008.001.08_GBIC_4
157+
return str_starts_with($value, $xmlSchema);
158+
});
159+
160+
if (count($matchingSchemas) === 0) {
152161
throw new UnsupportedException("The bank does not support the XML schema $this->painNamespace, but only "
153162
. implode(', ', $supportedPainNamespaces));
154163
}

lib/Fhp/Action/SendSEPARealtimeTransfer.php

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,25 @@ protected function createRequest(BPD $bpd, ?UPD $upd)
5858
/** @var HIIPZSv1|HIIPZSv2 $hiipzs */
5959
$hiipzs = $bpd->requireLatestSupportedParameters('HIIPZS');
6060

61-
/** @var HISPAS $hispas */
62-
$hispas = $bpd->requireLatestSupportedParameters('HISPAS');
63-
$supportedSchemas = $hispas->getParameter()->getUnterstuetzteSepaDatenformate();
64-
if (!in_array($this->xmlSchema, $supportedSchemas)) {
61+
$supportedSchemas = $hiipzs->parameter->unterstuetzteSEPADatenformate;
62+
63+
// If there are no SEPA formats available in the HIIPZS Parameters, we look to the general formats
64+
if (is_null($supportedSchemas)) {
65+
/** @var HISPAS $hispas */
66+
$hispas = $bpd->requireLatestSupportedParameters('HISPAS');
67+
$supportedSchemas = $hispas->getParameter()->getUnterstuetzteSepaDatenformate();
68+
}
69+
70+
// Sometimes the Bank reports supported schemas with a "_GBIC_X" postfix.
71+
// GIBC_X stands for German Banking Industry Committee and a version counter.
72+
$xmlSchema = $this->xmlSchema;
73+
$matchingSchemas = array_filter($supportedSchemas, function($value) use ($xmlSchema) {
74+
// For example urn:iso:std:iso:20022:tech:xsd:pain.001.001.09 from the xml matches
75+
// urn:iso:std:iso:20022:tech:xsd:pain.001.001.09_GBIC_4
76+
return str_starts_with($value, $xmlSchema);
77+
});
78+
79+
if (count($matchingSchemas) === 0) {
6580
throw new UnsupportedException("The bank does not support the XML schema $this->xmlSchema, but only "
6681
. implode(', ', $supportedSchemas));
6782
}

lib/Fhp/Action/SendSEPATransfer.php

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,13 @@ protected function createRequest(BPD $bpd, ?UPD $upd)
5252
$numberOfTransactions = $xmlAsObject->CstmrCdtTrfInitn->GrpHdr->NbOfTxs;
5353
$hasReqdExDates = false;
5454
foreach ($xmlAsObject->CstmrCdtTrfInitn?->PmtInf as $pmtInfo) {
55-
if (isset($pmtInfo->ReqdExctnDt) && $pmtInfo->ReqdExctnDt != '1999-01-01') {
55+
// Checks for both, <ReqdExctnDt>1999-01-01</ReqdExctnDt> and <ReqdExctnDt><Dt>1999-01-01</Dt></ReqdExctnDt>
56+
if (isset($pmtInfo->ReqdExctnDt) && ($pmtInfo->ReqdExctnDt->Dt ?? $pmtInfo->ReqdExctnDt) != '1999-01-01') {
5657
$hasReqdExDates = true;
5758
break;
5859
}
5960
}
6061

61-
6262
//NOW READ OUT, WICH SEGMENT SHOULD BE USED:
6363
if ($numberOfTransactions > 1 && $hasReqdExDates) {
6464

@@ -89,7 +89,17 @@ protected function createRequest(BPD $bpd, ?UPD $upd)
8989
/** @var HISPAS $hispas */
9090
$parameters = $bpd->requireLatestSupportedParameters('HISPAS');
9191
$supportedSchemas = $parameters->getParameter()->getUnterstuetzteSepaDatenformate();
92-
if (!in_array($this->xmlSchema, $supportedSchemas)) {
92+
93+
// Sometimes the Bank reports supported schemas with a "_GBIC_X" postfix.
94+
// GIBC_X stands for German Banking Industry Committee and a version counter.
95+
$xmlSchema = $this->xmlSchema;
96+
$matchingSchemas = array_filter($supportedSchemas, function($value) use ($xmlSchema) {
97+
// For example urn:iso:std:iso:20022:tech:xsd:pain.001.001.09 from the xml matches
98+
// urn:iso:std:iso:20022:tech:xsd:pain.001.001.09_GBIC_4
99+
return str_starts_with($value, $xmlSchema);
100+
});
101+
102+
if (count($matchingSchemas) === 0) {
93103
throw new UnsupportedException("The bank does not support the XML schema $this->xmlSchema, but only "
94104
. implode(', ', $supportedSchemas));
95105
}

0 commit comments

Comments
 (0)