gnunet-svn
[Top][All Lists]
Advanced

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

[libeufin] branch master updated: drafting task to submit payments


From: gnunet
Subject: [libeufin] branch master updated: drafting task to submit payments
Date: Sat, 06 Jun 2020 01:26:00 +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 30df1e0  drafting task to submit payments
30df1e0 is described below

commit 30df1e0c3d84ccaace6c01a25451eb51a6796387
Author: MS <ms@taler.net>
AuthorDate: Sat Jun 6 01:25:37 2020 +0200

    drafting task to submit payments
---
 nexus/src/main/kotlin/tech/libeufin/nexus/DB.kt    |  2 +-
 nexus/src/main/kotlin/tech/libeufin/nexus/Main.kt  |  4 +-
 nexus/src/main/kotlin/tech/libeufin/nexus/taler.kt | 52 ++++++++++++++++++++--
 3 files changed, 51 insertions(+), 7 deletions(-)

diff --git a/nexus/src/main/kotlin/tech/libeufin/nexus/DB.kt 
b/nexus/src/main/kotlin/tech/libeufin/nexus/DB.kt
index 193c1ef..67e09e8 100644
--- a/nexus/src/main/kotlin/tech/libeufin/nexus/DB.kt
+++ b/nexus/src/main/kotlin/tech/libeufin/nexus/DB.kt
@@ -234,7 +234,7 @@ class EbicsSubscriberEntity(id: EntityID<Int>) : 
IntEntity(id) {
     var authenticationPrivateKey by 
EbicsSubscribersTable.authenticationPrivateKey
     var bankEncryptionPublicKey by 
EbicsSubscribersTable.bankEncryptionPublicKey
     var bankAuthenticationPublicKey by 
EbicsSubscribersTable.bankAuthenticationPublicKey
-    var nexusBankConnection by NexusBankConnectionEntity referencedOn  
EbicsSubscribersTable.nexusBankConnection
+    var nexusBankConnection by NexusBankConnectionEntity referencedOn 
EbicsSubscribersTable.nexusBankConnection
     var ebicsIniState by EbicsSubscribersTable.ebicsIniState
     var ebicsHiaState by EbicsSubscribersTable.ebicsHiaState
 }
diff --git a/nexus/src/main/kotlin/tech/libeufin/nexus/Main.kt 
b/nexus/src/main/kotlin/tech/libeufin/nexus/Main.kt
index 901db99..3809708 100644
--- a/nexus/src/main/kotlin/tech/libeufin/nexus/Main.kt
+++ b/nexus/src/main/kotlin/tech/libeufin/nexus/Main.kt
@@ -540,9 +540,7 @@ fun serverMain(dbName: String) {
                         throw NexusError(HttpStatusCode.NotFound, "unknown 
bank account")
                     }
                     val defaultBankConnection = 
bankAccount.defaultBankConnection
-                    if (defaultBankConnection == null) {
-                        throw NexusError(HttpStatusCode.NotFound, "needs a 
default connection")
-                    }
+                        ?: throw NexusError(HttpStatusCode.NotFound, "needs a 
default connection")
                     val subscriberDetails = 
getEbicsSubscriberDetails(user.id.value, defaultBankConnection.id.value)
                     return@transaction object {
                         val pain001document = 
createPain001document(preparedPayment)
diff --git a/nexus/src/main/kotlin/tech/libeufin/nexus/taler.kt 
b/nexus/src/main/kotlin/tech/libeufin/nexus/taler.kt
index 7a74d09..15e45be 100644
--- a/nexus/src/main/kotlin/tech/libeufin/nexus/taler.kt
+++ b/nexus/src/main/kotlin/tech/libeufin/nexus/taler.kt
@@ -19,9 +19,8 @@ import org.jetbrains.exposed.dao.Entity
 import org.jetbrains.exposed.dao.id.IdTable
 import org.jetbrains.exposed.sql.*
 import org.jetbrains.exposed.sql.transactions.transaction
-import tech.libeufin.util.CryptoUtil
-import tech.libeufin.util.EbicsProtocolError
-import tech.libeufin.util.parseAmount
+import org.w3c.dom.Document
+import tech.libeufin.util.*
 import kotlin.math.abs
 import kotlin.math.min
 
@@ -371,6 +370,53 @@ suspend fun talerAddIncoming(call: ApplicationCall): Unit {
     )
 }
 
+// submits ALL the prepared payments from ALL the Taler facades.
+suspend fun submitPreparedPaymentsViaEbics() {
+    data class EbicsSubmission(
+        val subscriberDetails: EbicsClientSubscriberDetails,
+        val pain001document: String
+    )
+    val workQueue = mutableListOf<EbicsSubmission>()
+    transaction {
+        TalerFacadeStateEntity.all().forEach {
+            val bankConnection = 
NexusBankConnectionEntity.findById(it.bankConnection) ?: throw NexusError(
+                HttpStatusCode.InternalServerError,
+                "Such facade '${it.facade.id.value}' doesn't map to any bank 
connection (named '${it.bankConnection}')"
+            )
+            if (bankConnection.type != "ebics") {
+                logger.info("Skipping non-implemented bank connection 
'${bankConnection.type}'")
+                return@forEach
+            }
+
+            val subscriberEntity = EbicsSubscriberEntity.find {
+                EbicsSubscribersTable.nexusBankConnection eq it.bankConnection
+            }.firstOrNull() ?: throw NexusError(
+                HttpStatusCode.InternalServerError,
+                "Such facade '${it.facade.id.value}' doesn't map to any Ebics 
subscriber"
+            )
+            val bankAccount: NexusBankAccountEntity = 
NexusBankAccountEntity.findById(it.bankAccount) ?: throw NexusError(
+                HttpStatusCode.InternalServerError,
+                "Bank account '${it.bankAccount}' not found for facade 
'${it.id.value}'"
+            )
+            PreparedPaymentEntity.find { PreparedPaymentsTable.debitorIban eq 
bankAccount.iban }.forEach {
+                val pain001document = createPain001document(it)
+                val subscriberDetails = 
getEbicsSubscriberDetailsInternal(subscriberEntity)
+                workQueue.add(EbicsSubmission(subscriberDetails, 
pain001document))
+            }
+        }
+    }
+    val httpClient = HttpClient()
+    workQueue.forEach {
+        doEbicsUploadTransaction(
+            httpClient,
+            it.subscriberDetails,
+            "CCT",
+            it.pain001document.toByteArray(Charsets.UTF_8),
+            EbicsStandardOrderParams()
+        )
+    }
+}
+
 /**
  * Crawls the database to find ALL the users that have a Taler
  * facade and process their histories respecting the TWG policy.

-- 
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]