From 7466ab1b9f59d1fd417c567039001d4cab89c3d1 Mon Sep 17 00:00:00 2001 From: Hans Ulrich Wucherer <hans-ulrich.wucherer@ormigo.com> Date: Fri, 27 Jun 2014 11:03:20 +0200 Subject: [PATCH] adjustable format for creation date time A local time format with utc offset ("'Y-m-d\TH:i:s.000P") is required by a german bank (sparkasse-koelnbonn.de). --- .../Sepa/DomBuilder/BaseDomBuilder.php | 2 +- lib/Digitick/Sepa/GroupHeader.php | 22 +++++++++- tests/CustomerCreditValidationTest.php | 42 +++++++++++++++++++ 3 files changed, 64 insertions(+), 2 deletions(-) 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.'); + } }