libeufin

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

commit f91bbdac3e752cb3246de8ad2decfb6d8d8227f3
parent 3f8e7a5f595be2175ca56713ad20a80e562125aa
Author: Marcello Stanisci <stanisci.m@gmail.com>
Date:   Thu, 26 Mar 2020 11:55:01 +0100

Give endpoint to query C53 entries in DB.

Diffstat:
Mcli/python/libeufin-cli | 22++++++++++++++++++++++
Mnexus/src/main/kotlin/tech/libeufin/nexus/DB.kt | 2++
Mnexus/src/main/kotlin/tech/libeufin/nexus/Main.kt | 35++++++++++++++++++++++++++---------
3 files changed, 50 insertions(+), 9 deletions(-)

diff --git a/cli/python/libeufin-cli b/cli/python/libeufin-cli @@ -423,6 +423,28 @@ def crz(obj, account_id, date_range, nexus_base_url): print(resp.content.decode("utf-8")) +@ebics.command(help="Show raw transactions from the Nexus database") +@click.pass_obj +@click.option( + "--account-id", + help="Numerical ID of the customer at the Nexus", + required=True +) +@click.argument( + "nexus-base-url" +) +def show_collected_c53(obj, account_id, date_range, nexus_base_url): + if date_range is not None and len(date_range) == 2: + req = dict(dateRange=dict(start=date_range[0], end=date_range[1])) + else: + req = dict() + url = urljoin(nexus_base_url, "/ebics/subscribers/{}/collect-transactions-c53".format(account_id)) + resp = post(url, json=req) + print(resp.content.decode("utf-8")) + + + + @ebics.command(help="Send C53 message AND instruct the Nexus to persist the result") @click.pass_obj @click.option( diff --git a/nexus/src/main/kotlin/tech/libeufin/nexus/DB.kt b/nexus/src/main/kotlin/tech/libeufin/nexus/DB.kt @@ -28,6 +28,7 @@ object EbicsRawBankTransactionsTable : IdTable<Long>() { val amount = text("amount") val creditorIban = text("creditorIban") val debitorIban = text("creditorIban") + val bookingDate = text("bookingDate") } class EbicsRawBankTransactionEntry(id: EntityID<Long>) : LongEntity(id) { @@ -40,6 +41,7 @@ class EbicsRawBankTransactionEntry(id: EntityID<Long>) : LongEntity(id) { var amount by EbicsRawBankTransactionsTable.amount var creditorIban by EbicsRawBankTransactionsTable.creditorIban var debitorIban by EbicsRawBankTransactionsTable.debitorIban + var bookingDate by EbicsRawBankTransactionsTable.bookingDate var nexusSubscriber by EbicsSubscriberEntity referencedOn EbicsRawBankTransactionsTable.nexusSubscriber } diff --git a/nexus/src/main/kotlin/tech/libeufin/nexus/Main.kt b/nexus/src/main/kotlin/tech/libeufin/nexus/Main.kt @@ -626,6 +626,27 @@ fun main() { } + get("/ebics/subscribers/{id}/show-collected-transactions-c53") { + val id = expectId(call.parameters["id"]) + var ret = "" + transaction { + val subscriber = getSubscriberEntityFromId(id) + EbicsRawBankTransactionEntry.find { + (EbicsRawBankTransactionsTable.nexusSubscriber eq subscriber.id) and + (EbicsRawBankTransactionsTable.sourceType eq "C53") + }.forEach { + ret += "\n###\nCreditor: ${it.creditorIban}\nDebitor: ${it.debitorIban}\nAmount: ${it.currency}:${it.amount}\nDate: ${it.bookingDate}" + } + } + + call.respondText( + ret, + ContentType.Text.Plain, + HttpStatusCode.OK + ) + + return@get + } post("/ebics/subscribers/{id}/collect-transactions-c53") { // FIXME(florian): Download C53 and store the result in the right database table val id = expectId(call.parameters["id"]) @@ -662,6 +683,10 @@ fun main() { camt53doc, "//*[local-name()='Ntry']//*[local-name()='Amt']" ) + val bookingDate = XMLUtil.getStringFromXpath( + camt53doc, + "//*[local-name()='BookgDt']//*[local-name()='Dt']" + ) val subject = XMLUtil.getStringFromXpath( camt53doc, "//*[local-name()='RmtInf']//*[local-name()='Ustrd']" @@ -670,15 +695,6 @@ fun main() { camt53doc, "//*[local-name()='Ntry']//*[local-name()='Amt']/@Ccy" ) - println( - "####" + - "\n\tCreditor IBAN: $creditorIban," + - "\n\tDebitor IBAN: $debitorIban," + - "\n\tCurrency: $currency," + - "\n\tAmount: ${amount}" + - "\n\tSubject: $subject," + - "\n\tFile name: $fileName" - ) transaction { EbicsRawBankTransactionEntry.new { sourceType = "C53" @@ -689,6 +705,7 @@ fun main() { this.amount = amount this.creditorIban = creditorIban this.debitorIban = debitorIban + this.bookingDate = bookingDate nexusSubscriber = getSubscriberEntityFromId(id) } }