-
Notifications
You must be signed in to change notification settings - Fork 0
/
fints_test.py
146 lines (132 loc) · 5.38 KB
/
fints_test.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
import datetime
import getpass
import logging
import sys
from decimal import Decimal
from fints.client import FinTS3PinTanClient, NeedTANResponse, FinTSUnsupportedOperation
from fints.hhd.flicker import terminal_flicker_unix
from fints.utils import minimal_interactive_cli_bootstrap
import config
logging.basicConfig(level=logging.DEBUG)
client_args = (
config.blz, # BLZ
config.user, # USER
config.pin,
config.fints_url # ENDPOINT
)
f = FinTS3PinTanClient(*client_args)
minimal_interactive_cli_bootstrap(f)
def ask_for_tan(response):
print("A TAN is required")
print(response.challenge)
if getattr(response, 'challenge_hhduc', None):
try:
terminal_flicker_unix(response.challenge_hhduc)
except KeyboardInterrupt:
pass
tan = input('Please enter TAN:')
return f.send_tan(response, tan)
# Open the actual dialog
with f:
# Since PSD2, a TAN might be needed for dialog initialization. Let's check if there is one required
if f.init_tan_response:
ask_for_tan(f.init_tan_response)
# Fetch accounts
accounts = f.get_sepa_accounts()
if isinstance(accounts, NeedTANResponse):
accounts = ask_for_tan(accounts)
if len(accounts) == 1:
account = accounts[0]
else:
print("Multiple accounts available, choose one")
for i, mm in enumerate(accounts):
print(i, mm.iban)
choice = input("Choice: ").strip()
account = accounts[int(choice)]
# Test pausing and resuming the dialog
dialog_data = f.pause_dialog()
client_data = f.deconstruct(including_private=True)
f = FinTS3PinTanClient(*client_args, from_data=client_data)
with f.resume_dialog(dialog_data):
while True:
operations = [
"End dialog",
"Fetch transactions of the last 30 days",
"Fetch transactions of the last 120 days",
"Fetch transactions XML of the last 30 days",
"Fetch transactions XML of the last 120 days",
"Fetch information",
"Fetch balance",
"Fetch holdings",
"Fetch scheduled debits",
"Fetch status protocol",
"Make a simple transfer"
]
print("Choose an operation")
for i, o in enumerate(operations):
print(i, o)
choice = int(input("Choice: ").strip())
try:
if choice == 0:
break
elif choice == 1:
res = f.get_transactions(account, datetime.date.today() - datetime.timedelta(days=30),
datetime.date.today())
while isinstance(res, NeedTANResponse):
res = ask_for_tan(res)
print("Found", len(res), "transactions")
elif choice == 2:
res = f.get_transactions(account, datetime.date.today() - datetime.timedelta(days=120),
datetime.date.today())
while isinstance(res, NeedTANResponse):
res = ask_for_tan(res)
print("Found", len(res), "transactions")
elif choice == 3:
res = f.get_transactions_xml(account, datetime.date.today() - datetime.timedelta(days=30),
datetime.date.today())
while isinstance(res, NeedTANResponse):
res = ask_for_tan(res)
print("Found", len(res[0]) + len(res[1]), "XML documents")
elif choice == 4:
res = f.get_transactions_xml(account, datetime.date.today() - datetime.timedelta(days=120),
datetime.date.today())
while isinstance(res, NeedTANResponse):
res = ask_for_tan(res)
print("Found", len(res[0]) + len(res[1]), "XML documents")
elif choice == 5:
print(f.get_information())
elif choice == 6:
res = f.get_balance(account)
while isinstance(res, NeedTANResponse):
res = ask_for_tan(res)
print(res)
elif choice == 7:
res = f.get_holdings(account)
while isinstance(res, NeedTANResponse):
res = ask_for_tan(res)
print(res)
elif choice == 8:
res = f.get_scheduled_debits(account)
while isinstance(res, NeedTANResponse):
res = ask_for_tan(res)
print(res)
elif choice == 9:
res = f.get_status_protocol()
while isinstance(res, NeedTANResponse):
res = ask_for_tan(res)
print(res)
elif choice == 10:
res = f.simple_sepa_transfer(
account=accounts[0],
iban=input('Target IBAN:'),
bic=input('Target BIC:'),
amount=Decimal(input('Amount:')),
recipient_name=input('Recipient name:'),
account_name=input('Your name:'),
reason=input('Reason:'),
endtoend_id='NOTPROVIDED',
)
if isinstance(res, NeedTANResponse):
ask_for_tan(res)
except FinTSUnsupportedOperation as e:
print("This operation is not supported by this bank:", e)