From: Henryk Plötz Date: Sat, 11 Aug 2018 18:55:28 +0000 (+0200) Subject: get_sepa_accounts() working X-Git-Tag: v2.0.0~1^2~117 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a98acfd161edc4853cce414b831f4b3942ccfe24;p=thirdparty%2Fpython-fints.git get_sepa_accounts() working --- diff --git a/fints/client.py b/fints/client.py index 6aa40d2..2718b93 100644 --- a/fints/client.py +++ b/fints/client.py @@ -10,13 +10,14 @@ from fints.segments.debit import HKDSE, HKDME from .connection import FinTSHTTPSConnection from .dialog import FinTSDialog from .message import FinTSMessage -from .models import SEPAAccount, TANMethod, TANChallenge6, TANChallenge5, TANChallenge3, TANChallenge4, TANChallenge +from .models import SEPAAccount, TANChallenge6, TANChallenge5, TANChallenge3, TANChallenge4, TANChallenge from .segments.accounts import HKSPA from .segments.auth import HKTAN, HKTAB from .segments.depot import HKWPD from .segments.saldo import HKSAL from .segments.statement import HKKAZ from .segments.transfer import HKCCS, HKCCM +from .formals import TwoStepParametersCommon from .utils import mt940_to_array, MT535_Miniparser, Password logger = logging.getLogger(__name__) @@ -56,12 +57,9 @@ class FinTS3Client: logger.debug('Got HKSPA response: {}'.format(resp)) dialog.end() - seg = resp._find_segment('HISPA') self.accounts = [] - for arr in seg[1:]: - self.accounts.append(SEPAAccount( - iban=arr[1], bic=arr[2], accountnumber=arr[3], subaccount=arr[4], blz=arr[6] - )) + for seg in resp.find_segments('HISPA'): + self.accounts.extend(seg.accounts) return self.accounts @@ -290,7 +288,7 @@ class FinTS3Client: challenge.dialog.end() - def start_simple_sepa_transfer(self, account: SEPAAccount, tan_method: TANMethod, iban: str, bic: str, + def start_simple_sepa_transfer(self, account: SEPAAccount, tan_method: TwoStepParametersCommon, iban: str, bic: str, recipient_name: str, amount: Decimal, account_name: str, reason: str, endtoend_id='NOTPROVIDED', tan_description=''): """ diff --git a/fints/connection.py b/fints/connection.py index 1f121f1..65d7fc3 100644 --- a/fints/connection.py +++ b/fints/connection.py @@ -27,6 +27,7 @@ class FinTSHTTPSConnection: raise FinTSConnectionError('Bad status code {}'.format(r.status_code)) response = base64.b64decode(r.content.decode('iso-8859-1')) retval = FinTSResponse(response) + #import pprint; pprint.pprint(response) FIXME Remove print("Received <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<") with Password.protect(): retval.print_nested() diff --git a/fints/formals.py b/fints/formals.py index 6004a39..aa2c53f 100644 --- a/fints/formals.py +++ b/fints/formals.py @@ -806,3 +806,11 @@ class SupportedLanguages2(DataElementGroup): class SupportedHBCIVersions2(DataElementGroup): versions = DataElementField(type='code', max_length=3, min_count=1, max_count=9) + +class AccountInternational(DataElementGroup): + is_sepa = DataElementField(type='jn') + iban = DataElementField(type='an', max_length=34) + bic = DataElementField(type='an', max_length=11) + account_number = DataElementField(type='id') + subaccount_number = DataElementField(type='id') + bank_identifier = DataElementGroupField(type=BankIdentifier) diff --git a/fints/message.py b/fints/message.py index eaa5def..a1a38c6 100644 --- a/fints/message.py +++ b/fints/message.py @@ -19,9 +19,9 @@ class FinTSMessage: self.segments = [] self.encrypted_segments = [] - if tan_mechs and '999' not in [t.security_feature for t in tan_mechs]: + if tan_mechs and '999' not in [t.security_function for t in tan_mechs]: self.profile_version = 2 - self.security_function = tan_mechs[0].security_feature + self.security_function = tan_mechs[0].security_function else: self.profile_version = 1 self.security_function = '999' diff --git a/fints/models.py b/fints/models.py index df4eb94..6709df9 100644 --- a/fints/models.py +++ b/fints/models.py @@ -23,190 +23,6 @@ class DataClass: ) -class TANMethod(DataClass): - pass - - -class TANMethod1(TANMethod): - """ - :param security_feature: - :param tan_process: - :param tech_id: - :param name: - :param max_length_input: - :param allowed_format: - :param text_returnvalue: - :param max_length_returnvalue: - :param number_of_supported_lists: - :param multiple_tans_allowed: - :param tan_time_delayed_allowed: - """ - # Source: PIN/TAN docs – Verfahrensparameter Zwei-Schritt-Verfahren, Elementversion #1 - version = 1 - args = ['security_feature', 'tan_process', 'tech_id', 'name', 'max_length_input', 'allowed_format', - 'text_returnvalue', 'max_length_returnvalue', 'number_of_supported_lists', 'multiple_tans_allowed', - 'tan_time_delayed_allowed'] - - -class TANMethod2(TANMethod): - """ - :param security_feature: - :param tan_process: - :param tech_id: - :param name: - :param max_length_input: - :param allowed_format: - :param text_returnvalue: - :param max_length_returnvalue: - :param number_of_supported_lists: - :param multiple_tans_allowed: - :param tan_time_dialog_association: - :param tan_list_number_required: - :param cancel_allowed: - :param challenge_class_required: - :param challenge_value_required: - """ - # Source: PIN/TAN docs – Verfahrensparameter Zwei-Schritt-Verfahren, Elementversion #2 - version = 2 - args = ['security_feature', 'tan_process', 'tech_id', 'name', 'max_length_input', 'allowed_format', - 'text_returnvalue', 'max_length_returnvalue', 'number_of_supported_lists', 'multiple_tans_allowed', - 'tan_time_dialog_association', 'tan_list_number_required', 'cancel_allowed', 'challenge_class_required', - 'challenge_value_required'] - - - -class TANMethod3(TANMethod): - """ - :param security_feature: - :param tan_process: - :param tech_id: - :param name: - :param max_length_input: - :param allowed_format: - :param text_returnvalue: - :param max_length_returnvalue: - :param number_of_supported_lists: - :param multiple_tans_allowed: - :param tan_time_dialog_association: - :param tan_list_number_required: - :param cancel_allowed: - :param challenge_class_required: - :param challenge_value_required: - :param initialization_mode: - :param description_required: - :param supported_media_number: - """ - # Source: PIN/TAN docs – Verfahrensparameter Zwei-Schritt-Verfahren, Elementversion #3 - version = 3 - args = ['security_feature', 'tan_process', 'tech_id', 'name', 'max_length_input', 'allowed_format', - 'text_returnvalue', 'max_length_returnvalue', 'number_of_supported_lists', 'multiple_tans_allowed', - 'tan_time_dialog_association', 'tan_list_number_required', 'cancel_allowed', 'challenge_class_required', - 'challenge_value_required', 'initialization_mode', 'description_required', 'supported_media_number'] - - -class TANMethod4(TANMethod): - """ - :param security_feature: - :param tan_process: - :param tech_id: - :param zka_id: - :param zka_version: - :param name: - :param max_length_input: - :param allowed_format: - :param text_returnvalue: - :param max_length_returnvalue: - :param number_of_supported_lists: - :param multiple_tans_allowed: - :param tan_time_dialog_association: - :param tan_list_number_required: - :param cancel_allowed: - :param sms_charge_account_required: - :param challenge_class_required: - :param challenge_value_required: - :param challenge_structured - :param initialization_mode: - :param description_required: - :param supported_media_number: - """ - # Source: PIN/TAN docs – Verfahrensparameter Zwei-Schritt-Verfahren, Elementversion #4 - version = 4 - args = ['security_feature', 'tan_process', 'tech_id', 'zka_id', 'zka_version', 'name', 'max_length_input', - 'allowed_format', 'text_returnvalue', 'max_length_returnvalue', 'number_of_supported_lists', - 'multiple_tans_allowed', 'tan_time_dialog_association', 'tan_list_number_required', 'cancel_allowed', - 'sms_charge_account_required', 'challenge_class_required', 'challenge_value_required', - 'challenge_structured', 'initialization_mode', 'description_required', 'supported_media_number'] - - - -class TANMethod5(TANMethod): - """ - :param security_feature: - :param tan_process: - :param tech_id: - :param zka_id: - :param zka_version: - :param name: - :param max_length_input: - :param allowed_format: - :param text_returnvalue: - :param max_length_returnvalue: - :param number_of_supported_lists: - :param multiple_tans_allowed: - :param tan_time_dialog_association: - :param tan_list_number_required: - :param cancel_allowed: - :param sms_charge_account_required: - :param principal_account_required: - :param challenge_class_required: - :param challenge_value_required: - :param initialization_mode: - :param description_required: - :param supported_media_number: - """ - # Source: PIN/TAN docs – Verfahrensparameter Zwei-Schritt-Verfahren, Elementversion #5 - version = 5 - args = ['security_feature', 'tan_process', 'tech_id', 'zka_id', 'zka_version', 'name', 'max_length_input', - 'allowed_format', 'text_returnvalue', 'max_length_returnvalue', 'number_of_supported_lists', - 'multiple_tans_allowed', 'tan_time_dialog_association', 'tan_list_number_required', 'cancel_allowed', - 'sms_charge_account_required', 'principal_account_required', 'challenge_class_required', - 'challenge_value_required', 'initialization_mode', 'description_required', 'supported_media_number'] - - -class TANMethod6(TANMethod): - # Source: PIN/TAN docs – Verfahrensparameter Zwei-Schritt-Verfahren, Elementversion #6 - """ - :param security_feature: - :param tan_process: - :param tech_id: - :param zka_id: - :param zka_version: - :param name: - :param max_length_input: - :param allowed_format: - :param text_returnvalue: - :param max_length_returnvalue: - :param number_of_supported_lists: - :param multiple_tans_allowed: - :param tan_time_dialog_association: - :param cancel_allowed: - :param sms_charge_account_required: - :param principal_account_required: - :param challenge_class_required: - :param challenge_value_required: - :param initialization_mode: - :param description_required: - :param hhd_uc_required: - :param supported_media_number: - """ - version = 6 - args = ['security_feature', 'tan_process', 'tech_id', 'zka_id', 'zka_version', 'name', 'max_length_input', - 'allowed_format', 'text_returnvalue', 'max_length_returnvalue', 'multiple_tans_allowed', - 'tan_time_dialog_association', 'cancel_allowed', 'sms_charge_account_required', - 'principal_account_required', - 'challenge_class_required', 'challenge_structured', 'initialization_mode', 'description_required', - 'hhd_uc_required', 'supported_media_number'] - class TANChallenge(DataClass): def __init__(self, dialog, *args, **kwargs): diff --git a/fints/segments/__init__.py b/fints/segments/__init__.py index 44bf1db..04fa53f 100644 --- a/fints/segments/__init__.py +++ b/fints/segments/__init__.py @@ -1,6 +1,6 @@ import re -from fints.formals import Container, ContainerMeta, SegmentHeader, DataElementGroupField, DataElementField, ReferenceMessage, SegmentSequenceField, SecurityProfile, SecurityIdentificationDetails, SecurityDateTime, EncryptionAlgorithm, KeyName, Certificate, HashAlgorithm, SignatureAlgorithm, UserDefinedSignature, Response, AccountInformation, AccountLimit, AllowedTransaction, ParameterTwostepTAN1, ParameterTwostepTAN2, ParameterTwostepTAN3, ParameterTwostepTAN4, ParameterTwostepTAN5, ParameterTwostepTAN6, ParameterPinTan, SupportedLanguages2, SupportedHBCIVersions2, BankIdentifier +from fints.formals import Container, ContainerMeta, SegmentHeader, DataElementGroupField, DataElementField, ReferenceMessage, SegmentSequenceField, SecurityProfile, SecurityIdentificationDetails, SecurityDateTime, EncryptionAlgorithm, KeyName, Certificate, HashAlgorithm, SignatureAlgorithm, UserDefinedSignature, Response, AccountInformation, AccountLimit, AllowedTransaction, ParameterTwostepTAN1, ParameterTwostepTAN2, ParameterTwostepTAN3, ParameterTwostepTAN4, ParameterTwostepTAN5, ParameterTwostepTAN6, ParameterPinTan, SupportedLanguages2, SupportedHBCIVersions2, BankIdentifier, AccountInternational from fints.utils import classproperty, SubclassesMixin @@ -187,3 +187,6 @@ class HIBPA3(FinTS3Segment): max_message_length = DataElementField(type='num', max_length=4, required=False) min_timeout = DataElementField(type='num', max_length=4, required=False) max_timeout = DataElementField(type='num', max_length=4, required=False) + +class HISPA1(FinTS3Segment): + accounts = DataElementGroupField(type=AccountInternational, max_count=999, required=False)