libeufin

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

commit 9e836fd04bf792b2f6b87c17a9ab71c194a9d523
parent 4604071f1baa7f8d297295ddccb97b8e3adf1e5a
Author: MS <ms@taler.net>
Date:   Tue, 19 Sep 2023 15:29:34 +0200

Endpoint to GET withdrawal details.

Diffstat:
Mbank/src/main/kotlin/tech/libeufin/bank/talerWebHandlers.kt | 34++++++++++++++++++++++++++++++++--
Mbank/src/main/kotlin/tech/libeufin/bank/types.kt | 11+++++++++++
2 files changed, 43 insertions(+), 2 deletions(-)

diff --git a/bank/src/main/kotlin/tech/libeufin/bank/talerWebHandlers.kt b/bank/src/main/kotlin/tech/libeufin/bank/talerWebHandlers.kt @@ -25,10 +25,12 @@ package tech.libeufin.bank import io.ktor.server.application.* +import io.ktor.server.plugins.* import io.ktor.server.request.* import io.ktor.server.response.* import io.ktor.server.routing.* import net.taler.common.errorcodes.TalerErrorCode +import net.taler.wallet.crypto.Base32Crockford import tech.libeufin.util.getBaseUrl import java.util.* @@ -67,7 +69,7 @@ fun Routing.talerWebHandlers() { throw internalServerError("Bank failed at creating the withdraw operation.") val bankBaseUrl = call.request.getBaseUrl() - ?: throw internalServerError("Bank could not find its base URL") + ?: throw internalServerError("Bank could not find its own base URL") call.respond(BankAccountCreateWithdrawalResponse( withdrawal_id = opId.toString(), taler_withdraw_uri = getTalerWithdrawUri(bankBaseUrl, opId.toString()) @@ -75,7 +77,35 @@ fun Routing.talerWebHandlers() { return@post } get("/accounts/{USERNAME}/withdrawals/{W_ID}") { - throw NotImplementedError() + val c = call.myAuth(TokenScope.readonly) ?: throw unauthorized() + val accountName = call.expectUriComponent("USERNAME") + // Admin allowed to see the details + if (c.login != accountName && c.login != "admin") throw forbidden() + // Permissions passed, get the information. + val opIdParam: String = call.request.queryParameters.get("W_ID") ?: throw + MissingRequestParameterException("withdrawal_id") + val opId = try { + UUID.fromString(opIdParam) + } catch (e: Exception) { + logger.error(e.message) + throw badRequest("withdrawal_id query parameter was malformed") + } + val op = db.talerWithdrawalGet(opId) + ?: throw notFound( + hint = "Withdrawal operation ${opIdParam} not found", + talerEc = TalerErrorCode.TALER_EC_END + ) + call.respond(BankAccountGetWithdrawalResponse( + amount = op.amount.toString(), + aborted = op.aborted, + confirmation_done = op.confirmationDone, + selection_done = op.selectionDone, + selected_exchange_account = op.selectedExchangePayto, + selected_reserve_pub = if (op.reservePub != null) { + Base32Crockford.encode(op.reservePub) + } else null + )) + return@get } post("/accounts/{USERNAME}/withdrawals/abort") { throw NotImplementedError() diff --git a/bank/src/main/kotlin/tech/libeufin/bank/types.kt b/bank/src/main/kotlin/tech/libeufin/bank/types.kt @@ -395,3 +395,14 @@ data class BankAccountCreateWithdrawalResponse( val withdrawal_id: String, val taler_withdraw_uri: String ) + +// Taler withdrawal details response +@Serializable +data class BankAccountGetWithdrawalResponse( + val amount: String, + val aborted: Boolean, + val confirmation_done: Boolean, + val selection_done: Boolean, + val selected_reserve_pub: String? = null, + val selected_exchange_account: String? = null +)