From: Raphael Michel Date: Wed, 25 Jul 2018 13:09:06 +0000 (+0200) Subject: Use sepaxml to generate PAIN message X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=41f188911b9e5753778ffcfb340f9e85fcc9e156;p=thirdparty%2Fpython-fints.git Use sepaxml to generate PAIN message --- diff --git a/fints/client.py b/fints/client.py index a867ac3..3212b20 100644 --- a/fints/client.py +++ b/fints/client.py @@ -2,6 +2,8 @@ import logging import re import datetime +from decimal import Decimal + from .connection import FinTSHTTPSConnection from .dialog import FinTSDialog from .message import FinTSMessage @@ -15,6 +17,7 @@ from .segments.transfer import HKCCS from .message import FinTSResponse from .utils import mt940_to_array, MT535_Miniparser, split_for_data_groups, split_for_data_elements, Password from mt940.models import Balance +from sepaxml import SepaTransfer logger = logging.getLogger(__name__) @@ -265,20 +268,40 @@ class FinTS3Client: return 'Ok' - def create_sepa_transfer(self, account, arg): - # Diese Funktion erstellt eine neue SEPA-Überweisung - self.tan_bezeichnung = arg['TAN-Bezeichnung'] + def start_simple_sepa_transfer(self, account: SEPAAccount, tan_method, iban: str, bic: str, recipient_name: str, + amount: Decimal, account_name: str, reason: str, endtoend_id='NOTPROVIDED', + tan_description=''): + config = { + "name": account_name, + "IBAN": account.iban, + "BIC": account.bic, + "batch": False, + "currency": "EUR", + } + sepa = SepaTransfer(config, 'pain.001.001.03') + payment = { + "name": recipient_name, + "IBAN": iban, + "BIC": bic, + "amount": int(Decimal(amount) * 100), # in cents + "execution_date": datetime.date.today(), + "description": reason, + "endtoend_id": endtoend_id, + } + sepa.add_payment(payment) + xml = sepa.export().decode() + self.start_sepa_transfer(account, xml, tan_method, tan_description) + + def start_sepa_transfer(self, account: SEPAAccount, pain_message: str, tan_method, tan_description=''): dialog = self._new_dialog() dialog.sync() - # TAN-Verfahren für Dialoginitialisierung ändern - dialog.tan_mechs = [arg['TAN-Verfahren']] - + dialog.tan_mechs = [tan_method.security_feature] dialog.init() def _get_msg(): - segHKCCS = HKCCS(3, account, arg) - segHKTAN = HKTAN(4, 4, '', self.tan_bezeichnung) + segHKCCS = HKCCS(3, account, pain_message) + segHKTAN = HKTAN(4, 4, '', tan_description) return self._new_message(dialog, [ segHKCCS, segHKTAN @@ -293,7 +316,6 @@ class FinTS3Client: response = {} response['response'] = resp response['dialog'] = dialog - return response def get_tan_methods(self): diff --git a/fints/segments/transfer.py b/fints/segments/transfer.py index e839ed3..fe17bbb 100644 --- a/fints/segments/transfer.py +++ b/fints/segments/transfer.py @@ -1,5 +1,5 @@ from . import FinTS3Segment -import datetime +from ..models import SEPAAccount class HKCCS(FinTS3Segment): @@ -9,10 +9,9 @@ class HKCCS(FinTS3Segment): """ type = 'HKCCS' - def __init__(self, segno, account, arg): + def __init__(self, segno, account: SEPAAccount, pain_msg): self.version = 1 sepa_descriptor = 'urn?:iso?:std?:iso?:20022?:tech?:xsd?:pain.001.001.03' - pain_msg = self.create_pain(account, arg) msg = ':'.join([ account.iban, account.bic @@ -23,40 +22,3 @@ class HKCCS(FinTS3Segment): '@{}@{}'.format(len(pain_msg), pain_msg) ] super().__init__(segno, data) - - def create_pain(self, account, arg): - pain = '' - pain += '' - pain += '' - pain += '' - pain += '' + datetime.datetime.now().isoformat()[:-2] + '' - pain += '' + datetime.datetime.now().replace(microsecond=0).isoformat() + '' - pain += '1' - pain += '' + arg['CtrlSum'] + '' - pain += '' + arg['Nm'] + '' - pain += '' - pain += '' - pain += '' + datetime.datetime.now().isoformat()[:-2] + '' - pain += 'TRF1' - pain += '' + arg['CtrlSum'] + '' - pain += 'SEPA' - pain += '1999-01-01' - pain += '' + arg['Nm'] + '' - pain += '' + account.iban + '' - pain += '' + account.bic + '' - pain += 'SLEV' - pain += '' - pain += 'NOTPROVIDED' - pain += '' + arg['CtrlSum'] + '' - pain += '' + arg['DbtrAgt'] + '' - pain += '' + arg['Nm'] + '' - pain += '' + arg['DbtrAcct'] + '' - pain += '' + arg['Ustrd'] + '' - pain += '' - pain += '' - pain += '' - pain += '' - - return pain diff --git a/requirements.txt b/requirements.txt index 3b33fbc..b562c2e 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,3 @@ requests mt-940 - +sepaxml==2.0.* diff --git a/setup.py b/setup.py index e48a574..9cb9846 100644 --- a/setup.py +++ b/setup.py @@ -35,7 +35,7 @@ setup( keywords='hbci banking fints', install_requires=[ - 'requests', 'mt-940', + 'requests', 'mt-940', 'sepaxml==2.0.*' ], packages=find_packages(include=['fints', 'fints.*']),