From: Henryk Plötz Date: Sat, 8 Jun 2019 18:19:17 +0000 (+0200) Subject: Let simple_sepa_transfer() automatically choose a SEPA PAIN version X-Git-Tag: v2.2.0~9^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=refs%2Fpull%2F76%2Fhead;p=thirdparty%2Fpython-fints.git Let simple_sepa_transfer() automatically choose a SEPA PAIN version --- diff --git a/fints/client.py b/fints/client.py index 5814491..3d09332 100644 --- a/fints/client.py +++ b/fints/client.py @@ -681,6 +681,23 @@ class FinTS3Client: return responses + def _find_supported_sepa_version(self, candidate_versions): + hispas = self.bpd.find_segment_first('HISPAS') + if not hispas: + logger.warning("Could not determine supported SEPA versions, is the dialogue open? Defaulting to first candidate: %s.", candidate_versions[0]) + return candidate_versions[0] + + bank_supported = list(hispas.parameter.supported_sepa_formats) + + for candidate in candidate_versions: + if "urn:iso:std:iso:20022:tech:xsd:{}".format(candidate) in bank_supported: + return candidate + if "urn:iso:std:iso:20022:tech:xsd:{}.xsd".format(candidate) in bank_supported: + return candidate + + logger.warning("No common supported SEPA version. Defaulting to first candidate and hoping for the best: %s.", candidate_versions[0]) + return candidate_versions[0] + def simple_sepa_transfer(self, account: SEPAAccount, iban: str, bic: str, recipient_name: str, amount: Decimal, account_name: str, reason: str, endtoend_id='NOTPROVIDED'): @@ -704,7 +721,8 @@ class FinTS3Client: "batch": False, "currency": "EUR", } - sepa = SepaTransfer(config, 'pain.001.001.03') + version = self._find_supported_sepa_version(['pain.001.001.03', 'pain.001.003.03']) + sepa = SepaTransfer(config, version) payment = { "name": recipient_name, "IBAN": iban, @@ -716,7 +734,7 @@ class FinTS3Client: } sepa.add_payment(payment) xml = sepa.export().decode() - return self.sepa_transfer(account, xml) + return self.sepa_transfer(account, xml, pain_descriptor="urn:iso:std:iso:20022:tech:xsd:"+version) def sepa_transfer(self, account: SEPAAccount, pain_message: str, multiple=False, control_sum=None, currency='EUR', book_as_single=False,