gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[libeufin] branch master updated: nexus: drafting pain.001 generation


From: gnunet
Subject: [libeufin] branch master updated: nexus: drafting pain.001 generation
Date: Wed, 25 Oct 2023 15:27:57 +0200

This is an automated email from the git hooks/post-receive script.

ms pushed a commit to branch master
in repository libeufin.

The following commit(s) were added to refs/heads/master by this push:
     new ce91844d nexus: drafting pain.001 generation
ce91844d is described below

commit ce91844da940b21187b13b5db08b1a19b4e536a5
Author: MS <ms@taler.net>
AuthorDate: Wed Oct 25 15:26:50 2023 +0200

    nexus: drafting pain.001 generation
---
 .../main/kotlin/tech/libeufin/nexus/Iso20022.kt    | 148 +++++++++++++++++++++
 .../tech/libeufin/nexus/{ => ebics}/Ebics3.kt      |   5 +-
 .../nexus/ebics/{Ebics.kt => EbicsCommon.kt}       |   0
 3 files changed, 152 insertions(+), 1 deletion(-)

diff --git a/nexus/src/main/kotlin/tech/libeufin/nexus/Iso20022.kt 
b/nexus/src/main/kotlin/tech/libeufin/nexus/Iso20022.kt
new file mode 100644
index 00000000..87e80d8e
--- /dev/null
+++ b/nexus/src/main/kotlin/tech/libeufin/nexus/Iso20022.kt
@@ -0,0 +1,148 @@
+package tech.libeufin.nexus
+
+import tech.libeufin.util.IbanPayto
+import tech.libeufin.util.constructXml
+import tech.libeufin.util.parsePayto
+import java.time.Instant
+import java.time.ZoneId
+import java.time.ZonedDateTime
+import java.time.format.DateTimeFormatter
+
+
+data class Pain001Namespaces(
+    val fullNamespace: String,
+    val xsdFilename: String
+)
+
+/**
+ * Create a pain.001 document.  It requires the debtor BIC.
+ *
+ * @param requestUid UID of this request, helps to make this request 
idempotent.
+ * @param debtorMetadataFile bank account information of the EBICS subscriber 
that
+ *                           sends this request.
+ * @param amount amount to pay.
+ * @param wireTransferSubject wire transfer subject.
+ * @param creditAccount payment receiver.
+ * @return raw pain.001 XML, or throws if the debtor BIC is not found.
+ */
+fun createPain001(
+    requestUid: String,
+    debtorMetadataFile: BankAccountMetadataFile,
+    amount: TalerAmount,
+    wireTransferSubject: String,
+    creditAccount: IbanPayto
+): String {
+    val namespace = Pain001Namespaces(
+        fullNamespace = "urn:iso:std:iso:20022:tech:xsd:pain.001.001.09",
+        xsdFilename = "pain.001.001.09.ch.03.xsd"
+    )
+    val creationTimestamp = Instant.now()
+    val amountWithoutCurrency: String = amount.toString().split(":").run {
+        if (this.size != 2) throw Exception("Invalid stringified amount: 
$amount")
+        return@run this[1]
+    }
+    if (debtorMetadataFile.bank_code == null)
+        throw Exception("Need debtor BIC, but not found in the debtor account 
metadata file.")
+
+    return constructXml(indent = true) {
+        root("Document") {
+            attribute("xmlns", namespace.fullNamespace)
+            attribute("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance";)
+            attribute(
+                "xsi:schemaLocation",
+                "${namespace.fullNamespace} ${namespace.xsdFilename}"
+            )
+            element("CstmrCdtTrfInitn") {
+                element("GrpHdr") {
+                    element("MsgId") {
+                        text(requestUid)
+                    }
+                    element("CreDtTm") {
+                        val dateFormatter = 
DateTimeFormatter.ISO_OFFSET_DATE_TIME
+                        val zoned = ZonedDateTime.ofInstant(
+                            creationTimestamp,
+                            ZoneId.systemDefault() // FIXME: should this be 
UTC?
+                        )
+                        text(dateFormatter.format(zoned))
+                    }
+                    element("NbOfTxs") {
+                        text("1")
+                    }
+                    element("CtrlSum") {
+                        text(amount.toString())
+                    }
+                    element("InitgPty/Nm") { // optional
+                        text(debtorMetadataFile.account_holder_name)
+                    }
+                }
+                element("PmtInf") {
+                    element("PmtInfId") {
+                        text("NOT GIVEN")
+                    }
+                    element("PmtMtd") {
+                        text("TRF")
+                    }
+                    element("BtchBookg") {
+                        text("true")
+                    }
+                    element("NbOfTxs") {
+                        text("1")
+                    }
+                    element("CtrlSum") {
+                        text(amount.toString())
+                    }
+                    element("PmtTpInf/SvcLvl/Cd") {
+                        text("SDVA")
+                    }
+                    element("ReqdExctnDt") {
+                        
text(DateTimeFormatter.ISO_DATE.format(creationTimestamp))
+                    }
+                    element("Dbtr/Nm") { // optional
+                        text(debtorMetadataFile.account_holder_name)
+                    }
+                    element("DbtrAcct/Id/IBAN") {
+                        text(debtorMetadataFile.account_holder_iban)
+                    }
+                    element("DbtrAgt/FinInstnId") {
+                        element("BICFI") {
+                            text(debtorMetadataFile.bank_code)
+                        }
+                    }
+                    element("ChrgBr") {
+                        text("SLEV")
+                    }
+                    element("CdtTrfTxInf") {
+                        element("PmtId") {
+                            element("InstrId") { text("NOT PROVIDED") }
+                            element("EndToEndId") { text("NOT PROVIDED") }
+                        }
+                        element("Amt/InstdAmt") {
+                            attribute("Ccy", amount.currency)
+                            text(amountWithoutCurrency)
+                        }
+                        creditAccount.bic.apply {
+                            if (this != null)
+                                element("CdtrAgt/FinInstnId") {
+                                    element("BICFI") {
+                                        text(this@apply)
+                                    }
+                                }
+                        }
+                        creditAccount.receiverName.apply {
+                            if (this != null)
+                                element("Cdtr/Nm") {
+                                    text(this@apply)
+                                }
+                        }
+                        element("CdtrAcct/Id/IBAN") {
+                            text(creditAccount.iban)
+                        }
+                        element("RmtInf/Ustrd") {
+                            text(wireTransferSubject)
+                        }
+                    }
+                }
+            }
+        }
+    }
+}
\ No newline at end of file
diff --git a/nexus/src/main/kotlin/tech/libeufin/nexus/Ebics3.kt 
b/nexus/src/main/kotlin/tech/libeufin/nexus/ebics/Ebics3.kt
similarity index 94%
rename from nexus/src/main/kotlin/tech/libeufin/nexus/Ebics3.kt
rename to nexus/src/main/kotlin/tech/libeufin/nexus/ebics/Ebics3.kt
index e94d8105..406eb9f4 100644
--- a/nexus/src/main/kotlin/tech/libeufin/nexus/Ebics3.kt
+++ b/nexus/src/main/kotlin/tech/libeufin/nexus/ebics/Ebics3.kt
@@ -1,5 +1,8 @@
-package tech.libeufin.nexus
+package tech.libeufin.nexus.ebics
 
+import tech.libeufin.nexus.BankPublicKeysFile
+import tech.libeufin.nexus.ClientPrivateKeysFile
+import tech.libeufin.nexus.EbicsSetupConfig
 import tech.libeufin.util.PreparedUploadData
 import tech.libeufin.util.XMLUtil
 import tech.libeufin.util.ebics_h005.Ebics3Request
diff --git a/nexus/src/main/kotlin/tech/libeufin/nexus/ebics/Ebics.kt 
b/nexus/src/main/kotlin/tech/libeufin/nexus/ebics/EbicsCommon.kt
similarity index 100%
rename from nexus/src/main/kotlin/tech/libeufin/nexus/ebics/Ebics.kt
rename to nexus/src/main/kotlin/tech/libeufin/nexus/ebics/EbicsCommon.kt

-- 
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]