ch2877 / swiss-payment

PHP library to generate Swiss pain.001 XML messages
MIT License
8 stars 5 forks source link

Date of payment #8

Closed Tarom11 closed 2 years ago

Tarom11 commented 2 years ago

Thank you for this great tool. Is it possible to enter the payment date as well? Unfortunately I have not found it.

Best regards from St. Gallen Tarom

cbaconnier commented 2 years ago

You should be able to set the payment date on the PaymentInformation level


$payment = new PaymentInformation(
         'payment-001',  
         'InnoMuster AG',
         new BIC('ZKBKCHZZ80A'),
         new IBAN('CH6600700110000204481')
);

$payment->setExecutionDate(new \DateTime());
Tarom11 commented 2 years ago

Thank you very much. Do you know which date format to use here?

cbaconnier commented 2 years ago

It uses a DateTime class, you can set the date with the following format

$payment->setExecutionDate(new \DateTime('2022-12-31'));

You can also use other/custom format. Refer to the DateTime documentation: https://www.php.net/manual/en/class.datetime.php


The library will format the date for the XML with the following

$this->executionDate->format('Y-m-d')

PaymentInformation.php#L244

If you don't provide an execution date, the library will use the date of today: PaymentInformation.php#L87

Tarom11 commented 2 years ago

Thank you very much. Will test it right away.