8000 Add QRBills.create_esr_reference by kalsan · Pull Request #31 · damoiser/qr-bills · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Add QRBills.create_esr_reference #31

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open

Conversation

kalsan
Copy link
@kalsan kalsan commented Oct 20, 2023

Hello and thank you for your much appreciated work on this gem! It's a true gem indeed.

While creditor references (RF...) are very easy to generate with QRBills.create_creditor_reference, I've had quite some struggle to generate valid references for bills that support QR style IBANs. As it seems that I've finally managed to generate valid references (with an ESR-style modulo-10 check-digit), I thought that it might be a good idea to contribute the solution back to qr-bills, as it is a feature that is yet missing, in my opinion.

This pull request adds QRBills.create_esr_reference to qr-bills. The solution is based on http://sahits.ch/blog/blog/2007/11/08/uberprufen-esr-referenz-nummer/. Feel free to change anything you like :-)

Best,
Kalsan

@damoiser
Copy link
Owner

better later than never :-) sorry for the delay answering here and thanks a lot for your contribution.

Just a question, is ESR reference still compliant to QR bills? Reading quickly the six page I found that ESR got decommissioned in favor of the QR Bill IBAN

The QR-IBAN replaces the ESR subscriber number.
https://www.six-group.com/en/blog/qr-bill-standing-orders.html

I just try to be more compliant as possible with the standards of QR Bills.

@kalsan
Copy link
Author
kalsan commented Jun 19, 2025

Hi @damoiser

TLDR: when generating a QR bill with a reference number, one doesn't get to choose whether the number should be QR-style or ESR-style; it is dictated by the IBAN the money will flow to.

This pull request ensures backwards compatibility. While ESR should have disappeared, there are still many ESR-style IBANs around, forcing us to keep using the feature.

A few years ago, banks sent us new IBAN numbers and asked us to use them, but claimed that the old ones were still valid. I guess that might be why some billers still have old IBAN numbers in ESR style. So while in theory, ESR style should be deprecated, it is still needed if the invoicing party sends the old style IBAN.
I found this to be very helpful: https://swiss-qr-invoice.org/validator

This is how to find out whether an IBAN can be used with proper QR or needs the backwards compatibility:

  def qr_iban?
    return false if iban.blank? # arbitrary safeguard
    iban_institute_identifier = iban.strip.gsub(' ', '')[4..8].to_i
    return iban_institute_identifier.between?(30_000, 31_999)
  end

I just try to be more compliant as possible with the standards of QR Bills.

I totally understand your concern. Perhaps adding a note to the documentation mentioning that ESR is outdated and should only be used if the IBAN dictates it would be a solution?

Best,
Kalsan

@damoiser damoiser self-requested a review June 19, 2025 20:36
@damoiser
Copy link
Owner

Hi @kalsan - thanks for the info, I slightly adjusted, bumped the ruby version and added some tests. Please check if is ok for you as well, after that. Will then merge it and publish the new version. Thanks again for contributing!

@kalsan
Copy link
Author
kalsan commented Jun 20, 2025

@damoiser looks great, thank you very much!

Given our discussion, I'm wondering whether it would be a good idea to further include the method qr_iban? described above before releasing the version - would you like me to add a commit?

@damoiser
Copy link
Owner

Hi @kalsan - yes sure! feel free to commit as well the qr_iban? helper, however I would ask you to use another name for this function, maybe "qr_esr_iban?", as "qr_iban" can be interpreted as standard iban but this follow another validation pattern (as quickly checked here: https://stackoverflow.com/questions/21928083/iban-validation-check).

Thanks!

@kalsan
Copy link
Author
kalsan commented Jun 23, 2025

@damoiser I've added an appropriate method and performed some slight refactoring for better consistency. Further, I've added a line to the README hinting to the comment explaining the differences.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants
0