-
Notifications
You must be signed in to change notification settings - Fork 0
/
iban.py
65 lines (56 loc) · 2.36 KB
/
iban.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
__author__ = "n3rdkeller.de"
__license__ = "GPL"
__version__ = "0.1"
__email__ = "github@n3rdkeller.de"
__status__ = "Development"
# global variables
COUNTRIES = ("AD", "AT", "BE", "CH", "CY", "CZ", "DE", "DK", "EE", "ES", \
"FI", "FR", "GB", "GI", "GR", "HU", "IE", "IS", "IT", "LT", \
"LU", "LV", "NL", "NO", "PL", "SE", "SI", "SK")
# countries that are currently involved in SEPA
# 12-30-2013
# I got it from here:
# http://www.pruefziffernberechnung.de/I/IBAN.shtml
##############
# class IBAN #
##############
class Iban(object):
'''New instance of iban-class'''
def __init__(self, country_code, account_number, routing_number):
self.country_code = country_code
self.account_number = account_number
self.routing_number = routing_number
def gen_iban(self) -> str:
if self.country_code == "DE":
# I know there are many things that are equal here to other
# countries. But I decided to only do DE for now.
fill_to_ten = 10 - len(self.account_number)
bban = str(self.routing_number) + \
(fill_to_ten * "0") + \
str(self.account_number)
# country code chars have to get converted first:
country_code_int = 131400 # only works for "DE"
# I know this is no implementation
# but I'm too lazy now
# get the checksum
checksum = 98 - int(bban + str(country_code_int)) % 97
# not sure if this is working:
if (checksum < 0) and (abs(checksum) < 10):
checksum = "0" + str(abs(checksum))
# assemble the iban
self.my_iban = self.country_code + str(checksum) + bban
return self.my_iban
else:
print("\nOther countries than 'DE' not yet working.")
print("Feel free to contribute on GitHub.\n")
return "IBAN could not be generated."
def get_readable(self) -> str:
if len(self.my_iban) != 0:
return_string = ""
for i in range(len(self.my_iban)):
if (i % 4 == 0) and (i != 0):
return_string += " "
return_string += self.my_iban[i]
return return_string
else:
return "IBAN not generated yet."