summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMS <ms@taler.net>2023-03-07 19:37:54 +0100
committerMS <ms@taler.net>2023-03-07 19:39:37 +0100
commiteb734259ce107e8850e4f50c881be91847e5778c (patch)
tree14e3bb67f2cd27c4e444d543a31783e1ff7e7dbe
parent7e013b1fbdb10a27e65fc4cbc4f77d6d84413962 (diff)
downloadlibeufin-eb734259ce107e8850e4f50c881be91847e5778c.tar.gz
libeufin-eb734259ce107e8850e4f50c881be91847e5778c.tar.bz2
libeufin-eb734259ce107e8850e4f50c881be91847e5778c.zip
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.
-rw-r--r--sandbox/src/main/kotlin/tech/libeufin/sandbox/CircuitApi.kt12
-rw-r--r--sandbox/src/main/kotlin/tech/libeufin/sandbox/JSON.kt5
-rw-r--r--sandbox/src/main/kotlin/tech/libeufin/sandbox/Main.kt9
-rw-r--r--sandbox/src/main/kotlin/tech/libeufin/sandbox/bankAccount.kt16
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
index e3903923..2c325ccc 100644
--- 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
index 678ccff3..87021146 100644
--- 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
index cd52a8f4..70294e80 100644
--- 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
index d194178c..5bd45a6f 100644
--- 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