]> git.ipfire.org Git - thirdparty/python-fints.git/commitdiff
Let simple_sepa_transfer() automatically choose a SEPA PAIN version 76/head
authorHenryk Plötz <henryk@ploetzli.ch>
Sat, 8 Jun 2019 18:19:17 +0000 (20:19 +0200)
committerHenryk Plötz <henryk@ploetzli.ch>
Sat, 8 Jun 2019 18:23:38 +0000 (20:23 +0200)
fints/client.py

index 5814491a9a8637d1a7315681ed9c8c9222e9436b..3d09332a5a25f4f2d8a63424373a1bf8095bc80a 100644 (file)
@@ -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,