libeufin

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

commit 7033a39afafcfa430e5a9bea57ac022f13905e97
parent d0a36f7518e7a4a8b46c4f7464a6a180f52a4cb0
Author: Marcello Stanisci <ms@taler.net>
Date:   Sun, 10 May 2020 01:14:59 +0200

POST ../collected-transactions

Diffstat:
Mnexus/src/main/kotlin/tech/libeufin/nexus/DB.kt | 2++
Mnexus/src/main/kotlin/tech/libeufin/nexus/JSON.kt | 2+-
Mnexus/src/main/kotlin/tech/libeufin/nexus/Main.kt | 30++++++++++--------------------
3 files changed, 13 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 @@ -94,6 +94,7 @@ object RawBankTransactionsTable : LongIdTable() { val counterpartName = text("counterpartName") val bookingDate = long("bookingDate") val status = text("status") // BOOK or other. + val bankAccount = reference("bankAccount", BankAccountsTable) } class RawBankTransactionEntity(id: EntityID<Long>) : LongEntity(id) { @@ -109,6 +110,7 @@ class RawBankTransactionEntity(id: EntityID<Long>) : LongEntity(id) { var bookingDate by RawBankTransactionsTable.bookingDate var nexusUser by NexusUserEntity referencedOn RawBankTransactionsTable.nexusUser var status by RawBankTransactionsTable.status + var bankAccount by BankAccountEntity referencedOn RawBankTransactionsTable.bankAccount } /** * Represent a prepare payment. diff --git a/nexus/src/main/kotlin/tech/libeufin/nexus/JSON.kt b/nexus/src/main/kotlin/tech/libeufin/nexus/JSON.kt @@ -120,7 +120,7 @@ data class Transaction( ) data class Transactions( - val transactions: MutableList<Transaction> + val transactions: MutableList<Transaction> = mutableListOf() ) /** Request type of "POST /prepared-payments/submit" */ diff --git a/nexus/src/main/kotlin/tech/libeufin/nexus/Main.kt b/nexus/src/main/kotlin/tech/libeufin/nexus/Main.kt @@ -309,6 +309,7 @@ fun main() { val camt53doc = XMLUtil.parseStringIntoDom(it.second) transaction { RawBankTransactionEntity.new { + bankAccount = getBankAccountFromIban(camt53doc.pickString("//*[local-name()='Stmt']/Acct/Id/IBAN")) sourceFileName = fileName unstructuredRemittanceInformation = camt53doc.pickString("//*[local-name()='Ntry']//*[local-name()='Ustrd']") transactionType = camt53doc.pickString("//*[local-name()='Ntry']//*[local-name()='CdtDbtInd']") @@ -317,24 +318,8 @@ 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) - 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']" - ) + counterpartIban = camt53doc.pickString("//*[local-name()='${if (this.transactionType == "DBIT") "CdtrAcct" else "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']") } } @@ -383,10 +368,15 @@ fun main() { }.forEach { ret.transactions.add( Transaction( - account = it. + account = it.bankAccount.id.value, + counterpartBic = it.counterpartBic, + counterpartIban = it.counterpartIban, + counterpartName = it.counterpartName, + date = DateTime(it.bookingDate).toDashedDate(), + subject = it.unstructuredRemittanceInformation, + amount = "${it.currency}:${it.amount}" ) ) - } } return@get