commit 77fc37721ed4f1cdcefd4eff428487612a0d3c9c
parent 0c0a6de5c3173f15aaa1522f0e1c8bb0cd7ef155
Author: Antoine A <>
Date: Fri, 24 Nov 2023 22:05:22 +0000
Simplify bonus config
Diffstat:
10 files changed, 16 insertions(+), 51 deletions(-)
diff --git a/bank/conf/test.conf b/bank/conf/test.conf
@@ -2,7 +2,7 @@
CURRENCY = KUDOS
DEFAULT_CUSTOMER_DEBT_LIMIT = KUDOS:100
DEFAULT_ADMIN_DEBT_LIMIT = KUDOS:10000
-REGISTRATION_BONUS_ENABLED = NO
+REGISTRATION_BONUS = KUDOS:0
SUGGESTED_WITHDRAWAL_EXCHANGE = https://exchange.example.com
allow_conversion = YES
tan_sms = libeufin-tan-file.sh
diff --git a/bank/conf/test_bonus.conf b/bank/conf/test_bonus.conf
@@ -1,7 +1,6 @@
[libeufin-bank]
CURRENCY = KUDOS
DEFAULT_ADMIN_DEBT_LIMIT = KUDOS:10000
-REGISTRATION_BONUS_ENABLED = yes
REGISTRATION_BONUS = KUDOS:100
[libeufin-bankdb-postgres]
diff --git a/bank/conf/test_no_tan.conf b/bank/conf/test_no_tan.conf
@@ -2,7 +2,6 @@
CURRENCY = KUDOS
DEFAULT_CUSTOMER_DEBT_LIMIT = KUDOS:100
DEFAULT_ADMIN_DEBT_LIMIT = KUDOS:10000
-REGISTRATION_BONUS_ENABLED = NO
SUGGESTED_WITHDRAWAL_EXCHANGE = https://exchange.example.com
allow_conversion = YES
diff --git a/bank/conf/test_restrict.conf b/bank/conf/test_restrict.conf
@@ -2,7 +2,6 @@
CURRENCY = KUDOS
DEFAULT_CUSTOMER_DEBT_LIMIT = KUDOS:100
DEFAULT_ADMIN_DEBT_LIMIT = KUDOS:10000
-REGISTRATION_BONUS_ENABLED = NO
restrict_registration = YES
[libeufin-bankdb-postgres]
diff --git a/bank/src/main/kotlin/tech/libeufin/bank/Config.kt b/bank/src/main/kotlin/tech/libeufin/bank/Config.kt
@@ -34,40 +34,13 @@ private val BANK_CONFIG_SOURCE = ConfigSource("libeufin-bank", "libeufin-bank")
* Application the parsed configuration.
*/
data class BankConfig(
- /**
- * Main, regional currency of the bank.
- */
val regionalCurrency: String,
val regionalCurrencySpec: CurrencySpecification,
- /**
- * Restrict account registration to the administrator.
- */
val restrictRegistration: Boolean,
- /**
- * Restrict account deletion to the administrator.
- */
val restrictAccountDeletion: Boolean,
- /**
- * Default limit for the debt that a customer can have.
- * Can be adjusted per account after account creation.
- */
val defaultCustomerDebtLimit: TalerAmount,
- /**
- * Debt limit of the admin account.
- */
val defaultAdminDebtLimit: TalerAmount,
- /**
- * If true, transfer a registration bonus from the admin
- * account to the newly created account.
- */
- val registrationBonusEnabled: Boolean,
- /**
- * Only set if registration bonus is enabled.
- */
- val registrationBonus: TalerAmount?,
- /**
- * Exchange that the bank suggests to wallets for withdrawal.
- */
+ val registrationBonus: TalerAmount,
val suggestedWithdrawalExchange: String?,
/**
* URL where the user should be redirected to complete the captcha.
@@ -137,8 +110,7 @@ fun TalerConfig.loadBankConfig(): BankConfig = catchError {
regionalCurrencySpec = currencySpecificationFor(regionalCurrency),
restrictRegistration = lookupBoolean("libeufin-bank", "restrict_registration") ?: false,
defaultCustomerDebtLimit = requireAmount("libeufin-bank", "default_customer_debt_limit", regionalCurrency),
- registrationBonusEnabled = lookupBoolean("libeufin-bank", "registration_bonus_enabled") ?: false,
- registrationBonus = requireAmount("libeufin-bank", "registration_bonus", regionalCurrency),
+ registrationBonus = amount("libeufin-bank", "registration_bonus", regionalCurrency) ?: TalerAmount(0, 0, regionalCurrency),
suggestedWithdrawalExchange = lookupString("libeufin-bank", "suggested_withdrawal_exchange"),
defaultAdminDebtLimit = requireAmount("libeufin-bank", "default_admin_debt_limit", regionalCurrency),
spaCaptchaURL = lookupString("libeufin-bank", "spa_captcha_url"),
diff --git a/bank/src/main/kotlin/tech/libeufin/bank/CoreBankApi.kt b/bank/src/main/kotlin/tech/libeufin/bank/CoreBankApi.kt
@@ -159,8 +159,8 @@ private fun Routing.coreBankAccountsApi(db: Database, ctx: BankConfig) {
isPublic = req.is_public,
isTalerExchange = req.is_taler_exchange,
maxDebt = ctx.defaultCustomerDebtLimit,
- bonus = if (ctx.registrationBonusEnabled && !req.is_taler_exchange) ctx.registrationBonus
- else null
+ bonus = if (!req.is_taler_exchange) ctx.registrationBonus
+ else TalerAmount(0, 0, ctx.regionalCurrency)
)
when (result) {
diff --git a/bank/src/main/kotlin/tech/libeufin/bank/db/AccountDAO.kt b/bank/src/main/kotlin/tech/libeufin/bank/db/AccountDAO.kt
@@ -45,7 +45,7 @@ class AccountDAO(private val db: Database) {
isPublic: Boolean,
isTalerExchange: Boolean,
maxDebt: TalerAmount,
- bonus: TalerAmount?
+ bonus: TalerAmount
): AccountCreationResult = db.serializable { it ->
val now = Instant.now().toDbMicros() ?: throw faultyTimestampByBank();
it.transaction { conn ->
@@ -136,8 +136,8 @@ class AccountDAO(private val db: Database) {
return@transaction AccountCreationResult.PayToReuse
}
}
-
- if (bonus != null) {
+ println("$bonus")
+ if (bonus.value != 0L || bonus.frac != 0) {
conn.prepareStatement("""
SELECT out_balance_insufficient
FROM bank_transaction(?,'admin','bonus',(?,?)::taler_amount,?)
diff --git a/bank/src/main/kotlin/tech/libeufin/bank/helpers.kt b/bank/src/main/kotlin/tech/libeufin/bank/helpers.kt
@@ -133,7 +133,7 @@ suspend fun maybeCreateAdminAccount(db: Database, ctx: BankConfig, pw: String? =
isPublic = false,
isTalerExchange = false,
maxDebt = ctx.defaultAdminDebtLimit,
- bonus = null
+ bonus = TalerAmount(0, 0, ctx.regionalCurrency)
)
}
diff --git a/bank/src/test/kotlin/helpers.kt b/bank/src/test/kotlin/helpers.kt
@@ -68,35 +68,36 @@ fun bankSetup(
) {
setup(conf) { db, ctx ->
// Creating the exchange and merchant accounts first.
+ val bonus = TalerAmount("KUDOS:0")
assertEquals(AccountCreationResult.Success, db.account.create(
login = "merchant",
password = "merchant-password",
name = "Merchant",
internalPaytoUri = merchantPayto,
- maxDebt = TalerAmount(10, 0, "KUDOS"),
+ maxDebt = TalerAmount("KUDOS:10"),
isTalerExchange = false,
isPublic = false,
- bonus = null
+ bonus = bonus
))
assertEquals(AccountCreationResult.Success, db.account.create(
login = "exchange",
password = "exchange-password",
name = "Exchange",
internalPaytoUri = exchangePayto,
- maxDebt = TalerAmount(10, 0, "KUDOS"),
+ maxDebt = TalerAmount("KUDOS:10"),
isTalerExchange = true,
isPublic = false,
- bonus = null
+ bonus = bonus
))
assertEquals(AccountCreationResult.Success, db.account.create(
login = "customer",
password = "customer-password",
name = "Customer",
internalPaytoUri = customerPayto,
- maxDebt = TalerAmount(10, 0, "KUDOS"),
+ maxDebt = TalerAmount("KUDOS:10"),
isTalerExchange = false,
isPublic = false,
- bonus = null
+ bonus = bonus
))
// Create admin account
assertEquals(AccountCreationResult.Success, maybeCreateAdminAccount(db, ctx, "admin-password"))
diff --git a/contrib/libeufin-bank.conf b/contrib/libeufin-bank.conf
@@ -11,12 +11,7 @@ DEFAULT_CUSTOMER_DEBT_LIMIT = KUDOS:200
# admin account.
DEFAULT_ADMIN_DEBT_LIMIT = KUDOS:2000
-# Do newly registered bank customers receive
-# a sign-up bonus?
-REGISTRATION_BONUS_ENABLED = yes
-
# Value of the registration bonus for new users.
-# Only applicable of enabled.
REGISTRATION_BONUS = KUDOS:100
# Exchange that is suggested to wallets when withdrawing.