diff options
author | Marcello Stanisci <ms@taler.net> | 2020-05-09 14:06:29 +0200 |
---|---|---|
committer | Marcello Stanisci <ms@taler.net> | 2020-05-09 14:06:29 +0200 |
commit | d0a36f7518e7a4a8b46c4f7464a6a180f52a4cb0 (patch) | |
tree | a85ee8a38442f484b99c976b41bfba27d1ea9957 /nexus/src/main | |
parent | 4b42c655325ab5c69e776d7aec7cb6b2e42c79c9 (diff) | |
download | libeufin-d0a36f7518e7a4a8b46c4f7464a6a180f52a4cb0.tar.gz libeufin-d0a36f7518e7a4a8b46c4f7464a6a180f52a4cb0.tar.bz2 libeufin-d0a36f7518e7a4a8b46c4f7464a6a180f52a4cb0.zip |
API migration
Diffstat (limited to 'nexus/src/main')
-rw-r--r-- | nexus/src/main/kotlin/tech/libeufin/nexus/DB.kt | 62 | ||||
-rw-r--r-- | nexus/src/main/kotlin/tech/libeufin/nexus/Helpers.kt | 114 | ||||
-rw-r--r-- | nexus/src/main/kotlin/tech/libeufin/nexus/JSON.kt | 21 | ||||
-rw-r--r-- | nexus/src/main/kotlin/tech/libeufin/nexus/Main.kt | 81 | ||||
-rw-r--r-- | nexus/src/main/kotlin/tech/libeufin/nexus/MainDeprecated.kt | 14 | ||||
-rw-r--r-- | nexus/src/main/kotlin/tech/libeufin/nexus/taler.kt | 4 |
6 files changed, 170 insertions, 126 deletions
diff --git a/nexus/src/main/kotlin/tech/libeufin/nexus/DB.kt b/nexus/src/main/kotlin/tech/libeufin/nexus/DB.kt index ba5f7f85..8d47c84b 100644 --- a/nexus/src/main/kotlin/tech/libeufin/nexus/DB.kt +++ b/nexus/src/main/kotlin/tech/libeufin/nexus/DB.kt @@ -5,8 +5,6 @@ import org.jetbrains.exposed.dao.* import org.jetbrains.exposed.sql.* import org.jetbrains.exposed.sql.transactions.TransactionManager import org.jetbrains.exposed.sql.transactions.transaction -import tech.libeufin.nexus.BankAccountsTable.entityId -import tech.libeufin.nexus.BankAccountsTable.primaryKey import tech.libeufin.util.amount import java.sql.Connection @@ -19,7 +17,7 @@ const val ID_MAX_LENGTH = 50 * in the PAIN-table. */ object TalerRequestedPayments: LongIdTable() { - val preparedPayment = reference("payment", Pain001Table) + val preparedPayment = reference("payment", PreparedPaymentsTable) val requestUId = text("request_uid") val amount = text("amount") val exchangeBaseUrl = text("exchange_base_url") @@ -34,7 +32,7 @@ object TalerRequestedPayments: LongIdTable() { class TalerRequestedPaymentEntity(id: EntityID<Long>) : LongEntity(id) { companion object : LongEntityClass<TalerRequestedPaymentEntity>(TalerRequestedPayments) - var preparedPayment by Pain001Entity referencedOn TalerRequestedPayments.preparedPayment + var preparedPayment by PreparedPaymentEntity referencedOn TalerRequestedPayments.preparedPayment var requestUId by TalerRequestedPayments.requestUId var amount by TalerRequestedPayments.amount var exchangeBaseUrl by TalerRequestedPayments.exchangeBaseUrl @@ -91,11 +89,9 @@ object RawBankTransactionsTable : LongIdTable() { val transactionType = text("transactionType") /* DBIT or CRDT */ val currency = text("currency") val amount = text("amount") - val creditorIban = text("creditorIban") - val creditorName = text("creditorBic") - val debitorIban = text("debitorIban") - val debitorName = text("debitorName") + val counterpartIban = text("counterpartIban") val counterpartBic = text("counterpartBic") + val counterpartName = text("counterpartName") val bookingDate = long("bookingDate") val status = text("status") // BOOK or other. } @@ -107,11 +103,9 @@ class RawBankTransactionEntity(id: EntityID<Long>) : LongEntity(id) { var transactionType by RawBankTransactionsTable.transactionType var currency by RawBankTransactionsTable.currency var amount by RawBankTransactionsTable.amount - var debitorIban by RawBankTransactionsTable.debitorIban - var debitorName by RawBankTransactionsTable.debitorName - var creditorName by RawBankTransactionsTable.creditorName - var creditorIban by RawBankTransactionsTable.creditorIban + var counterpartIban by RawBankTransactionsTable.counterpartIban var counterpartBic by RawBankTransactionsTable.counterpartBic + var counterpartName by RawBankTransactionsTable.counterpartName var bookingDate by RawBankTransactionsTable.bookingDate var nexusUser by NexusUserEntity referencedOn RawBankTransactionsTable.nexusUser var status by RawBankTransactionsTable.status @@ -119,10 +113,12 @@ class RawBankTransactionEntity(id: EntityID<Long>) : LongEntity(id) { /** * Represent a prepare payment. */ -object Pain001Table : IdTable<String>() { +object PreparedPaymentsTable : IdTable<String>() { + /** the UUID representing this payment in the system */ override val id = BankAccountsTable.varchar("id", ID_MAX_LENGTH).entityId().primaryKey() val paymentId = long("paymentId") - val fileDate = long("fileDate") + val preparationDate = long("preparationDate") + val submissionDate = long("submissionDate").nullable() val sum = amount("sum") val currency = varchar("currency", length = 3).default("EUR") val endToEndId = long("EndToEndId") @@ -139,25 +135,27 @@ object Pain001Table : IdTable<String>() { * this state can be reached when the payment gets listed in a CRZ * response OR when the payment doesn't show up in a C52/C53 response */ val invalid = bool("invalid").default(false) + /** never really used, but it makes sure the user always exists */ val nexusUser = reference("nexusUser", NexusUsersTable) } -class Pain001Entity(id: EntityID<String>) : Entity<String>(id) { - companion object : EntityClass<String, Pain001Entity>(Pain001Table) - var paymentId by Pain001Table.paymentId - var date by Pain001Table.fileDate - var sum by Pain001Table.sum - var currency by Pain001Table.currency - var debitorIban by Pain001Table.debitorIban - var debitorBic by Pain001Table.debitorBic - var debitorName by Pain001Table.debitorName - var endToEndId by Pain001Table.endToEndId - var subject by Pain001Table.subject - var creditorIban by Pain001Table.creditorIban - var creditorBic by Pain001Table.creditorBic - var creditorName by Pain001Table.creditorName - var submitted by Pain001Table.submitted - var invalid by Pain001Table.invalid - var nexusUser by NexusUserEntity referencedOn Pain001Table.nexusUser +class PreparedPaymentEntity(id: EntityID<String>) : Entity<String>(id) { + companion object : EntityClass<String, PreparedPaymentEntity>(PreparedPaymentsTable) + var paymentId by PreparedPaymentsTable.paymentId + var preparationDate by PreparedPaymentsTable.preparationDate + var submissionDate by PreparedPaymentsTable.submissionDate + var sum by PreparedPaymentsTable.sum + var currency by PreparedPaymentsTable.currency + var debitorIban by PreparedPaymentsTable.debitorIban + var debitorBic by PreparedPaymentsTable.debitorBic + var debitorName by PreparedPaymentsTable.debitorName + var endToEndId by PreparedPaymentsTable.endToEndId + var subject by PreparedPaymentsTable.subject + var creditorIban by PreparedPaymentsTable.creditorIban + var creditorBic by PreparedPaymentsTable.creditorBic + var creditorName by PreparedPaymentsTable.creditorName + var submitted by PreparedPaymentsTable.submitted + var invalid by PreparedPaymentsTable.invalid + var nexusUser by NexusUserEntity referencedOn PreparedPaymentsTable.nexusUser } /** @@ -236,7 +234,7 @@ fun dbCreateTables() { transaction { addLogger(StdOutSqlLogger) SchemaUtils.create( - Pain001Table, + PreparedPaymentsTable, EbicsSubscribersTable, BankAccountsTable, RawBankTransactionsTable, diff --git a/nexus/src/main/kotlin/tech/libeufin/nexus/Helpers.kt b/nexus/src/main/kotlin/tech/libeufin/nexus/Helpers.kt index 7994558c..2b5eb663 100644 --- a/nexus/src/main/kotlin/tech/libeufin/nexus/Helpers.kt +++ b/nexus/src/main/kotlin/tech/libeufin/nexus/Helpers.kt @@ -1,11 +1,9 @@ package tech.libeufin.nexus -import io.ktor.application.ApplicationCall import io.ktor.http.HttpStatusCode import org.jetbrains.exposed.sql.and import org.jetbrains.exposed.sql.transactions.transaction import org.joda.time.DateTime -import org.joda.time.format.DateTimeFormat import tech.libeufin.util.Amount import tech.libeufin.util.CryptoUtil import tech.libeufin.util.EbicsClientSubscriberDetails @@ -61,33 +59,19 @@ fun extractFirstBic(bankCodes: List<EbicsTypes.AbstractBankCode>?): String? { return null } -fun getBankAccount(id: String): BankAccountEntity { - return transaction { - BankAccountEntity.findById(id) - } ?: throw NexusError( - HttpStatusCode.NotFound, - "Bank account '$id' not found" - ) -} - /** - * Given a nexus user id, returns the _list_ of bank accounts associated to it. - * - * @param id the subscriber id - * @return the bank account associated with this user. Can/should be adapted to - * return multiple bank accounts. + * Retrieve bank account details, only if user owns it. */ -fun getBankAccountFromNexusUserId(id: String): BankAccountEntity { - logger.debug("Looking up bank account of user '$id'") - val map = transaction { - BankAccountMapEntity.find { - BankAccountMapsTable.nexusUser eq id - } - }.firstOrNull() ?: throw NexusError( +fun getBankAccount(userId: String, accountId: String): BankAccountEntity { + return transaction { + val bankAccountMap = BankAccountMapEntity.find { + BankAccountMapsTable.nexusUser eq userId + }.firstOrNull() ?: throw NexusError( HttpStatusCode.NotFound, - "Such user '$id' does not have any bank account associated" - ) - return map.bankAccount + "Bank account '$accountId' not found" + ) + bankAccountMap.bankAccount + } } /** @@ -165,7 +149,7 @@ fun getSubscriberDetailsFromNexusUserId(id: String): EbicsClientSubscriberDetail * Create a PAIN.001 XML document according to the input data. * Needs to be called within a transaction block. */ -fun createPain001document(pain001Entity: Pain001Entity): String { +fun createPain001document(paymentData: PreparedPaymentEntity): String { /** * Every PAIN.001 document contains at least three IDs: * @@ -181,8 +165,8 @@ fun createPain001document(pain001Entity: Pain001Entity): String { */ val debitorBankAccountLabel = transaction { val debitorBankAcount = BankAccountEntity.find { - BankAccountsTable.iban eq pain001Entity.debitorIban and - (BankAccountsTable.bankCode eq pain001Entity.debitorBic) + BankAccountsTable.iban eq paymentData.debitorIban and + (BankAccountsTable.bankCode eq paymentData.debitorBic) }.firstOrNull() ?: throw NexusError( HttpStatusCode.NotFound, "Please download bank accounts details first (HTD)" @@ -198,11 +182,11 @@ fun createPain001document(pain001Entity: Pain001Entity): String { element("CstmrCdtTrfInitn") { element("GrpHdr") { element("MsgId") { - text(pain001Entity.id.value.toString()) + text(paymentData.id.value.toString()) } element("CreDtTm") { val dateMillis = transaction { - pain001Entity.date + paymentData.preparationDate } val dateFormatter = DateTimeFormatter.ISO_OFFSET_DATE_TIME val instant = Instant.ofEpochSecond(dateMillis / 1000) @@ -213,7 +197,7 @@ fun createPain001document(pain001Entity: Pain001Entity): String { text("1") } element("CtrlSum") { - text(pain001Entity.sum.toString()) + text(paymentData.sum.toString()) } element("InitgPty/Nm") { text(debitorBankAccountLabel) @@ -221,7 +205,7 @@ fun createPain001document(pain001Entity: Pain001Entity): String { } element("PmtInf") { element("PmtInfId") { - text(pain001Entity.id.value.toString()) + text(paymentData.id.value.toString()) } element("PmtMtd") { text("TRF") @@ -233,14 +217,14 @@ fun createPain001document(pain001Entity: Pain001Entity): String { text("1") } element("CtrlSum") { - text(pain001Entity.sum.toString()) + text(paymentData.sum.toString()) } element("PmtTpInf/SvcLvl/Cd") { text("SEPA") } element("ReqdExctnDt") { val dateMillis = transaction { - pain001Entity.date + paymentData.preparationDate } text(DateTime(dateMillis).toString("Y-MM-dd")) } @@ -248,10 +232,10 @@ fun createPain001document(pain001Entity: Pain001Entity): String { text(debitorBankAccountLabel) } element("DbtrAcct/Id/IBAN") { - text(pain001Entity.debitorIban) + text(paymentData.debitorIban) } element("DbtrAgt/FinInstnId/BIC") { - text(pain001Entity.debitorBic) + text(paymentData.debitorBic) } element("ChrgBr") { text("SLEV") @@ -264,20 +248,20 @@ fun createPain001document(pain001Entity: Pain001Entity): String { } } element("Amt/InstdAmt") { - attribute("Ccy", pain001Entity.currency) - text(pain001Entity.sum.toString()) + attribute("Ccy", paymentData.currency) + text(paymentData.sum.toString()) } element("CdtrAgt/FinInstnId/BIC") { - text(pain001Entity.creditorBic) + text(paymentData.creditorBic) } element("Cdtr/Nm") { - text(pain001Entity.creditorName) + text(paymentData.creditorName) } element("CdtrAcct/Id/IBAN") { - text(pain001Entity.creditorIban) + text(paymentData.creditorIban) } element("RmtInf/Ustrd") { - text(pain001Entity.subject) + text(paymentData.subject) } } } @@ -288,25 +272,39 @@ fun createPain001document(pain001Entity: Pain001Entity): String { } /** + * Retrieve prepared payment from database, raising exception + * if not found. + */ +fun getPreparedPayment(uuid: String): PreparedPaymentEntity { + return transaction { + PreparedPaymentEntity.findById(uuid) + } ?: throw NexusError( + HttpStatusCode.NotFound, + "Payment '$uuid' not found" + ) +} + +/** * Insert one row in the database, and leaves it marked as non-submitted. * @param debtorAccountId the mnemonic id assigned by the bank to one bank * account of the subscriber that is creating the pain entity. In this case, * it will be the account whose money will pay the wire transfer being defined * by this pain document. */ -fun createPain001entity(entry: Pain001Data, nexusUser: NexusUserEntity): Pain001Entity { +fun addPreparedPayment(paymentData: Pain001Data, nexusUser: NexusUserEntity): PreparedPaymentEntity { val randomId = Random().nextLong() return transaction { - Pain001Entity.new(randomId.toString()) { - subject = entry.subject - sum = entry.sum - debitorIban = entry.debitorIban - debitorBic = entry.debitorBic - debitorName = entry.debitorName - creditorName = entry.creditorName - creditorBic = entry.creditorBic - creditorIban = entry.creditorIban - date = DateTime.now().millis + val debitorAccount = getBankAccount(nexusUser.id.value, paymentData.debitorAccount) + PreparedPaymentEntity.new(randomId.toString()) { + subject = paymentData.subject + sum = paymentData.sum + debitorIban = debitorAccount.iban + debitorBic = debitorAccount.bankCode + debitorName = debitorAccount.accountHolder + creditorName = paymentData.creditorName + creditorBic = paymentData.creditorBic + creditorIban = paymentData.creditorIban + preparationDate = DateTime.now().millis paymentId = randomId endToEndId = randomId this.nexusUser = nexusUser @@ -331,14 +329,6 @@ fun extractNexusUser(param: String?): NexusUserEntity { } } -/* Needs a transaction{} block to be called */ -fun expectAcctidTransaction(param: String?): BankAccountEntity { - if (param == null) { - throw NexusError(HttpStatusCode.BadRequest, "Null Acctid given") - } - return BankAccountEntity.findById(param) ?: throw NexusError(HttpStatusCode.NotFound, "Account: $param not found") -} - /** * This helper function parses a Authorization:-header line, decode the credentials * and returns a pair made of username and hashed (sha256) password. The hashed value diff --git a/nexus/src/main/kotlin/tech/libeufin/nexus/JSON.kt b/nexus/src/main/kotlin/tech/libeufin/nexus/JSON.kt index eca99883..b0613b49 100644 --- a/nexus/src/main/kotlin/tech/libeufin/nexus/JSON.kt +++ b/nexus/src/main/kotlin/tech/libeufin/nexus/JSON.kt @@ -95,6 +95,19 @@ data class RawPayments( * API types (used as requests/responses types) * *************************************************/ +/** Response type of "GET /prepared-payments/{uuid}" */ +data class PaymentStatus( + val uuid: String, + val submitted: Boolean, + val creditorIban: String, + val creditorBic: String, + val creditorName: String, + val amount: String, + val subject: String, + val submissionDate: String, + val preparationDate: String +) + /** Response type of "GET /collected-transactions" */ data class Transaction( val account: String, @@ -106,6 +119,10 @@ data class Transaction( val date: String ) +data class Transactions( + val transactions: MutableList<Transaction> +) + /** Request type of "POST /prepared-payments/submit" */ data class SubmitPayment( val uuid: String, @@ -167,9 +184,7 @@ data class Pain001Data( val creditorIban: String, val creditorBic: String, val creditorName: String, - val debitorIban: String, - val debitorBic: String, - val debitorName: String, + val debitorAccount: String, val sum: Amount, val currency: String, val subject: String diff --git a/nexus/src/main/kotlin/tech/libeufin/nexus/Main.kt b/nexus/src/main/kotlin/tech/libeufin/nexus/Main.kt index cdb19f75..1a33c5ff 100644 --- a/nexus/src/main/kotlin/tech/libeufin/nexus/Main.kt +++ b/nexus/src/main/kotlin/tech/libeufin/nexus/Main.kt @@ -50,12 +50,8 @@ import org.slf4j.Logger import org.slf4j.LoggerFactory import org.slf4j.event.Level import tech.libeufin.util.* -import tech.libeufin.util.ebics_h004.HTDResponseOrderData import java.text.DateFormat -import java.text.SimpleDateFormat -import java.util.* import java.util.zip.InflaterInputStream -import javax.crypto.EncryptedPrivateKeyInfo import javax.sql.rowset.serial.SerialBlob data class NexusError(val statusCode: HttpStatusCode, val reason: String) : Exception() @@ -187,11 +183,10 @@ fun main() { post("/bank-accounts/{accountid}/prepared-payments/submit") { val userId = authenticateRequest(call.request.headers["Authorization"]) val body = call.receive<SubmitPayment>() - val preparedPayment = transaction { - Pain001Entity.findById(body.uuid) - } ?: throw NexusError( - HttpStatusCode.NotFound, - "Could not find prepared payment: ${body.uuid}" + val preparedPayment = getPreparedPayment(body.uuid) + if (preparedPayment.nexusUser.id.value != userId) throw NexusError( + HttpStatusCode.Forbidden, + "No rights over such payment" ) if (preparedPayment.submitted) { throw NexusError( @@ -213,7 +208,7 @@ fun main() { ) /** mark payment as 'submitted' */ transaction { - val payment = Pain001Entity.findById(body.uuid) ?: throw NexusError( + val payment = PreparedPaymentEntity.findById(body.uuid) ?: throw NexusError( HttpStatusCode.InternalServerError, "Severe internal error: could not find payment in DB after having submitted it to the bank" ) @@ -224,6 +219,7 @@ fun main() { ContentType.Text.Plain, HttpStatusCode.OK ) + preparedPayment.submissionDate = DateTime.now().millis } else -> throw NexusError( HttpStatusCode.NotImplemented, @@ -236,6 +232,25 @@ fun main() { * Shows information about one particular prepared payment. */ get("/bank-accounts/{accountid}/prepared-payments/{uuid}") { + val userId = authenticateRequest(call.request.headers["Authorization"]) + val preparedPayment = getPreparedPayment(expectId(call.parameters["uuid"])) + if (preparedPayment.nexusUser.id.value != userId) throw NexusError( + HttpStatusCode.Forbidden, + "No rights over such payment" + ) + call.respond( + PaymentStatus( + uuid = preparedPayment.id.value, + submitted = preparedPayment.submitted, + creditorName = preparedPayment.creditorName, + creditorBic = preparedPayment.creditorBic, + creditorIban = preparedPayment.creditorIban, + amount = "${preparedPayment.sum}:${preparedPayment.currency}", + subject = preparedPayment.subject, + submissionDate = DateTime(preparedPayment.submissionDate).toDashedDate(), + preparationDate = DateTime(preparedPayment.preparationDate).toDashedDate() + ) + ) return@get } /** @@ -243,17 +258,15 @@ fun main() { */ post("/bank-accounts/{accountid}/prepared-payments") { val userId = authenticateRequest(call.request.headers["Authorization"]) + val bankAccount = getBankAccount(userId, expectId(call.parameters["accountid"])) val body = call.receive<PreparedPaymentRequest>() - val debitBankAccount = getBankAccount(expectId(call.parameters["accountid"])) val amount = parseAmount(body.amount) - val paymentEntity = createPain001entity( + val paymentEntity = addPreparedPayment( Pain001Data( creditorIban = body.iban, creditorBic = body.bic, creditorName = body.name, - debitorIban = debitBankAccount.iban, - debitorBic = debitBankAccount.bankCode, - debitorName = debitBankAccount.accountHolder, + debitorAccount = bankAccount.id.value, sum = amount.amount, currency = amount.currency, subject = body.subject @@ -304,10 +317,24 @@ fun main() { status = camt53doc.pickString("//*[local-name()='Ntry']//*[local-name()='Sts']") bookingDate = parseDashedDate(camt53doc.pickString("//*[local-name()='BookgDt']//*[local-name()='Dt']")).millis nexusUser = extractNexusUser(userId) - creditorName = camt53doc.pickString("//*[local-name()='RltdPties']//*[local-name()='Dbtr']//*[local-name()='Nm']") - creditorIban = camt53doc.pickString("//*[local-name()='CdtrAcct']//*[local-name()='IBAN']") - debitorName = camt53doc.pickString("//*[local-name()='RltdPties']//*[local-name()='Dbtr']//*[local-name()='Nm']") - debitorIban = camt53doc.pickString("//*[local-name()='DbtrAcct']//*[local-name()='IBAN']") + counterpartIban = camt53doc.pickString( + if (this.transactionType == "DBIT") { + // counterpart is credit + "//*[local-name()='CdtrAcct']//*[local-name()='IBAN']" + } else { + // counterpart is debit + "//*[local-name()='DbtrAcct']//*[local-name()='IBAN']" + } + ) + counterpartName = camt53doc.pickString( + "//*[local-name()='RltdPties']//*[local-name()='${ + if (this.transactionType == "DBIT") { + "Cdtr" + } else { + "Dbtr" + } + }']//*[local-name()='Nm']" + ) counterpartBic = camt53doc.pickString("//*[local-name()='RltdAgts']//*[local-name()='BIC']") } } @@ -345,7 +372,23 @@ fun main() { val userId = authenticateRequest(call.request.headers["Authorization"]) val start = call.request.queryParameters["start"] val end = call.request.queryParameters["end"] + val ret = Transactions() + transaction { + RawBankTransactionEntity.find { + RawBankTransactionsTable.nexusUser eq userId and + RawBankTransactionsTable.bookingDate.between( + parseDashedDate(start ?: "1970-01-01"), + parseDashedDate(end ?: DateTime.now().toDashedDate()) + ) + }.forEach { + ret.transactions.add( + Transaction( + account = it. + ) + ) + } + } return@get } /** diff --git a/nexus/src/main/kotlin/tech/libeufin/nexus/MainDeprecated.kt b/nexus/src/main/kotlin/tech/libeufin/nexus/MainDeprecated.kt index 547f0b22..f589d764 100644 --- a/nexus/src/main/kotlin/tech/libeufin/nexus/MainDeprecated.kt +++ b/nexus/src/main/kotlin/tech/libeufin/nexus/MainDeprecated.kt @@ -46,8 +46,6 @@ import kotlinx.io.core.ExperimentalIoApi import org.jetbrains.exposed.sql.and 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 import tech.libeufin.util.* import tech.libeufin.util.ebics_h004.HTDResponseOrderData @@ -258,8 +256,8 @@ fun main() { BankAccountMapsTable.nexusUser eq nexusUser.id } bankAccountsMap.forEach { - Pain001Entity.find { - Pain001Table.debitorIban eq it.bankAccount.iban + PreparedPaymentEntity.find { + PreparedPaymentsTable.debitorIban eq it.bankAccount.iban }.forEach { ret.payments.add( RawPayment( @@ -287,7 +285,7 @@ fun main() { ) } } - createPain001entity(pain001data, nexusUser) + addPreparedPayment(pain001data, nexusUser) call.respondText( "Payment instructions persisted in DB", ContentType.Text.Plain, HttpStatusCode.OK @@ -560,8 +558,8 @@ fun main() { post("/ebics/execute-payments") { val (paymentRowId, painDoc, subscriber) = transaction { - val entity = Pain001Entity.find { - (Pain001Table.submitted eq false) and (Pain001Table.invalid eq false) + val entity = PreparedPaymentEntity.find { + (PreparedPaymentsTable.submitted eq false) and (PreparedPaymentsTable.invalid eq false) }.firstOrNull() ?: throw NexusError(HttpStatusCode.Accepted, reason = "No ready payments found") Triple(entity.id, createPain001document(entity), entity.nexusUser.ebicsSubscriber) } @@ -581,7 +579,7 @@ fun main() { ) /* flow here == no errors occurred */ transaction { - val payment = Pain001Entity.findById(paymentRowId) ?: throw NexusError( + val payment = PreparedPaymentEntity.findById(paymentRowId) ?: throw NexusError( HttpStatusCode.InternalServerError, "Severe internal error: could not find payment in DB after having submitted it to the bank" ) diff --git a/nexus/src/main/kotlin/tech/libeufin/nexus/taler.kt b/nexus/src/main/kotlin/tech/libeufin/nexus/taler.kt index 766e4b46..8a97107d 100644 --- a/nexus/src/main/kotlin/tech/libeufin/nexus/taler.kt +++ b/nexus/src/main/kotlin/tech/libeufin/nexus/taler.kt @@ -243,7 +243,7 @@ class Taler(app: Route) { ) } } - val pain001 = createPain001entity( + val pain001 = addPreparedPayment( Pain001Data( creditorIban = creditorData.iban, creditorBic = creditorData.bic, @@ -368,7 +368,7 @@ class Taler(app: Route) { TalerIncomingPaymentEntity.find { TalerIncomingPayments.refunded eq false and (TalerIncomingPayments.valid eq false) }.forEach { - createPain001entity( + addPreparedPayment( Pain001Data( creditorName = it.payment.debitorName, creditorIban = it.payment.debitorIban, |