libeufin

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

commit 846b72e6703dc6c43894aee8aad02e2222b6c54c
parent 87df1c6a292a142d7599ae665d05b5a5ac59f279
Author: MS <ms@taler.net>
Date:   Mon, 28 Nov 2022 20:59:33 +0100

logging wire transfer subjects along Camt communication

Diffstat:
Mnexus/src/main/kotlin/tech/libeufin/nexus/bankaccount/BankAccount.kt | 15+++++++++++++--
Mnexus/src/main/kotlin/tech/libeufin/nexus/ebics/EbicsNexus.kt | 5++---
Mnexus/src/test/kotlin/DownloadAndSubmit.kt | 19++++++++++++++++---
Msandbox/src/main/kotlin/tech/libeufin/sandbox/EbicsProtocolBackend.kt | 7++++++-
4 files changed, 37 insertions(+), 9 deletions(-)

diff --git a/nexus/src/main/kotlin/tech/libeufin/nexus/bankaccount/BankAccount.kt b/nexus/src/main/kotlin/tech/libeufin/nexus/bankaccount/BankAccount.kt @@ -146,6 +146,10 @@ data class CamtTransactionsCount( val downloadedTransactions: Int ) +/** + * Get the Camt parsed by a helper function, discards duplicates + * and stores new transactions. + */ fun processCamtMessage( bankAccountId: String, camtDoc: Document, code: String ): CamtTransactionsCount { @@ -173,6 +177,7 @@ fun processCamtMessage( if (b.type == "CLBD") { clbdCount++ val lastBalance = NexusBankBalanceEntity.all().lastOrNull() + // Only store non seen balances. if (lastBalance != null && b.amount.toPlainString() != lastBalance.balance) { NexusBankBalanceEntity.new { bankAccount = acct @@ -188,7 +193,10 @@ fun processCamtMessage( } } } - + /** + * Why is the report/statement creation timestamp important, + * rather than each individual payment identification value? + */ val stamp = ZonedDateTime.parse(res.creationDateTime, DateTimeFormatter.ISO_DATE_TIME).toInstant().toEpochMilli() when (code) { @@ -206,7 +214,7 @@ fun processCamtMessage( } } val entries = res.reports.map { it.entries }.flatten() - logger.info("found ${entries.size} money movements") + var newPaymentsLog = "" downloadedTransactions = entries.size txloop@ for (entry in entries) { val singletonBatchedTransaction = entry.batches?.get(0)?.batchTransactions?.get(0) @@ -238,6 +246,7 @@ fun processCamtMessage( } rawEntity.flush() newTransactions++ + newPaymentsLog += "\n- " + entry.batches[0].batchTransactions[0].details.unstructuredRemittanceInformation // This block tries to acknowledge a former outgoing payment as booked. if (singletonBatchedTransaction.creditDebitIndicator == CreditDebitIndicator.DBIT) { val t0 = singletonBatchedTransaction.details @@ -255,6 +264,8 @@ fun processCamtMessage( } } } + if (newTransactions > 0) + logger.debug("Camt $code '${res.messageId}' has new payments:${newPaymentsLog}") } return CamtTransactionsCount( newTransactions = newTransactions, diff --git a/nexus/src/main/kotlin/tech/libeufin/nexus/ebics/EbicsNexus.kt b/nexus/src/main/kotlin/tech/libeufin/nexus/ebics/EbicsNexus.kt @@ -489,9 +489,8 @@ class EbicsBankConnectionProtocol: BankConnectionProtocol { } } } - /* Not handling errors here because - sub-calls should throw and get caught by - global handlers. + /** + * Downloads and stores the bank message into the database. No ingestion. */ for (spec in specs) fetchEbicsC5x( diff --git a/nexus/src/test/kotlin/DownloadAndSubmit.kt b/nexus/src/test/kotlin/DownloadAndSubmit.kt @@ -100,16 +100,29 @@ class SchedulingTest { @Test fun download() { withNexusAndSandboxUser { + wireTransfer( + "bank", + "foo", + "default", + "Show up in logging!", + "TESTKUDOS:5" + ) + wireTransfer( + "bank", + "foo", + "default", + "Exist in logging!", + "TESTKUDOS:5" + ) withTestApplication(sandboxApp) { val conn = EbicsBankConnectionProtocol() runBlocking { - conn.fetchTransactions( + fetchBankAccountTransactions( + client, fetchSpec = FetchSpecAllJson( level = FetchLevel.REPORT, "foo" ), - client, - "foo", "mock-bank-account" ) } diff --git a/sandbox/src/main/kotlin/tech/libeufin/sandbox/EbicsProtocolBackend.kt b/sandbox/src/main/kotlin/tech/libeufin/sandbox/EbicsProtocolBackend.kt @@ -551,7 +551,12 @@ private fun constructCamtResponse( balancePrcd = lastBalance, balanceClbd = freshBalance ) - logger.debug("camt.052 document '${camtData.messageId}' generated.") + val payments: String = if (logger.isDebugEnabled) { + var ret = " It includes the payments:" + for (p in history) ret += "\n- ${p.subject}" + ret + } else "" + logger.debug("camt.052 document '${camtData.messageId}' generated.$payments") return listOf( camtData.camtMessage )