schoero / swissqrbill

Swiss QR Bill generation in Node.js and browsers
MIT License
155 stars 29 forks source link

Issue when trying to create a QR-bill with a QR-IBAN that ends with an alphabetical letter at the end #408

Closed Everoli closed 1 year ago

Everoli commented 1 year ago

Problem description

Hey guys, we're using your library and are quite happy with it. However, one of our customers ran into an issue. Originally, they had issues adding and validating their QR-IBAN (similar as reported here (https://github.com/schoero/SwissQRBill/issues/215). We tried the fix you mentioned there, however, when trying it now the QR-IBAN validation seems to work, but we run into issues when trying to create the QR-bill using this QR-IBAN. Is this already known or can I provide you with more information on this?

schoero commented 1 year ago

I understand that you are using a QR-IBAN with a QR-Reference and they are passing the validation checks. Is that correct?

but we run into issues when trying to create the QR-bill using this QR-IBAN.

Can you elaborate on that? What are the issues, can you share an error message that you might get?

As of now, I am not aware of any issues with the validation or use of QR-IBAN.

schnuffel1729 commented 1 year ago

Here are some technical details you need for it: invoiceNumber: 1000236 qriban: XXXX XXXX XXXX 1758 7240 V With qriban.replace(/\s/g, '').substring(2, 21) + fillUpString(invoiceNumber.toString(), '0', 7) we create the reference XXXXXXXXXX17587240V1000236 Now we use swissQrBillUtils.calculateQRReferenceChecksum(reference) to get the checksum. The result is NaN So I assume that something with the reference is wrong.

schoero commented 1 year ago

Yes, the reference you try to use is invalid. First of all, the reference can only contain numeric digits. In addition to that, it has a specific structure that may be predetermined by your bank. You can read more about it in this issue: #380

steefanfuchs commented 1 year ago

@schoero thanks for answering.

Now we figured out that the reference number we are using to calculate the checksum is invalid because of the letter V. As you can see in the data provided by @schnuffel1729, the V is coming from the QR-IBAN. This QR-IBAN is also passing the check of the utility function isValidQrIban so therefor it must be a valid QR-IBAN.

Do you maybe know how to deal with these kind of QR-IBANs when it comes to building the reference?

As far as i understood the whole process of building the reference, when using the QR-Reference (QRR), you need to use the QR-IBAN right? Screenshot 2023-04-26 at 11 46 40

schoero commented 1 year ago

If you use a QR-IBAN, you must also use a QR-Reference. This is the only connection between the QR-IBAN and the QR-Reference. The QR-Reference is not derived from the QR-IBAN.

From my previously linked comment: https://github.com/schoero/SwissQRBill/issues/380#issuecomment-1187980421

When I got my QR-IBAN, I have received a 6-Digit identification number from my bank (ZKB) and a diagram how it must be used which looked like that

II IIIIN NNNNN NNNNN NNNNN NNNNC
^      ^                       ^
Identification number
       Variable numbers
                               Checksum

For clarification:

Symbol Meaning Description
I Identification number 6-Digit number that I have received from my bank.
N Variable numbers Those digits can be freely chosen.
C Checksum Calculated checksum I got by calling calculateQRReferenceChecksum("IIIIIINNNNNNNNNNNNNNNNNNNN")

For my use case, I decided to use the customer number for the first 10 N digits and the invoice number for the last 10 N digits. If the invoice number is shorter than 10 digits, I fill the remaining digits with zeros. That way I was able to automatically identify the customer and the invoice by just looking at the QR-Reference.

I would recommend to reach out to your bank if they have rules how the QR-Reference should be used, as it is possible that the rules of your bank differ from mine.

Everoli commented 1 year ago

@schoero thanks for you help and explanation, now it's clear to us what was the issue with our previous implementation. I've one follow-up question - you mentioned that you use the identification number as the first 6 digits of the QR reference number. Do you know if that is mandatory to use? If I understand your comment in the linked discussion, it doesn't seem like it. Just wanted to confirm that before closing the issue.

The last digit of the reference is the checksum. You can calculate the checksum using the calculateQRReferenceChecksum function, exported from utils. The rest of the digits have no structure and can be freely chosen. It usually makes sense to use a combination of the customer number and invoice number and fill the other digits with 0.

schoero commented 1 year ago

@Everoli As far as I'm aware, the identification number is not part of the QR-Bill specifications, so other banks may not have an identification number, or they may have different requirements on how the QR-Reference should be structured. I can only tell how it was for my case with ZKB.

You need to check with your bank to see if they have any specific requirements regarding the QR-Reference. It is possible that you have received some information alongside you QR-IBAN? I would be interested to know if these requirements vary from bank to bank, so please let me know if you find any information.

Everoli commented 1 year ago

@schoero thanks for the info and your help! 🙏🏽 I also couldn't find anything related to the identification number in the guidelines provided by the Swiss payment services. If I find any further info on the identification number I'm happy to let you know.