gnunet-svn
[Top][All Lists]
Advanced

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

[libeufin] branch master updated (836f66b -> 51d1037)


From: gnunet
Subject: [libeufin] branch master updated (836f66b -> 51d1037)
Date: Wed, 26 Feb 2020 15:58:05 +0100

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

marcello pushed a change to branch master
in repository libeufin.

    from 836f66b  aspectratio
     new 59a4eed  Drafting PAIN generation.
     new 3f55c73  Filling PAIN document with more real data.
     new 51d1037  Testing PAIN.001 generation.

The 3 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 nexus/src/main/kotlin/tech/libeufin/nexus/Main.kt  | 124 +++++++++++++++++++++
 nexus/src/test/kotlin/DbTest.kt                    |   6 +-
 .../test/kotlin/{DbTest.kt => PainGeneration.kt}   |  44 ++++----
 3 files changed, 151 insertions(+), 23 deletions(-)
 copy nexus/src/test/kotlin/{DbTest.kt => PainGeneration.kt} (57%)

diff --git a/nexus/src/main/kotlin/tech/libeufin/nexus/Main.kt 
b/nexus/src/main/kotlin/tech/libeufin/nexus/Main.kt
index 167030e..85b60fc 100644
--- a/nexus/src/main/kotlin/tech/libeufin/nexus/Main.kt
+++ b/nexus/src/main/kotlin/tech/libeufin/nexus/Main.kt
@@ -46,6 +46,7 @@ import org.jetbrains.exposed.exceptions.ExposedSQLException
 import org.jetbrains.exposed.sql.StdOutSqlLogger
 import org.jetbrains.exposed.sql.addLogger
 import org.jetbrains.exposed.sql.transactions.transaction
+import org.joda.time.DateTime
 import org.slf4j.Logger
 import org.slf4j.LoggerFactory
 import org.slf4j.event.Level
@@ -166,6 +167,126 @@ data class Pain001Data(
     val subject: String
 )
 
+/**
+ * Create a PAIN.001 XML document according to the input data.
+ * Needs to be called within a transaction block.
+ */
+fun createPain001document(pain001Entity: Pain001Entity): String {
+
+    /**
+     * Every PAIN.001 document contains at least three IDs:
+     *
+     * 1) MsgId: a unique id for the message itself
+     * 2) PmtInfId: the unique id for the payment's set of information
+     * 3) EndToEndId: a unique id to be shared between the debtor and
+     *    creditor that uniquely identifies the transaction
+     *
+     * For now and for simplicity, since every PAIN entry in the database
+     * has a unique ID, and the three values aren't required to be mutually 
different,
+     * we'll assign the SAME id (= the row id) to all the three aforementioned
+     * PAIN id types.
+     */
+
+    val s = constructXml(indent = true) {
+        root("Document") {
+            element("CstmrCdtTrfInitn") {
+                element("GrpHdr") {
+                    element("MsgId") {
+                        text(pain001Entity.id.value.toString())
+                    }
+                    element("CreDtTm") {
+                        val dateMillis = transaction {
+                            pain001Entity.date
+                        }
+                        text(DateTime(dateMillis).toString("Y-M-d"))
+                    }
+                    element("NbOfTxs") {
+                        text("1")
+                    }
+                    element("CtrlSum") {
+                        text(pain001Entity.sum.toString())
+                    }
+                    element("InitgPty/Nm") {
+                        text(pain001Entity.debtorAccount)
+                    }
+                }
+                element("PmtInf") {
+                    element("PmtInfId") {
+                        text(pain001Entity.id.value.toString())
+                    }
+                    element("PmtMtd") {
+                        text("TRF")
+                    }
+                    element("BtchBookg") {
+                        text("true")
+                    }
+                    element("NbOfTxs") {
+                        text("1")
+                    }
+                    element("CtrlSum") {
+                        text(pain001Entity.sum.toString())
+                    }
+                    element("PmtTpInf/SvcLvl/Cd") {
+                        text("SEPA")
+                    }
+                    element("ReqdExctnDt") {
+                        val dateMillis = transaction {
+                            pain001Entity.date
+                        }
+                        text(DateTime(dateMillis).toString("Y-M-d"))
+                    }
+                    element("Dbtr/Nm") {
+                        text(pain001Entity.debtorAccount)
+                    }
+                    element("DbtrAcct/Id/IBAN") {
+                        text(transaction {
+                            
EbicsAccountInfoEntity.findById(pain001Entity.debtorAccount)?.iban ?: throw 
Exception(
+                            "Debtor IBAN not found in database"
+                            )
+                        })
+                    }
+                    element("DbtrAgt/FinInstnId/BIC") {
+
+                        text(transaction {
+                            
EbicsAccountInfoEntity.findById(pain001Entity.debtorAccount)?.bankCode ?: throw 
Exception(
+                                "Debtor BIC not found in database"
+                            )
+                        })
+                    }
+
+                    element("ChrgBr") {
+                        text("SLEV")
+                    }
+                    element("CdtTrfTxInf") {
+                        element("PmtId") {
+                            element("EndToEndId") {
+                                text(pain001Entity.id.value.toString())
+                            }
+                        }
+                        element("Amt/InstdAmt") {
+                            attribute("Ccy", "EUR")
+                            text(pain001Entity.sum.toString())
+                        }
+                        element("CdtrAgt/FinInstnId/BIC") {
+                            text(pain001Entity.creditorBic)
+                        }
+                        element("Cdtr/Nm") {
+                            text(pain001Entity.creditorName)
+                        }
+                        element("CdtrAcct/Id/IBAN") {
+                            text(pain001Entity.creditorIban)
+                        }
+                        element("RmtInf/Ustrd") {
+                            text(pain001Entity.subject)
+                        }
+                    }
+                }
+            }
+        }
+    }
+    return s
+}
+
 /**
  * Insert one row in the database, and leaves it marked as non-submitted.
  */
