From 8c7d5f8f0e849b8efc90b986651a2cb00c902580 Mon Sep 17 00:00:00 2001 From: danielmf Date: Thu, 12 Jun 2014 13:28:49 +0200 Subject: [PATCH 1/2] Fix pain.008.001.02 for Spanish banks Fix header for Spanish banks, see https://github.com/digitick/php-sepa-xml/issues/44 --- .../CustomerDirectDebitTransferDomBuilder.php | 29 ++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/lib/Digitick/Sepa/DomBuilder/CustomerDirectDebitTransferDomBuilder.php b/lib/Digitick/Sepa/DomBuilder/CustomerDirectDebitTransferDomBuilder.php index 95b51f0..5f57042 100644 --- a/lib/Digitick/Sepa/DomBuilder/CustomerDirectDebitTransferDomBuilder.php +++ b/lib/Digitick/Sepa/DomBuilder/CustomerDirectDebitTransferDomBuilder.php @@ -28,6 +28,7 @@ use Digitick\Sepa\TransferInformation\TransferInformationInterface; use Digitick\Sepa\PaymentInformation; use Digitick\Sepa\TransferFile\TransferFileInterface; +use Digitick\Sepa\GroupHeader; class CustomerDirectDebitTransferDomBuilder extends BaseDomBuilder @@ -175,4 +176,30 @@ public function visitTransferInformation(TransferInformationInterface $transacti } -} \ No newline at end of file + /** + * Add the specific OrgId element for the format 'pain.008.001.02' + * + * @param GroupHeader $groupHeader + * @return mixed + */ + public function visitGroupHeader(GroupHeader $groupHeader) + { + parent::visitGroupHeader($groupHeader); + + if ($groupHeader->getInitiatingPartyId() !== null && $this->painFormat === 'pain.008.001.02') { + $newId = $this->createElement('Id'); + $orgId = $this->createElement('OrgId'); + $othr = $this->createElement('Othr'); + $othr->appendChild($this->createElement('Id', $groupHeader->getInitiatingPartyId())); + $orgId->appendChild($othr); + $newId->appendChild($orgId); + + $xpath = new \DOMXpath($this->doc); + $items = $xpath->query('GrpHdr/InitgPty/Id', $this->currentTransfer); + $oldId = $items->item(0); + + $oldId->parentNode->replaceChild($newId, $oldId); + } + } + +} From d2c50935ec523df281dfd5fe0f13b9115a6b5dfe Mon Sep 17 00:00:00 2001 From: danielmf Date: Thu, 12 Jun 2014 13:56:26 +0200 Subject: [PATCH 2/2] Fix code style --- .../CustomerDirectDebitTransferDomBuilder.php | 49 +++++++++---------- 1 file changed, 24 insertions(+), 25 deletions(-) diff --git a/lib/Digitick/Sepa/DomBuilder/CustomerDirectDebitTransferDomBuilder.php b/lib/Digitick/Sepa/DomBuilder/CustomerDirectDebitTransferDomBuilder.php index 5f57042..f6c066e 100644 --- a/lib/Digitick/Sepa/DomBuilder/CustomerDirectDebitTransferDomBuilder.php +++ b/lib/Digitick/Sepa/DomBuilder/CustomerDirectDebitTransferDomBuilder.php @@ -175,31 +175,30 @@ public function visitTransferInformation(TransferInformationInterface $transacti } + /** + * Add the specific OrgId element for the format 'pain.008.001.02' + * + * @param GroupHeader $groupHeader + * @return mixed + */ + public function visitGroupHeader(GroupHeader $groupHeader) + { + parent::visitGroupHeader($groupHeader); - /** - * Add the specific OrgId element for the format 'pain.008.001.02' - * - * @param GroupHeader $groupHeader - * @return mixed - */ - public function visitGroupHeader(GroupHeader $groupHeader) - { - parent::visitGroupHeader($groupHeader); - - if ($groupHeader->getInitiatingPartyId() !== null && $this->painFormat === 'pain.008.001.02') { - $newId = $this->createElement('Id'); - $orgId = $this->createElement('OrgId'); - $othr = $this->createElement('Othr'); - $othr->appendChild($this->createElement('Id', $groupHeader->getInitiatingPartyId())); - $orgId->appendChild($othr); - $newId->appendChild($orgId); - - $xpath = new \DOMXpath($this->doc); - $items = $xpath->query('GrpHdr/InitgPty/Id', $this->currentTransfer); - $oldId = $items->item(0); - - $oldId->parentNode->replaceChild($newId, $oldId); - } - } + if ($groupHeader->getInitiatingPartyId() !== null && $this->painFormat === 'pain.008.001.02') { + $newId = $this->createElement('Id'); + $orgId = $this->createElement('OrgId'); + $othr = $this->createElement('Othr'); + $othr->appendChild($this->createElement('Id', $groupHeader->getInitiatingPartyId())); + $orgId->appendChild($othr); + $newId->appendChild($orgId); + + $xpath = new \DOMXpath($this->doc); + $items = $xpath->query('GrpHdr/InitgPty/Id', $this->currentTransfer); + $oldId = $items->item(0); + + $oldId->parentNode->replaceChild($newId, $oldId); + } + } }