Skip to content
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

Support for generating IBANs for countries when bban doesn't start with bank_code #9

Closed
sedlar opened this issue Nov 20, 2017 · 5 comments

Comments

@sedlar
Copy link

sedlar commented Nov 20, 2017

It's not possible to generate IBAN for countries where bban doesn't start with bank_code, e.g. Italy - http://www.xe.com/ibancalculator/sample/?ibancountry=italy

Do you intend to support generating ibans for all countries?

On [9]: iban = IBAN('IT60 X054 2811 1010 0000 0123 456')                                          

In [10]: iban.country_code
Out[10]: 'IT'

In [11]: iban.bank_code
Out[11]: '05428'

In [12]: iban.account_code
Out[12]: '000000123456'

In [13]: iban.branch_code
Out[13]: '11101'

In [14]: IBAN.generate(country_code=iban.country_code, bank_code=iban.bank_code+iban.branch_code, account_code=iban.account_code)
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-14-4145eaaa1945> in <module>()
----> 1 IBAN.generate(country_code=iban.country_code, bank_code=iban.bank_code+iban.branch_code, account_code=iban.account_code)

~/.virtualenvs/swift/lib/python3.5/site-packages/schwifty/iban.py in generate(cls, country_code, bank_code, account_code)
    111         account_code = account_code.rjust(account_code_length, '0')
    112         iban = country_code + '??' + bank_code + account_code
--> 113         return cls(iban)
    114 
    115     def validate(self):

~/.virtualenvs/swift/lib/python3.5/site-packages/schwifty/iban.py in __init__(self, iban, allow_invalid)
     67 
     68         if not allow_invalid:
---> 69             self.validate()
     70 
     71     def _calc_checksum_digits(self):

~/.virtualenvs/swift/lib/python3.5/site-packages/schwifty/iban.py in validate(self)
    115     def validate(self):
    116         self._validate_characters()
--> 117         self._validate_length()
    118         self._validate_format()
    119         self._validate_checksum()

~/.virtualenvs/swift/lib/python3.5/site-packages/schwifty/iban.py in _validate_length(self)
    130     def _validate_length(self):
    131         if self.spec['iban_length'] != self.length:
--> 132             raise ValueError("Invalid IBAN length")
    133 
    134     def _validate_format(self):

ValueError: Invalid IBAN length
@mdomke
Copy link
Owner

mdomke commented Nov 30, 2017

Hey @sedlar, sorry for the late reply. This is actually a bug in schwifty, because the IBAN.generate-method cannot handle IBANs which are composed of other things than country-code, check-sum, bank-code, branch-code and account-code. The italian BBANs have a format specification that looks like this 1!a5!n5!n12!c. So there seems to be one character prefixed to the BBAN which I don't know the meaning of. Is it static? Is it always X. Can you maybe shed some light on this?

@sedlar
Copy link
Author

sedlar commented Nov 30, 2017

Hi @mdomke, thanks for reply. The X character is national checksum digit. I have found the description of the algorithm to compute it in https://docs.oracle.com/cd/E18727_01/doc.121/e13483/T359831T498954.htm. Descriptions of some other country specific checksum can be found also in globalcitizen/php-iban#39.

@mdomke
Copy link
Owner

mdomke commented Nov 30, 2017

Hi @sedlar thank you for the information. I'll try and see if I can implement something with respect to country specific check digits, but I can't promise anything time wise.

@giuseppecot
Copy link

giuseppecot commented Nov 26, 2019

Hi, for IBAN IT there is an error in the 'iban_registry.json' file, that is:
"IT": {
     "iban_spec": "IT2! n1! a5! n5! n12! c",
     "iban_length": 27,
     "bban_length": 23,
     "bban_spec": "1! a5! n5! n12! c",
     "positions": {
       "branch_code": [
         6
         11
       ]
       "account_code": [
         11
         23
       ]
       "bank_code": [
         0,
         6

       ]
     }
   }

referring to wikipedia
the bank_code cpm takes the CIN, so the index was modified to include the character 0.

in this way the problem has been solved.

@mdomke
Copy link
Owner

mdomke commented Apr 12, 2020

This is fixed by #26

@mdomke mdomke closed this as completed Apr 12, 2020
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

No branches or pull requests

3 participants