[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[libeufin] branch master updated: Sandbox bank account API.
From: |
gnunet |
Subject: |
[libeufin] branch master updated: Sandbox bank account API. |
Date: |
Sat, 07 Aug 2021 17:10:36 +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 575613d Sandbox bank account API.
575613d is described below
commit 575613d4d9f4c63a07ed22f245944f5b34214a8b
Author: ms <ms@taler.net>
AuthorDate: Sat Aug 7 17:07:57 2021 +0200
Sandbox bank account API.
Adding endpoints to create bank accounts (no EBICS)
and asking their balances.
---
.../src/main/kotlin/tech/libeufin/sandbox/Main.kt | 38 ++++++++++++++++++++--
.../kotlin/tech/libeufin/sandbox/bankAccount.kt | 20 ++++++++++--
2 files changed, 53 insertions(+), 5 deletions(-)
diff --git a/sandbox/src/main/kotlin/tech/libeufin/sandbox/Main.kt
b/sandbox/src/main/kotlin/tech/libeufin/sandbox/Main.kt
index 9201fa3..5ce553d 100644
--- a/sandbox/src/main/kotlin/tech/libeufin/sandbox/Main.kt
+++ b/sandbox/src/main/kotlin/tech/libeufin/sandbox/Main.kt
@@ -198,7 +198,8 @@ data class BankAccountInfo(
val label: String,
val name: String,
val iban: String,
- val bic: String
+ val bic: String,
+ val currency: String?
)
data class BankAccountsListReponse(
@@ -449,6 +450,38 @@ fun serverMain(dbName: String, port: Int) {
return@post
}
+ post("/admin/bank-accounts/{label}") {
+ val body = call.receiveJson<BankAccountInfo>()
+ transaction {
+ BankAccountEntity.new {
+ iban = body.iban
+ bic = body.bic
+ name = body.name
+ label = body.label
+ currency = body.currency ?: "EUR"
+ }
+ }
+ call.respond(object {})
+ return@post
+ }
+
+ get("/admin/bank-accounts/{label}") {
+ val label = ensureNonNull(call.parameters["label"])
+ val ret = transaction {
+ val account = getAccountFromLabel(label)
+ val balance = balanceForAccount(account.iban)
+ object {
+ val balance = "${account.currency}:${balance}"
+ val iban = account.iban
+ val bic = account.bic
+ val name = account.name
+ val label = account.label
+ }
+ }
+ call.respond(ret)
+ return@get
+ }
+
post("/admin/bank-accounts/{label}/simulate-incoming-transaction")
{
val body = call.receiveJson<IncomingPaymentInfo>()
// FIXME: generate nicer UUID!
@@ -543,7 +576,8 @@ fun serverMain(dbName: String, port: Int) {
label = it.label,
name = it.name,
bic = it.bic,
- iban = it.iban
+ iban = it.iban,
+ currency = it.currency
)
)
}
diff --git a/sandbox/src/main/kotlin/tech/libeufin/sandbox/bankAccount.kt
b/sandbox/src/main/kotlin/tech/libeufin/sandbox/bankAccount.kt
index 0d81230..aac8246 100644
--- a/sandbox/src/main/kotlin/tech/libeufin/sandbox/bankAccount.kt
+++ b/sandbox/src/main/kotlin/tech/libeufin/sandbox/bankAccount.kt
@@ -1,5 +1,6 @@
package tech.libeufin.sandbox
+import io.ktor.http.*
import org.jetbrains.exposed.sql.or
import org.jetbrains.exposed.sql.select
import org.jetbrains.exposed.sql.transactions.transaction
@@ -10,12 +11,25 @@ import tech.libeufin.util.RawPayment
import tech.libeufin.util.importDateFromMillis
import tech.libeufin.util.parseDecimal
import tech.libeufin.util.toDashedDate
+import java.math.BigDecimal
private val logger: Logger = LoggerFactory.getLogger("tech.libeufin.sandbox")
-fun balanceForAccount(iban: String): java.math.BigDecimal {
+fun getAccountFromLabel(accountLabel: String): BankAccountEntity {
+ return transaction {
+ val account = BankAccountEntity.find {
+ BankAccountsTable.label eq accountLabel
+ }.firstOrNull()
+ if (account == null) throw SandboxError(
+ HttpStatusCode.NotFound, "Account '$accountLabel' not found"
+ )
+ account
+ }
+}
+
+fun balanceForAccount(iban: String): BigDecimal {
logger.debug("Calculating balance for account: ${iban}")
- var balance = java.math.BigDecimal.ZERO
+ var balance = BigDecimal.ZERO
transaction {
BankAccountTransactionsTable.select {
BankAccountTransactionsTable.creditorIban eq iban
@@ -35,7 +49,7 @@ fun balanceForAccount(iban: String): java.math.BigDecimal {
* the current CAMT generator happy. Negative amounts need to have their
* onw sub-tree in the report, see bug: #6962
*/
- if (balance < java.math.BigDecimal.ZERO) return java.math.BigDecimal.ZERO
+ if (balance < BigDecimal.ZERO) return BigDecimal.ZERO
return balance
}
--
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: Sandbox bank account API.,
gnunet <=