mdomke / schwifty

IBAN parsing and validation

Home Page:https://schwifty.readthedocs.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

IBAN.generate not working for DK ?

AriMaritano opened this issue · comments

Hey, thanks a lot for the library, it's been of huge help! :)

I'm not sure if there's a bug here or if I'm using schiwfty.IBAN.generate wrong for DK bank account.
I check the specs for DK IBAN on swift, and they use '00400440116243' as an example.
If I'm not mistaken:
- '0040' should be the bank code
- '0440116243' should be the bank account number

(venv)
┌─[✓]─[usuario@dellari]─[~]
└──╼ pip show schwifty
Name: schwifty
Version: 2024.1.1.post0
Summary: 
Home-page: 
Author: 
Author-email: Martin Domke <mail@martindomke.net>
License: 
Location: /home/usuario/Shuttle99/venv/lib/python3.10/site-packages
Requires: iso3166, pycountry
Required-by: 
(venv) 
┌─[✓]─[usuario@dellari]─[~]
└──╼ python3
Python 3.10.12 (main, Nov 20 2023, 15:14:05) [GCC 11.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> bank_code = '0040'
>>> account_number = '0440116243'
>>> country = 'DK'
>>> import schwifty
>>> schwifty.IBAN.generate('DK', bank_code, account_number)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/usuario/Shuttle99/venv/lib/python3.10/site-packages/schwifty/iban.py", line 111, in generate
    bban = BBAN.from_components(
  File "/home/usuario/Shuttle99/venv/lib/python3.10/site-packages/schwifty/bban.py", line 101, in from_components
    raise exceptions.InvalidAccountCode(
schwifty.exceptions.InvalidAccountCode: Account code exceeds maximum size 9
>>> 

The domestic account number for Denmark seems to be 9 digits long, so that in your example it would be 044011624 the trailing 3 is actually the national check digit. There is however a problem with the current implementation of the IBAN generation in that regard.

  1. The national checksum digit for Denmark is not automatically calculated (I still have to find a source for the algorithm to use)
  2. It is currently not possible to provide the national check digit by hand to the IBAN.generate-method.

I will try to address both issues in the upcoming release.

On the other hand it would be good to understand if the Danish bank codes in the wild are in fact 9 digits long and the check digit ist only added when calculating the BBAN.

After reading through this document from the ECBS again, I think it is a legit idea to assume that the account numbers are actually provided as 10-digit long strings. It seems there is no official documentation on the actual algorithms begin used. I think I will just adapt the spec in the IBAN registry accordingly...

The release 2024.04.0 does now assume that Danish account numbers are always 10-digits long.

That's great, thanks @mdomke ! :)