libeufin

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

commit 5a874acbcbce6b08550073149408124a33fa7305
parent d2184eeac65907be5c32505ec0ee8297189b8f34
Author: Marcello Stanisci <stanisci.m@gmail.com>
Date:   Tue, 18 Feb 2020 23:29:37 +0100

Accepting payment details from POST.

Diffstat:
Mnexus/src/main/kotlin/tech/libeufin/nexus/DB.kt | 3---
Mnexus/src/main/kotlin/tech/libeufin/nexus/Main.kt | 20++++++++++++++------
Msandbox/src/main/kotlin/tech/libeufin/sandbox/DB.kt | 6------
3 files changed, 14 insertions(+), 15 deletions(-)

diff --git a/nexus/src/main/kotlin/tech/libeufin/nexus/DB.kt b/nexus/src/main/kotlin/tech/libeufin/nexus/DB.kt @@ -73,9 +73,7 @@ object Pain001Table : IntIdTableWithAmount() { } class Pain001Entity(id: EntityID<Int>) : IntEntity(id) { - companion object : IntEntityClass<Pain001Entity>(Pain001Table) - var msgId by Pain001Table.msgId var paymentId by Pain001Table.paymentId var date by Pain001Table.fileDate @@ -89,7 +87,6 @@ class Pain001Entity(id: EntityID<Int>) : IntEntity(id) { var submitted by Pain001Table.submitted } - object EbicsAccountsInfoTable : IdTable<String>() { override val id = varchar("id", ID_MAX_LENGTH).entityId().primaryKey() val subscriber = reference("subscriber", EbicsSubscribersTable) diff --git a/nexus/src/main/kotlin/tech/libeufin/nexus/Main.kt b/nexus/src/main/kotlin/tech/libeufin/nexus/Main.kt @@ -158,31 +158,28 @@ fun getSubscriberDetailsFromId(id: String): EbicsClientSubscriberDetails { } } -data class Pain001Entry( - val debtorAccountId: String, +data class Pain001Data( val creditorIban: String, val creditorBic: String, val creditorName: String, val sum: Amount, val subject: String - ) /** * Insert one row in the database, and leaves it marked as non-submitted. */ -fun createPain001entry(entry: Pain001Entry) { +fun createPain001entry(entry: Pain001Data, debtorAccountId: String) { transaction { Pain001Entity.new { subject = entry.subject sum = entry.sum - debtorAccount = entry.debtorAccountId + debtorAccount = debtorAccountId creditorName = entry.creditorName creditorBic = entry.creditorBic creditorIban = entry.creditorIban } } - } fun main() { @@ -371,9 +368,20 @@ fun main() { post("/ebics/subscribers/{id}/accounts/{acctid}/prepare-payment") { val acctid = expectId(call.parameters["acctid"]) val subscriberId = expectId(call.parameters["id"]) + val accountDetails: EbicsAccountInfoElement = getBankAccountDetailsFromAcctid(acctid) val subscriberDetails = getSubscriberDetailsFromId(subscriberId) + transaction { + val accountinfo = EbicsAccountInfoEntity.findById(acctid) + val subscriber = EbicsSubscriberEntity.findById(subscriberId) + if (accountinfo?.subscriber != subscriber) { + throw Exception("Claimed account doesn't belong to POSTer!") + } + } + val pain001data = call.receive<Pain001Data>() + createPain001entry(pain001data, acctid) + /** * Payment preparation logic goes here! */ diff --git a/sandbox/src/main/kotlin/tech/libeufin/sandbox/DB.kt b/sandbox/src/main/kotlin/tech/libeufin/sandbox/DB.kt @@ -31,9 +31,6 @@ import java.math.MathContext import java.math.RoundingMode import java.sql.Blob import java.sql.Connection -import tech.libeufin.util.IntIdTableWithAmount - - const val CUSTOMER_NAME_MAX_LENGTH = 20 const val EBICS_HOST_ID_MAX_LENGTH = 10 @@ -112,15 +109,12 @@ object BankTransactionsTable : IntIdTableWithAmount() { class BankTransactionEntity(id: EntityID<Int>) : IntEntity(id) { companion object : IntEntityClass<BankTransactionEntity>(BankTransactionsTable) - /* the id of the local customer involved in this transaction, * either as the credit or the debit part; makes lookups easier */ var localCustomer by BankCustomerEntity referencedOn BankTransactionsTable.localCustomer - /* keeping as strings, as to allow hosting IBANs and/or other * unobvious formats. */ var counterpart by BankTransactionsTable.counterpart - var subject by BankTransactionsTable.subject var operationDate by BankTransactionsTable.operationDate var valueDate by BankTransactionsTable.valueDate