commit ccba644bd59347255a4740575170e96353f24304
parent 4199e9b6817c88c37903ec6ca7e662e46f579b9e
Author: Florian Dold <florian@dold.me>
Date: Sun, 17 Jan 2021 01:04:47 +0100
improve sandbox transaction history
Diffstat:
3 files changed, 41 insertions(+), 11 deletions(-)
diff --git a/sandbox/src/main/kotlin/tech/libeufin/sandbox/JSON.kt b/sandbox/src/main/kotlin/tech/libeufin/sandbox/JSON.kt
@@ -19,6 +19,7 @@
package tech.libeufin.sandbox
+import tech.libeufin.util.PaymentInfo
import tech.libeufin.util.RawPayment
/**
@@ -51,6 +52,13 @@ data class PaymentsResponse(
)
/**
+ * List type that show all the payments existing in the system.
+ */
+data class AccountTransactions(
+ val payments: MutableList<PaymentInfo> = mutableListOf()
+)
+
+/**
* Used to create AND show one Ebics subscriber in the system.
*/
data class EbicsSubscriberElement(
diff --git a/sandbox/src/main/kotlin/tech/libeufin/sandbox/Main.kt b/sandbox/src/main/kotlin/tech/libeufin/sandbox/Main.kt
@@ -74,6 +74,7 @@ import tech.libeufin.sandbox.BankAccountTransactionsTable.debtorBic
import tech.libeufin.sandbox.BankAccountTransactionsTable.debtorIban
import tech.libeufin.sandbox.BankAccountTransactionsTable.debtorName
import tech.libeufin.sandbox.BankAccountTransactionsTable.direction
+import tech.libeufin.sandbox.BankAccountTransactionsTable.pmtInfId
import tech.libeufin.util.*
import tech.libeufin.util.ebics_h004.EbicsResponse
import tech.libeufin.util.ebics_h004.EbicsTypes
@@ -425,7 +426,7 @@ fun serverMain(dbName: String, port: Int) {
call.respond(accounts)
}
get("/admin/bank-accounts/{label}/transactions") {
- val ret = PaymentsResponse()
+ val ret = AccountTransactions()
transaction {
val accountLabel = ensureNonNull(call.parameters["label"])
transaction {
@@ -433,28 +434,32 @@ fun serverMain(dbName: String, port: Int) {
BankAccountTransactionsTable.select { BankAccountTransactionsTable.account eq account.id }
.forEach {
ret.payments.add(
- RawPayment(
+ PaymentInfo(
+ accountLabel = account.label,
creditorIban = it[creditorIban],
- debitorIban = it[debtorIban],
+ // FIXME: We need to modify the transactions table to have an actual
+ // account servicer reference here.
+ accountServicerReference = it[pmtInfId],
+ debtorIban = it[debtorIban],
subject = it[BankAccountTransactionsTable.subject],
date = it[date].toHttpDateString(),
amount = it[amount],
creditorBic = it[creditorBic],
creditorName = it[creditorName],
- debitorBic = it[debtorBic],
- debitorName = it[debtorName],
+ debtorBic = it[debtorBic],
+ debtorName = it[debtorName],
currency = it[currency],
- direction = it[direction]
+ creditDebitIndicator = when (it[direction]) {
+ "CRDT" -> "credit"
+ "DBIT" -> "debit"
+ else -> throw Error("invalid direction")
+ }
)
)
}
}
}
- call.respond(
- object {
- val payments = ret
- }
- )
+ call.respond(ret)
}
post("/admin/bank-accounts/{label}/generate-transactions") {
transaction {
diff --git a/util/src/main/kotlin/JSON.kt b/util/src/main/kotlin/JSON.kt
@@ -53,3 +53,19 @@ data class IncomingPaymentInfo(
val currency: String,
val subject: String
)
+
+data class PaymentInfo(
+ val accountLabel: String,
+ val creditorIban: String,
+ val creditorBic: String?,
+ val creditorName: String,
+ val debtorIban: String,
+ val debtorBic: String?,
+ val debtorName: String,
+ val amount: String,
+ val currency: String,
+ val subject: String,
+ val date: String? = null,
+ val creditDebitIndicator: String,
+ val accountServicerReference: String
+)
+\ No newline at end of file