diff options
author | Marcello Stanisci <stanisci.m@gmail.com> | 2020-03-31 15:10:42 +0200 |
---|---|---|
committer | Marcello Stanisci <stanisci.m@gmail.com> | 2020-03-31 15:10:42 +0200 |
commit | e03560814c0c3e7ce0ad4056c165efce6a32c4a6 (patch) | |
tree | a736c842cb6e6f19aa2b1e2e85900f3f0e6bf368 | |
parent | 854bb60a4db41f397b3ecc37b103a1045fab0a85 (diff) | |
download | libeufin-e03560814c0c3e7ce0ad4056c165efce6a32c4a6.tar.gz libeufin-e03560814c0c3e7ce0ad4056c165efce6a32c4a6.tar.bz2 libeufin-e03560814c0c3e7ce0ad4056c165efce6a32c4a6.zip |
Process raw payments into Taler table.
-rw-r--r-- | nexus/src/main/kotlin/tech/libeufin/nexus/DB.kt | 24 | ||||
-rw-r--r-- | nexus/src/main/kotlin/tech/libeufin/nexus/Main.kt | 43 |
2 files changed, 46 insertions, 21 deletions
diff --git a/nexus/src/main/kotlin/tech/libeufin/nexus/DB.kt b/nexus/src/main/kotlin/tech/libeufin/nexus/DB.kt index c20662fb..e15b2958 100644 --- a/nexus/src/main/kotlin/tech/libeufin/nexus/DB.kt +++ b/nexus/src/main/kotlin/tech/libeufin/nexus/DB.kt @@ -12,22 +12,17 @@ import java.sql.Connection const val ID_MAX_LENGTH = 50 -object ValidTalerIncomingPayments: LongIdTable() { +object TalerIncomingPayments: LongIdTable() { val payment = reference("payment", EbicsRawBankTransactionsTable) + val valid = bool("valid") + // avoid refunding twice! + val processed = bool("refunded").default(false) } -class ValidTalerIncomingPaymentEntry(id: EntityID<Long>) : LongEntity(id) { - companion object : LongEntityClass<ValidTalerIncomingPaymentEntry>(ValidTalerIncomingPayments) - var payment by EbicsRawBankTransactionEntry referencedOn ValidTalerIncomingPayments.payment -} - -object InvalidTalerIncomingPayments: LongIdTable() { - val payment = reference("payment", EbicsRawBankTransactionsTable) -} - -class InvalidTalerIncomingPaymentEntry(id: EntityID<Long>) : LongEntity(id) { - companion object : LongEntityClass<InvalidTalerIncomingPaymentEntry>(InvalidTalerIncomingPayments) - var payment by EbicsRawBankTransactionEntry referencedOn InvalidTalerIncomingPayments.payment +class TalerIncomingPaymentEntry(id: EntityID<Long>) : LongEntity(id) { + companion object : LongEntityClass<TalerIncomingPaymentEntry>(TalerIncomingPayments) + var payment by EbicsRawBankTransactionEntry referencedOn TalerIncomingPayments.payment + var valid by TalerIncomingPayments.valid } object EbicsRawBankTransactionsTable : LongIdTable() { @@ -153,8 +148,7 @@ fun dbCreateTables() { EbicsSubscribersTable, EbicsAccountsInfoTable, EbicsRawBankTransactionsTable, - ValidTalerIncomingPayments, - InvalidTalerIncomingPayments + TalerIncomingPayments ) } }
\ No newline at end of file diff --git a/nexus/src/main/kotlin/tech/libeufin/nexus/Main.kt b/nexus/src/main/kotlin/tech/libeufin/nexus/Main.kt index 35fc85f4..3c6e1798 100644 --- a/nexus/src/main/kotlin/tech/libeufin/nexus/Main.kt +++ b/nexus/src/main/kotlin/tech/libeufin/nexus/Main.kt @@ -39,6 +39,7 @@ import io.ktor.routing.post import io.ktor.routing.routing import io.ktor.server.engine.embeddedServer import io.ktor.server.netty.Netty +import net.taler.wallet.crypto.Base32Crockford import org.apache.commons.compress.archivers.zip.ZipFile import org.apache.commons.compress.utils.SeekableInMemoryByteChannel import org.jetbrains.exposed.exceptions.ExposedSQLException @@ -621,6 +622,7 @@ fun main() { // FIXME(florian): Download C52 and store the result in the right database table } + get("/ebics/subscribers/{id}/show-collected-transactions-c53") { val id = expectId(call.parameters["id"]) var ret = "" @@ -633,7 +635,6 @@ fun main() { ret += "###\nDebitor: ${it.debitorIban}\nCreditor: ${it.creditorIban}\nAmount: ${it.currency}:${it.amount}\nDate: ${it.bookingDate}\n" } } - call.respondText( ret, ContentType.Text.Plain, @@ -648,11 +649,42 @@ fun main() { * incoming transactions (those with a valid subject, i.e. a public key), * and invalid ones (the rest). */ - post("/ebics/admin/digest-incoming-transactions") { - + post("/ebics/subscribers/{id}/digest-incoming-transactions") { + val id = expectId(call.parameters["id"]) + // first find highest ID value of already processed rows. + transaction { + val latest = TalerIncomingPaymentEntry.all().sortedByDescending { + it.payment.id + }.firstOrNull() ?: throw NexusError( + HttpStatusCode.NotFound, "No payments to process" + ) + EbicsRawBankTransactionEntry.find { + EbicsRawBankTransactionsTable.id.greater(latest.id) and + (EbicsRawBankTransactionsTable.nexusSubscriber eq id) + }.forEach { + if (CryptoUtil.checkValidEddsaPublicKey( + Base32Crockford.decode(it.unstructuredRemittanceInformation) + ) + ) { + TalerIncomingPaymentEntry.new { + payment = it + valid = true + } + } else { + TalerIncomingPaymentEntry.new { + payment = it + valid = false + } + } + } + } + call.respondText ( + "New raw payments Taler-processed", + ContentType.Text.Plain, + HttpStatusCode.OK + ) + return@post } - - post("/ebics/subscribers/{id}/collect-transactions-c53") { val id = expectId(call.parameters["id"]) val paramsJson = call.receive<EbicsStandardOrderParamsJson>() @@ -784,7 +816,6 @@ fun main() { } } } - post("/ebics/subscribers/{id}/sendC53") { val id = expectId(call.parameters["id"]) val paramsJson = call.receive<EbicsStandardOrderParamsJson>() |