[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[libeufin] branch master updated: Testing Taler integration API.
From: |
gnunet |
Subject: |
[libeufin] branch master updated: Testing Taler integration API. |
Date: |
Wed, 20 Sep 2023 16:50:06 +0200 |
This is an automated email from the git hooks/post-receive script.
ms pushed a commit to branch master
in repository libeufin.
The following commit(s) were added to refs/heads/master by this push:
new b14953d6 Testing Taler integration API.
b14953d6 is described below
commit b14953d651990c952bcb66095a0c0e3512b38b03
Author: MS <ms@taler.net>
AuthorDate: Wed Sep 20 16:49:45 2023 +0200
Testing Taler integration API.
---
bank/src/main/kotlin/tech/libeufin/bank/helpers.kt | 8 +++-
.../tech/libeufin/bank/talerIntegrationHandlers.kt | 33 ++++++++-----
bank/src/test/kotlin/TalerApiTest.kt | 55 ++++++++++++++++++++++
3 files changed, 83 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
index 9487679a..a71cf992 100644
--- 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
index ef66e7ef..665691dc 100644
--- 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
index c025ea10..06e4cbe4 100644
--- 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() {
--
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [libeufin] branch master updated: Testing Taler integration API.,
gnunet <=