Skip to content

Commit ab16dac

Browse files
authored
Auto-detect supported CAMT formats of bank (#201)
1 parent bb89d91 commit ab16dac

File tree

3 files changed

+31
-4
lines changed

3 files changed

+31
-4
lines changed

fints/client.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -567,17 +567,27 @@ def _response_handler_get_transactions_xml(responses):
567567
return booked_streams, pending_streams
568568

569569
def get_transactions_xml(self, account: SEPAAccount, start_date: datetime.date = None,
570-
end_date: datetime.date = None) -> list:
570+
end_date: datetime.date = None, supported_camt_messages = None) -> list:
571571
"""
572-
Fetches the list of transactions of a bank account in a certain timeframe as camt.052.001.02 XML files.
572+
Fetches the list of transactions of a bank account in a certain timeframe as camt XML files.
573573
Returns both booked and pending transactions.
574574
575575
:param account: SEPA
576576
:param start_date: First day to fetch
577577
:param end_date: Last day to fetch
578+
:param supported_camt_messages: Names of accepted camt formats. If `None`, we'll accept whatever the bank offers.
578579
:return: Two lists of bytestrings containing XML documents, possibly empty: first one for booked transactions,
579580
second for pending transactions
580581
"""
582+
hicazs = self.bpd.find_segment_first('HICAZS')
583+
if hicazs:
584+
bank_supported_camt_messages = list(hicazs.parameter.supported_camt_formats)
585+
else:
586+
bank_supported_camt_messages = []
587+
if supported_camt_messages is None:
588+
supported_camt_messages = bank_supported_camt_messages
589+
else:
590+
supported_camt_messages = [m for m in supported_camt_messages if m in bank_supported_camt_messages]
581591

582592
with self._get_dialog() as dialog:
583593
hkcaz = self._find_highest_supported_command(HKCAZ1)
@@ -591,7 +601,7 @@ def get_transactions_xml(self, account: SEPAAccount, start_date: datetime.date =
591601
date_start=start_date,
592602
date_end=end_date,
593603
touchdown_point=touchdown,
594-
supported_camt_messages=SupportedMessageTypes(['urn:iso:std:iso:20022:tech:xsd:camt.052.001.02']),
604+
supported_camt_messages=SupportedMessageTypes(supported_camt_messages),
595605
),
596606
FinTS3Client._response_handler_get_transactions_xml,
597607
'HICAZ'

fints/formals.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -919,6 +919,16 @@ class ScheduledBatchDebitParameter1(DataElementGroup):
919919
single_booking_allowed = DataElementField(type='jn', _d="Einzelbuchung erlaubt")
920920

921921

922+
class TransactionsTimeParameter1(DataElementGroup):
923+
"""Parameter Kontoumsätze/Zeitraum camt, version 1
924+
925+
Source: FinTS Financial Transaction Services, Schnittstellenspezifikation, Messages -- Multibankfähige Geschäftsvorfälle """
926+
storage_duration = DataElementField(type='num', max_length=4, _d="Speicherzeitraum")
927+
entry_number_entries_allowed = DataElementField(type='jn', _d="Eingabe Anzahl Einträge erlaubt")
928+
all_accounts_allowed = DataElementField(type='jn', _d="Alle Konten erlaubt")
929+
supported_camt_formats = DataElementField(type='an', max_length=256, max_count=99, required=False, _d="Unterstützte camt-Datenformate")
930+
931+
922932
class ScheduledBatchDebitParameter2(DataElementGroup):
923933
"""Parameter terminierte SEPA-Sammellastschrift einreichen, version 2
924934

fints/segments/statement.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from fints.fields import DataElementField, DataElementGroupField, CodeField
22
from fints.formals import KTI1, Account2, Account3, QueryCreditCardStatements2, SupportedMessageTypes, \
3-
BookedCamtStatements1, StatementFormat, Confirmation, ReportPeriod2
3+
BookedCamtStatements1, StatementFormat, Confirmation, ReportPeriod2, TransactionsTimeParameter1
44

55
from .base import FinTS3Segment, ParameterSegment
66

@@ -90,6 +90,13 @@ class DIKKUS2(ParameterSegment):
9090
parameter = DataElementGroupField(type=QueryCreditCardStatements2, _d="Parameter Kreditkartenumsätze anfordern")
9191

9292

93+
class HICAZS1(ParameterSegment):
94+
"""Kontoumsätze/Zeitraum camt Parameter, version 1
95+
96+
Source: FinTS Financial Transaction Services, Schnittstellenspezifikation, Messages -- Multibankfähige Geschäftsvorfälle """
97+
parameter = DataElementGroupField(type=TransactionsTimeParameter1, _d="Parameter Kontoumsätze/Zeitraum camt")
98+
99+
93100
class HKCAZ1(FinTS3Segment):
94101
"""Kontoumsätze anfordern/Zeitraum, version 5
95102

0 commit comments

Comments
 (0)