manuelbl / SwissQRBill.NET

.NET library for Swiss QR bill payment slips (aka QR-Rechnung)
MIT License
86 stars 32 forks source link

QR data ends mistakenly with an empty line #12

Closed f45t closed 4 years ago

f45t commented 4 years ago

When testing the generated QR bills against several banking solutions several portals raises the following error:

The last delivered data element must not be terminated with a line feed (CR + LF or LF).

"Das letzte gelieferte Datenelement darf nicht mit einer Zeilenschaltung (CR + LF bzw. LF) abgeschlossen werden."

For more infos, check paragraph 4.2.4: https://www.paymentstandards.ch/dam/downloads/ig-qr-bill-de.pdf

I verified the contained QR data and "they" are correct, at the moment an empty line closes the payment/qr data

manuelbl commented 4 years ago

Thanks for the feedback. This has caused problems before when reading a QR code, and now it's related to generating a QR code.

I'm rather convinced that the banking solutions understand the specification incorrectly and this library implements it correctly. The question boils down to what the last data element is. According to my interpretation, it can either be bill information (StrdBkgInf) or alternative schemes (AltPmt) if they are used. The difference arises if bill information is empty and not alternative schemes are used.

According to chapter 4.3.3 of the specification, StrdBkgInf is an optional field, i.e. it can be empty but it must always be delivered (see 4.3.1). So the field Trailer can never be the last data element.

Therefore, this library always adds NL after Trailer as the next field (StrdBkgInf) cannot be omitted. If StrdBkgInf is empty, the QR code text will end with NL. This is probably the case the banking solutions complain about.

Can you confirm that the problem only arises if bill information / StrdBkgInf is empty and alternative schemes are not used?

Can you be more specific regarding the banking solutions? Are we talking about accouting software or mobile banking apps, and what specific one?

f45t commented 4 years ago

Thanks for the fast response.

Yes, the StrdBkgInf (BillInformation) is empty. You're correct that according to the definition, the Field StrdBkgInf is optional and therefore can be empty, but must be contained... i assume the definition as O is wrong and it should more likely be an A. But that's an assumption, i didn't contact SIX. (as a bypass i will always add the BillInformation)

As an example implementation which throws the error: The iOS "MobileSCAN" app of "Raiffeisen Schweiz Genossenschaft" (Version 2.0.2)

manuelbl commented 4 years ago

Raiffeisen aren't the first one to treat StrdBkgInf as a field of type A instead of type O. I've already relaxed the verfication of scanned QR codes to allow for it.

I will further investigate the issue and probably go with the most compatible solution, i.e. I might remove the LF after Trailer. But first I need to ensure it will not cause new incompatibilities with other solutions.

f45t commented 4 years ago

And thanks again for your fast response.

IMHO and as you laid out, the issue is not an issue of this library. its either an issue of the specification or of the "other" implementations. specifying the BillInformation solves "the problem" for me in all testet setups. Therefore i close this issue... i assume the lack of clarity in this part of the specification will popup within the next month at several places and implementations... sorry to bother you.

... and btw: thanks for this library!