Browse Source

Added checking for common Romanian banks in IBAN

pull/7/head
Kenneth Bruen 3 years ago
parent
commit
6f7242477e
Signed by: kbruen
GPG Key ID: C1980A470C3EE5B1
  1. 9
      server/foxbank_server/apis/accounts.py
  2. 24
      server/foxbank_server/utils/iban.py

9
server/foxbank_server/apis/accounts.py

@ -7,7 +7,7 @@ import re
from ..decorators import ensure_logged_in from ..decorators import ensure_logged_in
from ..models import Account from ..models import Account
from ..utils.iban import check_iban from ..utils.iban import IBAN_BANKS, check_iban
from .. import decorators from .. import decorators
from .. import db_utils from .. import db_utils
from .. import returns from .. import returns
@ -29,6 +29,7 @@ class MetaValidateIbanParams(Schema):
class MetaValidateIbanSchema(returns.SuccessSchema): class MetaValidateIbanSchema(returns.SuccessSchema):
valid = fields.Bool() valid = fields.Bool()
formatted_iban = fields.Str(data_key='formattedIban', optional=True) formatted_iban = fields.Str(data_key='formattedIban', optional=True)
bank_name = fields.Str(data_key='bankName', optional=True, description='Known bank for IBAN')
@bp.get('/meta/currencies') @bp.get('/meta/currencies')
@bp.response(200, MetaCurrenciesSchema) @bp.response(200, MetaCurrenciesSchema)
@ -51,9 +52,15 @@ def get_validate_iban(iban: str):
"""Validate IBAN""" """Validate IBAN"""
iban = re.sub(r'\s', '', iban) iban = re.sub(r'\s', '', iban)
valid = len(iban) > 8 and re.match(r'^[A-Z]{2}[0-9]{2}', iban) is not None and check_iban(iban) valid = len(iban) > 8 and re.match(r'^[A-Z]{2}[0-9]{2}', iban) is not None and check_iban(iban)
bank_name = None
if iban[0:2] in IBAN_BANKS:
if iban[4:8] in IBAN_BANKS[iban[0:2]]:
bank_name = IBAN_BANKS[iban[0:2]][iban[4:8]]
return returns.success( return returns.success(
valid=valid, valid=valid,
formatted_iban=re.sub(r'(.{4})', r'\1 ', iban) if valid else None, formatted_iban=re.sub(r'(.{4})', r'\1 ', iban) if valid else None,
bank_name=bank_name if valid else None,
) )

24
server/foxbank_server/utils/iban.py

@ -1,6 +1,30 @@
from .string import str_range_replace from .string import str_range_replace
IBAN_BANKS = {
'RO': {
'NBOR': 'BANCA NATIONALA A ROMANIEI',
'BUCU': 'ALPHA BANK ROMANIA SA',
'CARP': 'BANCA COMERCIALA CARPATICA SA',
'RNCB': 'BANCA COMERCIALA ROMANA SA',
'BRDE': 'BANCA ROMANA PENTRU DEZVOLTARE',
'BRMA': 'BANCA ROMANEASCA SA',
'BTRL': 'BANCA TRANSILVANIA SA',
'DAFB': 'BANK LEUMI ROMANIA SA',
'CECE': 'CASA DE ECONOMII SI CONSEMNATIUNI CEC SA',
'CITI': 'CITIBANK ROMANIA SA',
'UGBI': 'GARANTIBANK INTERNATIONAL NV - SUCURSALA ROMANIA',
'INGB': 'ING BANK NV',
'BREL': 'LIBRA BANK SA',
'BNRB': 'OTP BANK ROMANIA SA',
'RZBR': 'RAIFFEISEN BANK SA',
'TREZ': 'TREZORERIA STATULUI',
'BACX': 'UNICREDIT BANK SA',
'FOXB': 'FOXBANK',
},
}
def c_to_iban_i(c: str) -> int: def c_to_iban_i(c: str) -> int:
a = ord(c) a = ord(c)
if a in range(48, 58): if a in range(48, 58):

Loading…
Cancel
Save