libeufin

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

commit 9f0348d373a04fe7f96db2a19d8b2c74c2da8ec8
parent 2b11a2cbef9f342be397c08c2b0811215c033d2b
Author: ms <ms@taler.net>
Date:   Sat, 23 Oct 2021 10:41:28 +0200

Amount format.

Allowing wire-transfer CLI command to keep using the
Taler format for amounts, to stay compatible with tests.

Diffstat:
Msandbox/src/main/kotlin/tech/libeufin/sandbox/Helpers.kt | 15+++++++++------
Msandbox/src/main/kotlin/tech/libeufin/sandbox/Main.kt | 18+++++++++++-------
2 files changed, 20 insertions(+), 13 deletions(-)

diff --git a/sandbox/src/main/kotlin/tech/libeufin/sandbox/Helpers.kt b/sandbox/src/main/kotlin/tech/libeufin/sandbox/Helpers.kt @@ -127,7 +127,7 @@ fun wireTransfer( creditAccount: String, demobank: String, subject: String, - amount: String + amount: String // $currency:x.y ): String { val args: Triple<BankAccountEntity, BankAccountEntity, DemobankConfigEntity> = transaction { val debitAccount = BankAccountEntity.find { @@ -151,12 +151,13 @@ fun wireTransfer( Triple(debitAccount, creditAccount, demoBank) } + val amountObj = parseAmount(amount) return wireTransfer( debitAccount = args.first, creditAccount = args.second, - demoBank = args.third, + Demobank = args.third, subject = subject, - amount = amount + amount = amountObj.amount.toPlainString() ) } /** @@ -172,7 +173,7 @@ fun wireTransfer( fun wireTransfer( debitAccount: BankAccountEntity, creditAccount: BankAccountEntity, - demoBank: DemobankConfigEntity, + Demobank: DemobankConfigEntity, subject: String, amount: String, ): String { @@ -189,11 +190,12 @@ fun wireTransfer( debtorName = getPersonNameFromCustomer(debitAccount.owner) this.subject = subject this.amount = amount - this.currency = demoBank.currency + this.currency = Demobank.currency date = timeStamp accountServicerReference = transactionRef account = creditAccount direction = "CRDT" + this.demobank = Demobank } BankAccountTransactionEntity.new { creditorIban = creditAccount.iban @@ -204,11 +206,12 @@ fun wireTransfer( debtorName = getPersonNameFromCustomer(debitAccount.owner) this.subject = subject this.amount = amount - this.currency = demoBank.currency + this.currency = Demobank.currency date = timeStamp accountServicerReference = transactionRef account = debitAccount direction = "DBIT" + demobank = Demobank } } return transactionRef diff --git a/sandbox/src/main/kotlin/tech/libeufin/sandbox/Main.kt b/sandbox/src/main/kotlin/tech/libeufin/sandbox/Main.kt @@ -399,7 +399,7 @@ val sandboxApp: Application.() -> Unit = { } } } - install(io.ktor.features.ContentNegotiation) { + install(ContentNegotiation) { jackson { enable(com.fasterxml.jackson.databind.SerializationFeature.INDENT_OUTPUT) setDefaultPrettyPrinter(DefaultPrettyPrinter().apply { @@ -457,18 +457,18 @@ val sandboxApp: Application.() -> Unit = { ) val hostAuthPriv = transaction { val host = EbicsHostEntity.find { - tech.libeufin.sandbox.EbicsHostsTable.hostID.upperCase() eq call.attributes.get(tech.libeufin.sandbox.EbicsHostIdAttribute) + EbicsHostsTable.hostID.upperCase() eq call.attributes.get(tech.libeufin.sandbox.EbicsHostIdAttribute) .uppercase() }.firstOrNull() ?: throw SandboxError( io.ktor.http.HttpStatusCode.InternalServerError, "Requested Ebics host ID not found." ) - tech.libeufin.util.CryptoUtil.loadRsaPrivateKey(host.authenticationPrivateKey.bytes) + CryptoUtil.loadRsaPrivateKey(host.authenticationPrivateKey.bytes) } call.respondText( - tech.libeufin.util.XMLUtil.signEbicsResponse(resp, hostAuthPriv), - io.ktor.http.ContentType.Application.Xml, - io.ktor.http.HttpStatusCode.OK + XMLUtil.signEbicsResponse(resp, hostAuthPriv), + ContentType.Application.Xml, + HttpStatusCode.OK ) } exception<Throwable> { cause -> @@ -895,9 +895,11 @@ val sandboxApp: Application.() -> Unit = { * generic error types to EBICS-formatted responses. */ catch (e: UtilError) { + logger.error(e) throw EbicsProcessingError("Serving EBICS threw unmanaged UtilError: ${e.reason}") } catch (e: SandboxError) { + logger.error(e) // Should translate to EBICS error code. when (e.errorCode) { LibeufinErrorCode.LIBEUFIN_EC_INVALID_STATE -> throw EbicsProcessingError("Invalid bank state.") @@ -906,11 +908,13 @@ val sandboxApp: Application.() -> Unit = { } } catch (e: EbicsRequestError) { + logger.error(e) // Preventing the last catch-all block // from capturing a known type. throw e } catch (e: Exception) { + logger.error(e) if (e !is EbicsRequestError) { throw EbicsProcessingError("Unmanaged error: $e") } @@ -1116,7 +1120,7 @@ val sandboxApp: Application.() -> Unit = { "Cannot transfer funds without reserve public key." ), // provide the currency. - demoBank = ensureDemobank(call) + Demobank = ensureDemobank(call) ) wo.confirmationDone = true }