summaryrefslogtreecommitdiff
path: root/nexus/src/main/kotlin/tech/libeufin/nexus/taler.kt
diff options
context:
space:
mode:
authorMS <ms@taler.net>2020-06-06 01:25:37 +0200
committerMS <ms@taler.net>2020-06-06 01:25:37 +0200
commit30df1e0c3d84ccaace6c01a25451eb51a6796387 (patch)
tree599156f1680a5753001f589a4d83b0e3a7fbcdf8 /nexus/src/main/kotlin/tech/libeufin/nexus/taler.kt
parent74c2a6c0e9b3ed17fdb8bd3abd1325edcd662d07 (diff)
downloadlibeufin-30df1e0c3d84ccaace6c01a25451eb51a6796387.tar.gz
libeufin-30df1e0c3d84ccaace6c01a25451eb51a6796387.tar.bz2
libeufin-30df1e0c3d84ccaace6c01a25451eb51a6796387.zip
drafting task to submit payments
Diffstat (limited to 'nexus/src/main/kotlin/tech/libeufin/nexus/taler.kt')
-rw-r--r--nexus/src/main/kotlin/tech/libeufin/nexus/taler.kt52
1 files changed, 49 insertions, 3 deletions
diff --git a/nexus/src/main/kotlin/tech/libeufin/nexus/taler.kt b/nexus/src/main/kotlin/tech/libeufin/nexus/taler.kt
index 7a74d09b..15e45bed 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.