Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix pain.008.001.02 for Spanish banks #47

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -174,5 +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);

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);
}
}

}
}