Skip to content

Commit

Permalink
fixup! Implements BE BBAN checksum check
Browse files Browse the repository at this point in the history
  • Loading branch information
mhemeryck committed May 21, 2021
1 parent 49c39f5 commit 3ffa661
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 4 deletions.
1 change: 1 addition & 0 deletions schwifty/checksum/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,4 @@ def register(algorithm_cls: Type[Algorithm], prefix: Optional[str] = None) -> Ty

from schwifty.checksum import germany # noqa
from schwifty.checksum import italy # noqa
from schwifty.checksum import belgium # noqa
8 changes: 4 additions & 4 deletions schwifty/checksum/belgium.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import functools

import schwifty.checksum
from schwifty import checksum


register = functools.partial(schwifty.checksum.register, prefix="BE")
register = functools.partial(checksum.register, prefix="BE")


@register
class DefaultAlgorithm(schwifty.checksum.Algorithm):
class DefaultAlgorithm(checksum.Algorithm):
name = "default"
accepts = schwifty.checksum.InputType.BBAN
accepts = checksum.InputType.BBAN

def compute(self, bban: str) -> str:
return str(int(bban[:-2]) % 97)
Expand Down
3 changes: 3 additions & 0 deletions schwifty/iban.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ def add_bban_checksum(country_code: str, bban: str) -> str:
if country_code == "IT":
checksum = algorithms["IT:default"].compute(bban[1:])
bban = checksum + bban[1:]
elif country_code == "BE":
checksum = algorithms["BE:default"].compute(bban)
bban = bban[:-2] + checksum
return bban


Expand Down
1 change: 1 addition & 0 deletions tests/test_iban.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ def test_iban_properties():
(("GB", "NWBK", "31926819", "601613"), "GB29NWBK60161331926819"),
(("GB", "NWBK", "31926819"), "GB66NWBK00000031926819"),
(("GB", "NWBK601613", "31926819"), "GB29NWBK60161331926819"),
(("BE", "050", "123456"), "BE67050000123487"),
],
)
def test_generate_iban(components, compact):
Expand Down

0 comments on commit 3ffa661

Please sign in to comment.