libeufin

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

commit eb734259ce107e8850e4f50c881be91847e5778c
parent 7e013b1fbdb10a27e65fc4cbc4f77d6d84413962
Author: MS <ms@taler.net>
Date:   Tue,  7 Mar 2023 19:37:54 +0100

Balances and GET /accounts.

Including the max debit allowed per account
and removing the "GET /accounts" filter for
the accounts without a cash-out target.

Diffstat:
Msandbox/src/main/kotlin/tech/libeufin/sandbox/CircuitApi.kt | 12+++++-------
Msandbox/src/main/kotlin/tech/libeufin/sandbox/JSON.kt | 5++++-
Msandbox/src/main/kotlin/tech/libeufin/sandbox/Main.kt | 9+++++----
Msandbox/src/main/kotlin/tech/libeufin/sandbox/bankAccount.kt | 16++++++++++++++++
4 files changed, 30 insertions(+), 12 deletions(-)

diff --git a/sandbox/src/main/kotlin/tech/libeufin/sandbox/CircuitApi.kt b/sandbox/src/main/kotlin/tech/libeufin/sandbox/CircuitApi.kt @@ -562,16 +562,14 @@ fun circuitApi(circuitRoute: Route) { // like() is case insensitive. DemobankCustomersTable.name.like(filter) }.forEach { - if (it.cashout_address == null) { - logger.debug("Not listing account '${it.username}', as that" + - " misses the cash-out address " + - "and therefore doesn't belong to the Circuit API" - ) - return@forEach - } customers.add(object { val username = it.username val name = it.name + val balance = getBalanceForJson( + getBalance(it.username), + getDefaultDemobank().currency + ) + val debitThreshold = getMaxDebitForUser(it.username) }) } } diff --git a/sandbox/src/main/kotlin/tech/libeufin/sandbox/JSON.kt b/sandbox/src/main/kotlin/tech/libeufin/sandbox/JSON.kt @@ -29,7 +29,10 @@ data class WithdrawalRequest( */ val amount: String // $CURRENCY:X.Y ) - +data class BalanceJson( + val amount: String, + val credit_debit_indicator: String +) data class Demobank( val currency: String, val name: String, diff --git a/sandbox/src/main/kotlin/tech/libeufin/sandbox/Main.kt b/sandbox/src/main/kotlin/tech/libeufin/sandbox/Main.kt @@ -1430,6 +1430,9 @@ val sandboxApp: Application.() -> Unit = { ) ) val iban = bankAccount.iban + // The Elvis operator helps the --no-auth case, + // where username would be empty + val debitThreshold = getMaxDebitForUser(username ?: "admin").toString() }) return@get } @@ -1559,16 +1562,14 @@ val sandboxApp: Application.() -> Unit = { ) val balance = getBalance(newAccount.bankAccount, withPending = true) call.respond(object { - val balance = object { - val amount = "${demobank.currency}:${balance.abs()}" - val credit_debit_indicator = if (balance < BigDecimal.ZERO) "DBIT" else "CRDT" - } + val balance = getBalanceForJson(balance, demobank.currency) val paytoUri = buildIbanPaytoUri( iban = newAccount.bankAccount.iban, bic = newAccount.bankAccount.bic, receiverName = getPersonNameFromCustomer(req.username) ) val iban = newAccount.bankAccount.iban + val debitThreshold = getMaxDebitForUser(req.username).toString() }) return@post } diff --git a/sandbox/src/main/kotlin/tech/libeufin/sandbox/bankAccount.kt b/sandbox/src/main/kotlin/tech/libeufin/sandbox/bankAccount.kt @@ -32,6 +32,22 @@ fun maybeDebit( return false } +fun getMaxDebitForUser(username: String): Int { + val bank = getDefaultDemobank() + if (username == "admin") return bank.bankDebtLimit + return bank.usersDebtLimit + + +} + +fun getBalanceForJson(value: BigDecimal, currency: String): BalanceJson { + return BalanceJson( + amount = "${currency}:${value.abs()}", + credit_debit_indicator = if (value < BigDecimal.ZERO) "DBIT" else "CRDT" + ) + +} + /** * The last balance is the one mentioned in the bank account's * last statement. If the bank account does not have any statement