Skip to content

Commit 87106bb

Browse files
authored
Improve code example in docs/tans.rst (#184)
* Add product_id to example in docs/tans.rst * Fix initial tan request in example in docs/tans.rst Before this commit, the example suggested that we should only ask for a TAN after calling client.get_transactions(). This did not work (at least for my bank Sparkasse Hannover). Now with this commit, the example is proposing to ask for a TAN already in the beginning, as also suggested in docs/trouble.rst. Another side effect of this commit is that ask_for_tan() now also checks for response.decoupled and presents a more reasonable string for input() in the case of PushTAN.
1 parent 28251f0 commit 87106bb

File tree

1 file changed

+22
-12
lines changed

1 file changed

+22
-12
lines changed

docs/tans.rst

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -206,30 +206,40 @@ A full example on how to get transactions if a TAN is required. If a TAN is requ
206206
207207
from credentials import blz, username, password, hbci_backend
208208
209+
product_id = "CHANGE_ME"
210+
211+
def ask_for_tan(f, response):
212+
print("A TAN is required")
213+
print(response.challenge)
214+
if getattr(response, 'challenge_hhduc', None):
215+
try:
216+
terminal_flicker_unix(response.challenge_hhduc)
217+
except KeyboardInterrupt:
218+
pass
219+
if response.decoupled:
220+
tan = input('Please press enter after confirming the transaction in your app:')
221+
else:
222+
tan = input('Please enter TAN:')
223+
return f.send_tan(response, tan)
224+
209225
client = FinTS3PinTanClient(blz,
210226
username,
211227
password,
212-
hbci_backend)
228+
hbci_backend,
229+
product_id=product_id)
213230
minimal_interactive_cli_bootstrap(client)
214231
with client:
232+
while isinstance(client.init_tan_response, NeedTANResponse):
233+
client.init_tan_response = ask_for_tan(client, client.init_tan_response)
234+
215235
accounts = client.get_sepa_accounts()
216236
for account in accounts:
217237
print(f"Doing {account.iban}")
218238
result = client.get_transactions(account,
219239
start_date=datetime.datetime.now() - datetime.timedelta(days=100),
220240
end_date=datetime.datetime.now())
221241
if isinstance(result, NeedTANResponse):
222-
print("TAN is required")
223-
if getattr(result, 'challenge_hhduc', None):
224-
# Smart-TAN with flicker
225-
try:
226-
terminal_flicker_unix(result.challenge_hhduc)
227-
except KeyboardInterrupt:
228-
pass
229-
# else: mobile TAN/manual Smart-TAN/... is used
230-
print(result.challenge)
231-
tan = input('Please enter TAN:')
232-
result = client.send_tan(result, tan)
242+
result = ask_for_tan(client, result)
233243
else:
234244
print("No TAN is required")
235245
print(f"Got {len(result)} transactions for {account.iban}")

0 commit comments

Comments
 (0)