diff --git a/lib/Digitick/Sepa/DomBuilder/BaseDomBuilder.php b/lib/Digitick/Sepa/DomBuilder/BaseDomBuilder.php index 02af781..b8c1cad 100644 --- a/lib/Digitick/Sepa/DomBuilder/BaseDomBuilder.php +++ b/lib/Digitick/Sepa/DomBuilder/BaseDomBuilder.php @@ -109,7 +109,7 @@ public function visitGroupHeader(GroupHeader $groupHeader) $groupHeaderTag->appendChild($messageId); $creationDateTime = $this->createElement( 'CreDtTm', - $groupHeader->getCreationDateTime()->format('Y-m-d\TH:i:s\Z') + $groupHeader->getCreationDateTime()->format($groupHeader->getCreationDateTimeFormat()) ); $groupHeaderTag->appendChild($creationDateTime); $groupHeaderTag->appendChild($this->createElement('NbOfTxs', $groupHeader->getNumberOfTransactions())); diff --git a/lib/Digitick/Sepa/GroupHeader.php b/lib/Digitick/Sepa/GroupHeader.php index c674567..0984465 100644 --- a/lib/Digitick/Sepa/GroupHeader.php +++ b/lib/Digitick/Sepa/GroupHeader.php @@ -66,6 +66,11 @@ class GroupHeader */ protected $creationDateTime; + /** + * @var string + */ + protected $creationDateTimeFormat = 'Y-m-d\TH:i:s\Z'; + /** * Should the bank book multiple transaction as a batch * @@ -211,4 +216,19 @@ public function getCreationDateTime() return $this->creationDateTime; } -} \ No newline at end of file + /** + * @param string $creationDateTimeFormat + */ + public function setCreationDateTimeFormat($creationDateTimeFormat) + { + $this->creationDateTimeFormat = $creationDateTimeFormat; + } + + /** + * @return string + */ + public function getCreationDateTimeFormat() + { + return $this->creationDateTimeFormat; + } +} diff --git a/tests/CustomerCreditValidationTest.php b/tests/CustomerCreditValidationTest.php index c2f3965..31345e9 100644 --- a/tests/CustomerCreditValidationTest.php +++ b/tests/CustomerCreditValidationTest.php @@ -305,4 +305,46 @@ public function testUmlautConversion() $testNode = $xpathDoc->query('//sepa:Ustrd'); $this->assertEquals('Only A-Z without aeoeuessAeOeUe remittanceInformation', $testNode->item(0)->textContent); } + + /** + * Test a transfer file using other date format. + * There are different representations possible for IsoDateTime: + * http://www.swift.com/assets/corporates/documents/business_areas/ebam_standards_mx/business/x68910b9357eed3cf49770d42b07d70f1.htm + */ + public function testSinglePaymentOtherCreationDateTimeFormat() + { + $dateTimeFormat = 'Y-m-d\TH:i:s.000P'; + + $groupHeader = new GroupHeader('transferID', 'Me'); + $groupHeader->setCreationDateTimeFormat($dateTimeFormat); + $sepaFile = new CustomerCreditTransferFile($groupHeader); + + $transfer = new CustomerCreditTransferInformation('0.02', 'FI1350001540000056', 'Their Corp'); + $transfer->setBic('OKOYFIHH'); + $transfer->setRemittanceInformation('Transaction Description'); + $transfer->setEndToEndIdentification(uniqid()); + $transfer->setInstructionId(uniqid()); + + $payment = new PaymentInformation('Payment Info ID', 'FR1420041010050500013M02606', 'PSSTFRPPMON', 'My Corp'); + $payment->setValidPaymentMethods(array('TRANSFER')); + $payment->setPaymentMethod('TRANSFER'); + $payment->setCategoryPurposeCode('SALA'); + $payment->addTransfer($transfer); + + $sepaFile->addPaymentInformation($payment); + + $domBuilder = new CustomerCreditTransferDomBuilder(); + $sepaFile->accept($domBuilder); + $xml = $domBuilder->asXml(); + + $doc = new \DOMDocument(); + $doc->loadXML($xml); + + $xpathDoc = new \DOMXPath($doc); + $xpathDoc->registerNamespace('sepa', 'urn:iso:std:iso:20022:tech:xsd:pain.001.002.03'); + + $dateTime = new \DateTime(); + $testNode = $xpathDoc->query('//sepa:CreDtTm'); + $this->assertEquals($dateTime->format($dateTimeFormat), $testNode->item(0)->textContent, 'CreDtTm has specified format.'); + } }