libeufin

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

commit 2e49f3b90d43e5f10cc2b7c79bf5f6f5e64ddf2b
parent 039845992553cb0f8816279479ee4d028e75d0de
Author: MS <ms@taler.net>
Date:   Mon, 30 Aug 2021 22:03:05 -1100

Adapting /admin/payments/camt (Camt query) to read from database.

It used to generate the statements on the fly.

Diffstat:
Msandbox/src/main/kotlin/tech/libeufin/sandbox/JSON.kt | 3++-
Msandbox/src/main/kotlin/tech/libeufin/sandbox/Main.kt | 30+++++++++++++++---------------
2 files changed, 17 insertions(+), 16 deletions(-)

diff --git a/sandbox/src/main/kotlin/tech/libeufin/sandbox/JSON.kt b/sandbox/src/main/kotlin/tech/libeufin/sandbox/JSON.kt @@ -68,5 +68,6 @@ data class BankAccountRequest( data class CamtParams( // name/label of the bank account to query. val bankaccount: String, - val type: Int + val type: Int, + // need range parameter ) diff --git a/sandbox/src/main/kotlin/tech/libeufin/sandbox/Main.kt b/sandbox/src/main/kotlin/tech/libeufin/sandbox/Main.kt @@ -587,27 +587,27 @@ fun serverMain(dbName: String, port: Int) { val version = "0.0.0-dev.0" }) } - - // only reason for a post is to hide the iban (to some degree.) + /** + * For now, only returns the last statement of the + * requesting account. + */ post("/admin/payments/camt") { val body = call.receiveJson<CamtParams>() val bankaccount = getAccountFromLabel(body.bankaccount) - val history = historyForAccount(bankaccount) - SandboxAssert(body.type == 53, - "Only Camt.053 is implemented" + if(body.type != 53) throw SandboxError( + HttpStatusCode.NotFound, + "Only Camt.053 documents can be generated." ) - val camtData = buildCamtString( - body.type, - bankaccount.iban, - history, - balancePrcd = BigDecimal.ZERO, - balanceClbd = balanceForAccount( - history, - baseBalance = BigDecimal.ZERO + val camtMessage = transaction { + BankAccountStatementEntity.find { + BankAccountStatementsTable.bankAccount eq bankaccount.id + }.lastOrNull()?.xmlMessage ?: throw SandboxError( + HttpStatusCode.NotFound, + "Could not find any statements; please wait next tick" ) - ) + } call.respondText( - camtData.camtMessage, ContentType.Text.Xml, HttpStatusCode.OK + camtMessage, ContentType.Text.Xml, HttpStatusCode.OK ) return@post }