summaryrefslogtreecommitdiff
path: root/nexus
diff options
context:
space:
mode:
authorMS <ms@taler.net>2021-01-15 10:58:32 +0100
committerMS <ms@taler.net>2021-01-15 10:58:32 +0100
commit159225a83bd263170f8ddfe0bb3ddb34c63abfa7 (patch)
tree9a750b32bb12a62dff0a56d92d0f71a138929c71 /nexus
parent3d688bbc47a3aa8b360de6ca594d1f3a00f56a4a (diff)
downloadlibeufin-159225a83bd263170f8ddfe0bb3ddb34c63abfa7.tar.gz
libeufin-159225a83bd263170f8ddfe0bb3ddb34c63abfa7.tar.bz2
libeufin-159225a83bd263170f8ddfe0bb3ddb34c63abfa7.zip
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 (limited to 'nexus')
-rw-r--r--nexus/src/main/kotlin/tech/libeufin/nexus/bankaccount/BankAccount.kt25
-rw-r--r--nexus/src/main/kotlin/tech/libeufin/nexus/server/NexusServer.kt4
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 019a091a..c3dc485f 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 e1ff46bc..878f7e82 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
}