commit 28f5733f768fa81b75f4794196fc59c748b7a583
parent b181be75916448fbe4378e3de13fbc2944279cce
Author: Antoine A <>
Date: Fri, 5 Sep 2025 18:33:41 +0200
bank: use config base url when set
Diffstat:
3 files changed, 23 insertions(+), 24 deletions(-)
diff --git a/bank/src/main/kotlin/tech/libeufin/bank/api/BankIntegrationApi.kt b/bank/src/main/kotlin/tech/libeufin/bank/api/BankIntegrationApi.kt
@@ -58,7 +58,7 @@ fun Routing.bankIntegrationApi(db: Database, ctx: BankConfig) {
)
call.respond(op.copy(
suggested_exchange = ctx.suggestedWithdrawalExchange,
- confirm_transfer_url = if (op.status == WithdrawalStatus.pending || op.status == WithdrawalStatus.selected) call.request.withdrawConfirmUrl(uuid) else null
+ confirm_transfer_url = if (op.status == WithdrawalStatus.pending || op.status == WithdrawalStatus.selected) call.request.withdrawConfirmUrl(ctx.baseUrl, uuid) else null
))
}
post("/taler-integration/withdrawal-operation/{wopid}") {
@@ -113,7 +113,7 @@ fun Routing.bankIntegrationApi(db: Database, ctx: BankConfig) {
call.respond(BankWithdrawalOperationPostResponse(
transfer_done = res.status == WithdrawalStatus.confirmed,
status = res.status,
- confirm_transfer_url = if (res.status == WithdrawalStatus.pending || res.status == WithdrawalStatus.selected) call.request.withdrawConfirmUrl(uuid) else null
+ confirm_transfer_url = if (res.status == WithdrawalStatus.pending || res.status == WithdrawalStatus.selected) call.request.withdrawConfirmUrl(ctx.baseUrl, uuid) else null
))
}
}
diff --git a/bank/src/main/kotlin/tech/libeufin/bank/api/CoreBankApi.kt b/bank/src/main/kotlin/tech/libeufin/bank/api/CoreBankApi.kt
@@ -574,7 +574,7 @@ private fun Routing.coreBankWithdrawalApi(db: Database, cfg: BankConfig) {
call.respond(
BankAccountCreateWithdrawalResponse(
withdrawal_id = opId.toString(),
- taler_withdraw_uri = call.request.talerWithdrawUri(opId)
+ taler_withdraw_uri = call.request.talerWithdrawUri(cfg.baseUrl, opId)
)
)
}
diff --git a/bank/src/main/kotlin/tech/libeufin/bank/helpers.kt b/bank/src/main/kotlin/tech/libeufin/bank/helpers.kt
@@ -43,6 +43,18 @@ import java.util.*
suspend fun ApplicationCall.bankInfo(db: Database): BankInfo
= db.account.bankInfo(username) ?: throw unknownAccount(username)
+private fun ApplicationRequest.fallbackBase() = BaseURL.parse(url {
+ protocol = URLProtocol(
+ name = origin.scheme,
+ defaultPort = -1
+ )
+ host = "${origin.serverHost}:${origin.serverPort}"
+ headers[X_FORWARD_PREFIX]?.let {
+ appendPathSegments(it)
+ }
+ appendPathSegments("")
+})
+
/**
* Builds the taler://withdraw-URI. Such URI will serve the requests
* from wallets, when they need to manage the operation. For example,
@@ -51,29 +63,16 @@ suspend fun ApplicationCall.bankInfo(db: Database): BankInfo
*
* https://$BANK_URL/taler-integration
*/
-fun ApplicationRequest.talerWithdrawUri(id: UUID) = url {
- protocol = URLProtocol(
- name = if (origin.scheme == "http") "taler+http" else "taler",
- defaultPort = -1
- )
- host = "withdraw"
- appendPathSegments("${origin.serverHost}:${origin.serverPort}")
- headers[X_FORWARD_PREFIX]?.let {
- appendPathSegments(it)
- }
- appendPathSegments("taler-integration", id.toString())
+fun ApplicationRequest.talerWithdrawUri(baseUrl: BaseURL?, id: UUID): String {
+ val base = (baseUrl ?: fallbackBase()).url
+ val protocol = if (base.protocol == "http") "taler+http" else "taler"
+ val port = if (base.port != -1) ":${base.port}" else ""
+ return "${protocol}://withdraw/${base.host}${port}${base.path}taler-integration/${id}"
}
-fun ApplicationRequest.withdrawConfirmUrl(id: UUID) = url {
- protocol = URLProtocol(
- name = origin.scheme,
- defaultPort = -1
- )
- host = "${origin.serverHost}:${origin.serverPort}"
- headers[X_FORWARD_PREFIX]?.let {
- appendPathSegments(it)
- }
- appendEncodedPathSegments("webui", "#", "operation", id.toString())
+fun ApplicationRequest.withdrawConfirmUrl(baseUrl: BaseURL?, id: UUID): String {
+ val base = (baseUrl ?: fallbackBase()).url
+ return "${base}webui/#/operation/${id}"
}
/**