@@ -365,6 +486,9 @@ fun main() {
                 return@get
             }
 
+            /* need primitive that crawls the database of pending payments and 
generates PAIN.001
+            * after those.  */
+
             post("/ebics/subscribers/{id}/accounts/{acctid}/prepare-payment") {
                 val acctid = expectId(call.parameters["acctid"])
                 val subscriberId = expectId(call.parameters["id"])
diff --git a/nexus/src/test/kotlin/DbTest.kt b/nexus/src/test/kotlin/DbTest.kt
index e79b783..c442889 100644
--- a/nexus/src/test/kotlin/DbTest.kt
+++ b/nexus/src/test/kotlin/DbTest.kt
@@ -43,14 +43,14 @@ class DbTest {
     @Test
     fun testPain001() {
         createPain001entry(
-            Pain001Entry(
-                debtorAccountId = "da",
+            Pain001Data(
                 creditorBic = "cb",
                 creditorIban = "ci",
                 creditorName = "cn",
                 sum = Amount(2),
                 subject = "s"
-            )
+            ),
+            "debtor acctid"
         )
     }
 }
\ No newline at end of file
diff --git a/nexus/src/test/kotlin/DbTest.kt 
b/nexus/src/test/kotlin/PainGeneration.kt
similarity index 57%
copy from nexus/src/test/kotlin/DbTest.kt
copy to nexus/src/test/kotlin/PainGeneration.kt
index e79b783..05db5bb 100644
--- a/nexus/src/test/kotlin/DbTest.kt
+++ b/nexus/src/test/kotlin/PainGeneration.kt
@@ -12,21 +12,18 @@ import tech.libeufin.util.Amount
 import javax.sql.rowset.serial.SerialBlob
 
 
-class DbTest {
+
+class PainTest {
 
     @Before
-    fun connectAndMakeTables() {
+    fun prepare() {
         Database.connect("jdbc:h2:mem:test;DB_CLOSE_DELAY=-1", driver = 
"org.h2.Driver")
         transaction {
             SchemaUtils.create(EbicsSubscribersTable)
+            SchemaUtils.create(EbicsAccountsInfoTable)
             SchemaUtils.create(Pain001Table)
-        }
-    }
 
-    @Test
-    fun makeCustomer() {
-        transaction {
-            EbicsSubscriberEntity.new(id = "123asdf") {
+            val subscriberEntity = EbicsSubscriberEntity.new(id = "123asdf") {
                 ebicsURL = "ebics url"
                 hostID = "host"
                 partnerID = "partner"
@@ -36,21 +33,28 @@ class DbTest {
                 authenticationPrivateKey = 
SerialBlob("authenticationPrivateKey".toByteArray())
                 encryptionPrivateKey = 
SerialBlob("encryptionPrivateKey".toByteArray())
             }
-            assert(EbicsSubscriberEntity.findById("123asdf") != null)
+            EbicsAccountInfoEntity.new(id = "acctid") {
+                subscriber = subscriberEntity
+                accountHolder = "Account Holder"
+                iban = "IBAN"
+                bankCode = "BIC"
+            }
         }
     }
 
     @Test
-    fun testPain001() {
-        createPain001entry(
-            Pain001Entry(
-                debtorAccountId = "da",
-                creditorBic = "cb",
-                creditorIban = "ci",
-                creditorName = "cn",
-                sum = Amount(2),
-                subject = "s"
-            )
-        )
+    fun testPain001document() {
+        transaction {
+            val pain001Entity = Pain001Entity.new {
+                sum = Amount(1)
+                debtorAccount = "acctid"
+                subject = "subject line"
+                creditorIban = "CREDIT IBAN"
+                creditorBic = "CREDIT BIC"
+                creditorName = "CREDIT NAME"
+            }
+            val s = createPain001document(pain001Entity)
+            println(s)
+        }
     }
 }
\ No newline at end of file

-- 
To stop receiving notification emails like this one, please contact
address@hidden.



reply via email to

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