[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[libeufin] 04/04: Counting transactions.
From: |
gnunet |
Subject: |
[libeufin] 04/04: Counting transactions. |
Date: |
Fri, 15 Jan 2021 10:59:59 +0100 |
This is an automated email from the git hooks/post-receive script.
ms pushed a commit to branch master
in repository libeufin.
commit 159225a83bd263170f8ddfe0bb3ddb34c63abfa7
Author: MS <ms@taler.net>
AuthorDate: Fri Jan 15 10:58:32 2021 +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.
---
.../tech/libeufin/nexus/bankaccount/BankAccount.kt | 25 +++++++++++-----------
.../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
index 019a091..c3dc485 100644
--- 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
index e1ff46b..878f7e8 100644
--- 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
}
--
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.