]> git.ipfire.org Git - thirdparty/python-fints.git/commitdiff
Improve code example in docs/tans.rst (#184)
authorlemoer <git@irrelefant.net>
Mon, 10 Feb 2025 11:38:32 +0000 (12:38 +0100)
committerGitHub <noreply@github.com>
Mon, 10 Feb 2025 11:38:32 +0000 (12:38 +0100)
* 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.

docs/tans.rst

index f3a3eedd0d5913a46b001d2caa06714c8cf88fd3..432bac889cb02ef6e5d93ca05d988a6ffbd18001 100644 (file)
@@ -206,12 +206,32 @@ A full example on how to get transactions if a TAN is required. If a TAN is requ
 
     from credentials import blz, username, password, hbci_backend
 
+    product_id = "CHANGE_ME"
+
+    def ask_for_tan(f, 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
+        if response.decoupled:
+            tan = input('Please press enter after confirming the transaction in your app:')
+        else:
+            tan = input('Please enter TAN:')
+        return f.send_tan(response, tan)
+
     client = FinTS3PinTanClient(blz,
                                 username,
                                 password,
-                                hbci_backend)
+                                hbci_backend,
+                                product_id=product_id)
     minimal_interactive_cli_bootstrap(client)
     with client:
+        while isinstance(client.init_tan_response, NeedTANResponse):
+            client.init_tan_response = ask_for_tan(client, client.init_tan_response)
+
         accounts = client.get_sepa_accounts()
         for account in accounts:
             print(f"Doing {account.iban}")
@@ -219,17 +239,7 @@ A full example on how to get transactions if a TAN is required. If a TAN is requ
                                              start_date=datetime.datetime.now() - datetime.timedelta(days=100),
                                              end_date=datetime.datetime.now())
             if isinstance(result, NeedTANResponse):
-                print("TAN is required")
-                if getattr(result, 'challenge_hhduc', None):
-                    # Smart-TAN with flicker
-                    try:
-                        terminal_flicker_unix(result.challenge_hhduc)
-                    except KeyboardInterrupt:
-                        pass
-                # else: mobile TAN/manual Smart-TAN/... is used
-                print(result.challenge)
-                tan = input('Please enter TAN:')
-                result = client.send_tan(result, tan)
+                result = ask_for_tan(client, result)
             else:
                 print("No TAN is required")
             print(f"Got {len(result)} transactions for {account.iban}")