libeufin

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

commit b28f1511dab120ef2bfeef39801a0058c543138b
parent 1e1464497948747c59c3b0fcf859c257b6ea212e
Author: MS <ms@taler.net>
Date:   Fri, 20 Jan 2023 14:49:47 +0100

Circuit API.

Storing and showing more details about a cash-out
operation -- used to be only the state.

Avoiding showing accounts not added via the Circuit
API along its "GET /accounts" response.

Diffstat:
Msandbox/src/main/kotlin/tech/libeufin/sandbox/CircuitApi.kt | 43+++++++++++++++++++++++++++++++++++++++++--
Msandbox/src/main/kotlin/tech/libeufin/sandbox/DB.kt | 2++
Mutil/src/main/kotlin/HTTP.kt | 1+
3 files changed, 44 insertions(+), 2 deletions(-)

diff --git a/sandbox/src/main/kotlin/tech/libeufin/sandbox/CircuitApi.kt b/sandbox/src/main/kotlin/tech/libeufin/sandbox/CircuitApi.kt @@ -1,5 +1,6 @@ package tech.libeufin.sandbox +import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper import io.ktor.server.application.* import io.ktor.http.* import io.ktor.server.request.* @@ -262,7 +263,32 @@ fun circuitApi(circuitRoute: Route) { } if (maybeOperation == null) throw notFound("Cash-out operation $operationUuid not found.") - call.respond(object { val status = maybeOperation.state }) + call.respond(object { + val status = maybeOperation.state + val amount_credit = maybeOperation.amountCredit + val amount_debit = maybeOperation.amountDebit + val subject = maybeOperation.subject + val creation_time = maybeOperation.creationTime.toString() + val cashout_address = maybeOperation.tanChannel + val account = maybeOperation.account + }) + return@get + } + // Gets the list of all the cash-out operations. + circuitRoute.get("/cashouts") { + call.request.basicAuth(onlyAdmin = true) + val node = jacksonObjectMapper().createObjectNode() + val maybeArray = node.putArray("cashouts") + transaction { + CashoutOperationEntity.all().forEach { + maybeArray.add(it.uuid.toString()) + } + } + if (maybeArray.size() == 0) { + call.respond(HttpStatusCode.NoContent) + return@get + } + call.respond(node) return@get } // Create a cash-out operation. @@ -325,8 +351,9 @@ fun circuitApi(circuitRoute: Route) { val op = transaction { CashoutOperationEntity.new { this.amountDebit = req.amount_debit + this.amountCredit = req.amount_credit this.subject = cashoutSubject - this.creationTime = getUTCnow().toInstant().epochSecond + this.creationTime = getUTCnow().toInstant().toEpochMilli() this.tanChannel = tanChannel this.account = user this.tan = getRandomString(5) @@ -395,6 +422,11 @@ fun circuitApi(circuitRoute: Route) { throwIfInstitutionalName(resourceName) allowOwnerOrAdmin(username, resourceName) val customer = getCustomer(resourceName) + /** FIXME: the following query can 404, but should 500. + * The reason is that that's the bank's fault if an existing + * customer misses the bank account. Check other calls too, + * for the same error. + */ val bankAccount = getBankAccountFromLabel(resourceName) /** * Throwing when name or cash-out address aren't found ensures @@ -420,6 +452,13 @@ fun circuitApi(circuitRoute: Route) { val customers = mutableListOf<Any>() transaction { DemobankCustomerEntity.all().forEach { + if (it.cashout_address == null) { + logger.debug("Not listing account '${it.username}', as that" + + " misses the cash-out address " + + "and therefore doesn't belong to the Circuit API" + ) + return@forEach + } customers.add(object { val username = it.username val name = it.name diff --git a/sandbox/src/main/kotlin/tech/libeufin/sandbox/DB.kt b/sandbox/src/main/kotlin/tech/libeufin/sandbox/DB.kt @@ -440,6 +440,7 @@ object CashoutOperationsTable : LongIdTable() { * local currency bank account. */ val amountDebit = text("amountDebit") + val amountCredit = text("amountCredit") val subject = text("subject") val creationTime = long("creationTime") // in seconds. val tanChannel = text("tanChannel") @@ -452,6 +453,7 @@ class CashoutOperationEntity(id: EntityID<Long>) : LongEntity(id) { companion object : LongEntityClass<CashoutOperationEntity>(CashoutOperationsTable) var uuid by CashoutOperationsTable.uuid var amountDebit by CashoutOperationsTable.amountDebit + var amountCredit by CashoutOperationsTable.amountCredit var subject by CashoutOperationsTable.subject var creationTime by CashoutOperationsTable.creationTime var tanChannel by CashoutOperationsTable.tanChannel diff --git a/util/src/main/kotlin/HTTP.kt b/util/src/main/kotlin/HTTP.kt @@ -4,6 +4,7 @@ import UtilError import io.ktor.http.* import io.ktor.server.application.* import io.ktor.server.request.* +import io.ktor.server.response.* import io.ktor.server.util.* import io.ktor.util.* import logger