libeufin

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

commit b14953d651990c952bcb66095a0c0e3512b38b03
parent ddef3b151f6cf3a2b4884698c0bdde2b046b0314
Author: MS <ms@taler.net>
Date:   Wed, 20 Sep 2023 16:49:45 +0200

Testing Taler integration API.

Diffstat:
Mbank/src/main/kotlin/tech/libeufin/bank/helpers.kt | 8++++++--
Mbank/src/main/kotlin/tech/libeufin/bank/talerIntegrationHandlers.kt | 34+++++++++++++++++++++++-----------
Mbank/src/test/kotlin/TalerApiTest.kt | 55+++++++++++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 84 insertions(+), 13 deletions(-)

diff --git a/bank/src/main/kotlin/tech/libeufin/bank/helpers.kt b/bank/src/main/kotlin/tech/libeufin/bank/helpers.kt @@ -372,7 +372,11 @@ fun getTalerWithdrawUri(baseUrl: String, woId: String) = this.appendPathSegments(pathSegments) } -fun getWithdrawalConfirmUrl(baseUrl: String, wopId: String) = +fun getWithdrawalConfirmUrl( + baseUrl: String, + wopId: String, + username: String + ) = url { val baseUrlObj = URL(baseUrl) protocol = URLProtocol(name = baseUrlObj.protocol, defaultPort = -1) @@ -382,7 +386,7 @@ fun getWithdrawalConfirmUrl(baseUrl: String, wopId: String) = this.appendPathSegments(it) } // Completing the endpoint: - this.appendPathSegments("${wopId}/confirm") + this.appendPathSegments("accounts/${username}/withdrawals/${wopId}/confirm") } diff --git a/bank/src/main/kotlin/tech/libeufin/bank/talerIntegrationHandlers.kt b/bank/src/main/kotlin/tech/libeufin/bank/talerIntegrationHandlers.kt @@ -44,9 +44,13 @@ fun Routing.talerIntegrationHandlers() { throw internalServerError("Bank has a withdrawal not related to any bank account.") val suggestedExchange = db.configGet("suggested_exchange") ?: throw internalServerError("Bank does not have an exchange to suggest.") + val walletCustomer = db.customerGetFromRowId(relatedBankAccount.owningCustomerId) + if (walletCustomer == null) + throw internalServerError("Could not resort the username that owns this withdrawal") val confirmUrl = getWithdrawalConfirmUrl( baseUrl = call.request.getBaseUrl() ?: throw internalServerError("Could not get bank own base URL."), - wopId = wopid + wopId = wopid, + username = walletCustomer.login ) call.respond(BankWithdrawalOperationStatus( aborted = op.aborted, @@ -88,19 +92,26 @@ fun Routing.talerIntegrationHandlers() { if (!dbSuccess) // Whatever the problem, the bank missed it: respond 500. throw internalServerError("Bank failed at selecting the withdrawal.") + // Getting user details that MIGHT be used later. + val confirmUrl: String? = if (!op.confirmationDone) { + val walletBankAccount = db.bankAccountGetFromOwnerId(op.walletBankAccount) + ?: throw internalServerError("Could not resort the bank account owning this withdrawal") + val walletCustomer = db.customerGetFromRowId(walletBankAccount.owningCustomerId) + ?: throw internalServerError("Could not resort the username owning this withdrawal") + getWithdrawalConfirmUrl( + baseUrl = call.request.getBaseUrl() + ?: throw internalServerError("Could not get bank own base URL."), + wopId = wopid, + username = walletCustomer.login + ) + } + else + null val resp = BankWithdrawalOperationPostResponse( transfer_done = op.confirmationDone, - confirm_transfer_url = if (!op.confirmationDone) - getWithdrawalConfirmUrl( - baseUrl = call.request.getBaseUrl() - ?: throw internalServerError("Could not get bank own base URL."), - wopId = wopid - ) - else - null + confirm_transfer_url = confirmUrl ) call.respond(resp) return@post } -} - +} +\ No newline at end of file diff --git a/bank/src/test/kotlin/TalerApiTest.kt b/bank/src/test/kotlin/TalerApiTest.kt @@ -27,6 +27,61 @@ class TalerApiTest { hasDebt = false, maxDebt = TalerAmount(10, 1, "KUDOS") ) + // Selecting withdrawal details from the Integrtion API endpoint. + @Test + fun intSelect() { + val db = initDb() + val uuid = UUID.randomUUID() + assert(db.customerCreate(customerFoo) != null) + assert(db.bankAccountCreate(bankAccountFoo)) + db.configSet( + "suggested_exchange", + "payto://suggested-exchange" + ) + // insert new. + assert(db.talerWithdrawalCreate( + opUUID = uuid, + walletBankAccount = 1L, + amount = TalerAmount(1, 0) + )) + testApplication { + application(webApp) + val r = client.post("/taler-integration/withdrawal-operation/${uuid}") { + expectSuccess = true + contentType(ContentType.Application.Json) + setBody(""" + {"reserve_pub": "RESERVE-FOO", + "selected_exchange": "payto://selected/foo/exchange" } + """.trimIndent()) + } + println(r.bodyAsText()) + } + } + // Showing withdrawal details from the Integrtion API endpoint. + @Test + fun intGet() { + val db = initDb() + val uuid = UUID.randomUUID() + assert(db.customerCreate(customerFoo) != null) + assert(db.bankAccountCreate(bankAccountFoo)) + db.configSet( + "suggested_exchange", + "payto://suggested-exchange" + ) + // insert new. + assert(db.talerWithdrawalCreate( + opUUID = uuid, + walletBankAccount = 1L, + amount = TalerAmount(1, 0) + )) + testApplication { + application(webApp) + val r = client.get("/taler-integration/withdrawal-operation/${uuid}") { + expectSuccess = true + } + println(r.bodyAsText()) + } + } // Testing withdrawal abort @Test fun withdrawalAbort() {