]> git.ipfire.org Git - thirdparty/python-fints.git/commitdiff
Auto-detect supported CAMT formats of bank (#201)
authorRaphael Michel <michel@rami.io>
Thu, 27 Nov 2025 14:52:31 +0000 (15:52 +0100)
committerGitHub <noreply@github.com>
Thu, 27 Nov 2025 14:52:31 +0000 (15:52 +0100)
fints/client.py
fints/formals.py
fints/segments/statement.py

index 25cbd65746d93d99545d66864ced71a5aa97337c..8dd513ffd4575578f236989bcbd28f8d6d0535e8 100644 (file)
@@ -567,17 +567,27 @@ class FinTS3Client:
         return booked_streams, pending_streams
 
     def get_transactions_xml(self, account: SEPAAccount, start_date: datetime.date = None,
-                             end_date: datetime.date = None) -> list:
+                             end_date: datetime.date = None, supported_camt_messages = None) -> list:
         """
-        Fetches the list of transactions of a bank account in a certain timeframe as camt.052.001.02 XML files.
+        Fetches the list of transactions of a bank account in a certain timeframe as camt XML files.
         Returns both booked and pending transactions.
 
         :param account: SEPA
         :param start_date: First day to fetch
         :param end_date: Last day to fetch
+        :param supported_camt_messages: Names of accepted camt formats. If `None`, we'll accept whatever the bank offers.
         :return: Two lists of bytestrings containing XML documents, possibly empty: first one for booked transactions,
             second for pending transactions
         """
+        hicazs = self.bpd.find_segment_first('HICAZS')
+        if hicazs:
+            bank_supported_camt_messages = list(hicazs.parameter.supported_camt_formats)
+        else:
+            bank_supported_camt_messages = []
+        if supported_camt_messages is None:
+            supported_camt_messages = bank_supported_camt_messages
+        else:
+            supported_camt_messages = [m for m in supported_camt_messages if m in bank_supported_camt_messages]
 
         with self._get_dialog() as dialog:
             hkcaz = self._find_highest_supported_command(HKCAZ1)
@@ -591,7 +601,7 @@ class FinTS3Client:
                     date_start=start_date,
                     date_end=end_date,
                     touchdown_point=touchdown,
-                    supported_camt_messages=SupportedMessageTypes(['urn:iso:std:iso:20022:tech:xsd:camt.052.001.02']),
+                    supported_camt_messages=SupportedMessageTypes(supported_camt_messages),
                 ),
                 FinTS3Client._response_handler_get_transactions_xml,
                 'HICAZ'
index 877c0be821721a64320503fcd52ed0c18c252621..2d9d90703a8b5aafca3c8046640df45b74a0a54d 100644 (file)
@@ -919,6 +919,16 @@ class ScheduledBatchDebitParameter1(DataElementGroup):
     single_booking_allowed = DataElementField(type='jn', _d="Einzelbuchung erlaubt")
 
 
+class TransactionsTimeParameter1(DataElementGroup):
+    """Parameter Kontoumsätze/Zeitraum camt, version 1
+
+    Source: FinTS Financial Transaction Services, Schnittstellenspezifikation, Messages -- Multibankfähige Geschäftsvorfälle """
+    storage_duration = DataElementField(type='num', max_length=4, _d="Speicherzeitraum")
+    entry_number_entries_allowed = DataElementField(type='jn', _d="Eingabe Anzahl Einträge erlaubt")
+    all_accounts_allowed = DataElementField(type='jn', _d="Alle Konten erlaubt")
+    supported_camt_formats = DataElementField(type='an', max_length=256, max_count=99, required=False, _d="Unterstützte camt-Datenformate")
+
+
 class ScheduledBatchDebitParameter2(DataElementGroup):
     """Parameter terminierte SEPA-Sammellastschrift einreichen, version 2
 
index bc45c95a6a543312a5f42e53769b64e68e791228..58dd5f51486fffeb0917f8425c4b657e7bd462d9 100644 (file)
@@ -1,6 +1,6 @@
 from fints.fields import DataElementField, DataElementGroupField, CodeField
 from fints.formals import KTI1, Account2, Account3, QueryCreditCardStatements2, SupportedMessageTypes, \
-    BookedCamtStatements1, StatementFormat, Confirmation, ReportPeriod2
+    BookedCamtStatements1, StatementFormat, Confirmation, ReportPeriod2, TransactionsTimeParameter1
 
 from .base import FinTS3Segment, ParameterSegment
 
@@ -90,6 +90,13 @@ class DIKKUS2(ParameterSegment):
     parameter = DataElementGroupField(type=QueryCreditCardStatements2, _d="Parameter Kreditkartenumsätze anfordern")
 
 
+class HICAZS1(ParameterSegment):
+    """Kontoumsätze/Zeitraum camt Parameter, version 1
+
+    Source: FinTS Financial Transaction Services, Schnittstellenspezifikation, Messages -- Multibankfähige Geschäftsvorfälle """
+    parameter = DataElementGroupField(type=TransactionsTimeParameter1, _d="Parameter Kontoumsätze/Zeitraum camt")
+
+
 class HKCAZ1(FinTS3Segment):
     """Kontoumsätze anfordern/Zeitraum, version 5