diff options
author | MS <ms@taler.net> | 2023-01-20 15:18:09 +0100 |
---|---|---|
committer | MS <ms@taler.net> | 2023-01-20 16:39:58 +0100 |
commit | 57f578ddcd03cc8efd9c51d470b875e2ee0a6b52 (patch) | |
tree | ec8c71d1f722b21ae2ae0e6c8d4cf3c8e65575df /sandbox/src/main/kotlin/tech/libeufin | |
parent | 907eb293905ff709afc9229c13249b8b199f653a (diff) | |
download | libeufin-57f578ddcd03cc8efd9c51d470b875e2ee0a6b52.tar.gz libeufin-57f578ddcd03cc8efd9c51d470b875e2ee0a6b52.tar.bz2 libeufin-57f578ddcd03cc8efd9c51d470b875e2ee0a6b52.zip |
Circuit API.
Including the confirmation time along
the cash-out operation details.
Diffstat (limited to 'sandbox/src/main/kotlin/tech/libeufin')
-rw-r--r-- | sandbox/src/main/kotlin/tech/libeufin/sandbox/CircuitApi.kt | 51 | ||||
-rw-r--r-- | sandbox/src/main/kotlin/tech/libeufin/sandbox/DB.kt | 6 |
2 files changed, 37 insertions, 20 deletions
diff --git a/sandbox/src/main/kotlin/tech/libeufin/sandbox/CircuitApi.kt b/sandbox/src/main/kotlin/tech/libeufin/sandbox/CircuitApi.kt index a6e97778..721b3c16 100644 --- a/sandbox/src/main/kotlin/tech/libeufin/sandbox/CircuitApi.kt +++ b/sandbox/src/main/kotlin/tech/libeufin/sandbox/CircuitApi.kt @@ -13,7 +13,6 @@ import java.io.File import java.io.InputStreamReader import java.math.BigDecimal import java.math.MathContext -import java.util.* import java.util.concurrent.TimeUnit import kotlin.text.toByteArray @@ -86,6 +85,17 @@ data class CircuitAccountInfo( val cashout_address: String ) +data class CashoutOperationInfo( + val state: CashoutOperationState, + val amount_credit: String, + val amount_debit: String, + val subject: String, + val creation_time: Long, // milliseconds + val confirmation_time: Long?, // milliseconds + val tan_channel: SupportedTanChannels, + val account: String +) + data class CashoutConfirmation(val tan: String) // Validate phone number @@ -241,13 +251,16 @@ fun circuitApi(circuitRoute: Route) { * NOTE: the funds availability got already checked when this operation * was created. On top of that, the 'wireTransfer()' helper does also * check for funds availability. */ - wireTransfer( - debitAccount = op.account, - creditAccount = "admin", - subject = op.subject, - amount = op.amountDebit - ) - transaction { op.state = CashoutOperationState.CONFIRMED } + transaction { + wireTransfer( + debitAccount = op.account, + creditAccount = "admin", + subject = op.subject, + amount = op.amountDebit + ) + op.state = CashoutOperationState.CONFIRMED + op.confirmationTime = getUTCnow().toInstant().toEpochMilli() + } call.respond(HttpStatusCode.NoContent) return@post } @@ -263,15 +276,17 @@ fun circuitApi(circuitRoute: Route) { } if (maybeOperation == null) throw notFound("Cash-out operation $operationUuid not found.") - 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 - }) + val ret = CashoutOperationInfo( + amount_credit = maybeOperation.amountCredit, + amount_debit = maybeOperation.amountDebit, + subject = maybeOperation.subject, + state = maybeOperation.state, + creation_time = maybeOperation.creationTime, + confirmation_time = maybeOperation.confirmationTime, + tan_channel = maybeOperation.tanChannel, + account = maybeOperation.account + ) + call.respond(ret) return@get } // Gets the list of all the cash-out operations. @@ -354,7 +369,7 @@ fun circuitApi(circuitRoute: Route) { this.amountCredit = req.amount_credit this.subject = cashoutSubject this.creationTime = getUTCnow().toInstant().toEpochMilli() - this.tanChannel = tanChannel + this.tanChannel = SupportedTanChannels.valueOf(tanChannel) this.account = user this.tan = getRandomString(5) } diff --git a/sandbox/src/main/kotlin/tech/libeufin/sandbox/DB.kt b/sandbox/src/main/kotlin/tech/libeufin/sandbox/DB.kt index 3adb1a27..92171281 100644 --- a/sandbox/src/main/kotlin/tech/libeufin/sandbox/DB.kt +++ b/sandbox/src/main/kotlin/tech/libeufin/sandbox/DB.kt @@ -442,8 +442,9 @@ object CashoutOperationsTable : LongIdTable() { val amountDebit = text("amountDebit") val amountCredit = text("amountCredit") val subject = text("subject") - val creationTime = long("creationTime") // in seconds. - val tanChannel = text("tanChannel") + val creationTime = long("creationTime") // in milliseconds. + val confirmationTime = long("confirmationTime").nullable() // in milliseconds. + val tanChannel = enumeration("tanChannel", SupportedTanChannels::class) val account = text("account") val tan = text("tan") val state = enumeration("state", CashoutOperationState::class).default(CashoutOperationState.PENDING) @@ -456,6 +457,7 @@ class CashoutOperationEntity(id: EntityID<Long>) : LongEntity(id) { var amountCredit by CashoutOperationsTable.amountCredit var subject by CashoutOperationsTable.subject var creationTime by CashoutOperationsTable.creationTime + var confirmationTime by CashoutOperationsTable.confirmationTime var tanChannel by CashoutOperationsTable.tanChannel var account by CashoutOperationsTable.account var tan by CashoutOperationsTable.tan |