libeufin

Integration and sandbox testing for FinTech APIs and data formats
Log | Files | Refs | Submodules | README | LICENSE

commit 30df1e0c3d84ccaace6c01a25451eb51a6796387
parent 74c2a6c0e9b3ed17fdb8bd3abd1325edcd662d07
Author: MS <ms@taler.net>
Date:   Sat,  6 Jun 2020 01:25:37 +0200

drafting task to submit payments

Diffstat:
Mnexus/src/main/kotlin/tech/libeufin/nexus/DB.kt | 2+-
Mnexus/src/main/kotlin/tech/libeufin/nexus/Main.kt | 4+---
Mnexus/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 @@ -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 @@ -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 @@ -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.