commit 8e43b5d1810956eaad533f9849dcf05fe176ab43
parent f0a1fe102e9039c6354156fea8ff64ad653d0b02
Author: Antoine A <>
Date: Sat, 2 Dec 2023 12:43:36 +0000
Allow setting debit_threshold when creating new account
Diffstat:
3 files changed, 27 insertions(+), 2 deletions(-)
diff --git a/bank/src/main/kotlin/tech/libeufin/bank/CoreBankApi.kt b/bank/src/main/kotlin/tech/libeufin/bank/CoreBankApi.kt
@@ -145,6 +145,13 @@ private fun Routing.coreBankAccountsApi(db: Database, ctx: BankConfig) {
"Username '${req.username}' is reserved.",
TalerErrorCode.BANK_RESERVED_USERNAME_CONFLICT
)
+
+ if (req.debit_threshold != null && !isAdmin)
+ throw conflict(
+ "only admin account can choose the debit limit",
+ TalerErrorCode.BANK_NON_ADMIN_PATCH_DEBT_LIMIT
+ )
+
val internalPayto = req.internal_payto_uri ?: IbanPayTo(genIbanPaytoUri())
val result = db.account.create(
@@ -157,7 +164,7 @@ private fun Routing.coreBankAccountsApi(db: Database, ctx: BankConfig) {
internalPaytoUri = internalPayto,
isPublic = req.is_public,
isTalerExchange = req.is_taler_exchange,
- maxDebt = ctx.defaultCustomerDebtLimit,
+ maxDebt = req.debit_threshold ?: ctx.defaultCustomerDebtLimit,
bonus = if (!req.is_taler_exchange) ctx.registrationBonus
else TalerAmount(0, 0, ctx.regionalCurrency),
checkPaytoIdempotent = req.internal_payto_uri != null
diff --git a/bank/src/main/kotlin/tech/libeufin/bank/TalerMessage.kt b/bank/src/main/kotlin/tech/libeufin/bank/TalerMessage.kt
@@ -117,7 +117,8 @@ data class RegisterAccountRequest(
// Fiat bank account where to send cashout amounts.
val cashout_payto_uri: IbanPayTo? = null,
// Bank account internal to Libeufin-Bank.
- val internal_payto_uri: IbanPayTo? = null
+ val internal_payto_uri: IbanPayTo? = null,
+ val debit_threshold: TalerAmount? = null
)
@Serializable
diff --git a/bank/src/test/kotlin/CoreBankApiTest.kt b/bank/src/test/kotlin/CoreBankApiTest.kt
@@ -214,6 +214,23 @@ class CoreBankAccountsApiTest {
json(req)
}.assertOk()
+ // Check debit_threshold
+ obj {
+ "username" to "bat"
+ "password" to "password"
+ "name" to "Bat"
+ "debit_threshold" to "KUDOS:42"
+ }.let { req ->
+ client.post("/accounts") {
+ json(req)
+ }.assertErr(TalerErrorCode.BANK_NON_ADMIN_PATCH_DEBT_LIMIT)
+ client.post("/accounts") {
+ json(req)
+ pwAuth("admin")
+ }.assertOk()
+ }
+
+
// Reserved account
RESERVED_ACCOUNTS.forEach {
client.post("/accounts") {