libeufin

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

commit 159225a83bd263170f8ddfe0bb3ddb34c63abfa7
parent 3d688bbc47a3aa8b360de6ca594d1f3a00f56a4a
Author: MS <ms@taler.net>
Date:   Fri, 15 Jan 2021 10:58:32 +0100

Counting transactions.

Telling the user how many new money transactions were
received from the bank, instead of how many new Ebics
documents were downloaded.

Diffstat:
Mnexus/src/main/kotlin/tech/libeufin/nexus/bankaccount/BankAccount.kt | 25+++++++++++++------------
Mnexus/src/main/kotlin/tech/libeufin/nexus/server/NexusServer.kt | 4++--
2 files changed, 15 insertions(+), 14 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 @@ -119,16 +119,18 @@ private fun findDuplicate(bankAccountId: String, acctSvcrRef: String): NexusBank } } -fun processCamtMessage(bankAccountId: String, camtDoc: Document, code: String): Boolean { +fun processCamtMessage(bankAccountId: String, camtDoc: Document, code: String): Int { logger.info("processing CAMT message") - val success = transaction { + var newTransactions = 0 + transaction { val acct = NexusBankAccountEntity.findById(bankAccountId) if (acct == null) { throw NexusError(HttpStatusCode.NotFound, "user not found") } val res = try { parseCamtMessage(camtDoc) } catch (e: CamtParsingError) { logger.warn("Invalid CAMT received from bank: $e") - return@transaction false + newTransactions = -1 + return@transaction } val stamp = ZonedDateTime.parse(res.creationDateTime, DateTimeFormatter.ISO_DATE_TIME).toInstant().toEpochMilli() when (code) { @@ -176,6 +178,8 @@ fun processCamtMessage(bankAccountId: String, camtDoc: Document, code: String): status = entry.status } rawEntity.flush() + newTransactions++ + // This block tries to acknowledge a former outgoing payment as booked. if (singletonBatchedTransaction.creditDebitIndicator == CreditDebitIndicator.DBIT) { val t0 = singletonBatchedTransaction.details val msgId = t0.messageId @@ -192,13 +196,10 @@ fun processCamtMessage(bankAccountId: String, camtDoc: Document, code: String): paymentInitiation.confirmationTransaction = rawEntity } } - // FIXME: find matching PaymentInitiation - // by PaymentInformationID, message ID or whatever is present } } - return@transaction true } - return success + return newTransactions } /** @@ -221,14 +222,14 @@ fun ingestBankMessagesIntoAccount(bankConnectionId: String, bankAccountId: Strin (NexusBankMessagesTable.bankConnection eq conn.id) and (NexusBankMessagesTable.id greater acct.highestSeenBankMessageId) }.orderBy(Pair(NexusBankMessagesTable.id, SortOrder.ASC)).forEach { - logger.debug("Unseen Camt, account: ${bankAccountId}, connection: ${conn.id}, msgId: ${it.messageId}") - totalNew++ val doc = XMLUtil.parseStringIntoDom(it.message.bytes.toString(Charsets.UTF_8)) - if (!processCamtMessage(bankAccountId, doc, it.code)) { + val newTransactions = processCamtMessage(bankAccountId, doc, it.code) + if (newTransactions == -1) { it.errors = true return@forEach } lastId = it.id.value + totalNew += newTransactions } acct.highestSeenBankMessageId = lastId } @@ -313,9 +314,9 @@ suspend fun fetchBankAccountTransactions(client: HttpClient, fetchSpec: FetchSpe "Connection type '${res.connectionType}' not implemented" ) } - val newMessages = ingestBankMessagesIntoAccount(res.connectionName, accountId) + val newTransactions = ingestBankMessagesIntoAccount(res.connectionName, accountId) ingestTalerTransactions() - return newMessages + return newTransactions } fun importBankAccount(call: ApplicationCall, offeredBankAccountId: String, nexusBankAccountId: String) { diff --git a/nexus/src/main/kotlin/tech/libeufin/nexus/server/NexusServer.kt b/nexus/src/main/kotlin/tech/libeufin/nexus/server/NexusServer.kt @@ -671,8 +671,8 @@ fun serverMain(dbName: String, host: String, port: Int) { null ) } - val newMessages = fetchBankAccountTransactions(client, fetchSpec, accountid) - call.respond(object {val newMessages = newMessages}) + val newTransactions = fetchBankAccountTransactions(client, fetchSpec, accountid) + call.respond(object {val newTransactions = newTransactions}) return@post }