commit b06d03ffa1409f0043fe29c26fdbd9548a19d69b
parent da0c0cdc71d27670aba52dc566fb146046bffdc9
Author: MS <ms@taler.net>
Date: Wed, 8 Jul 2020 12:07:11 +0200
return list of initiated payments (API)
Diffstat:
3 files changed, 28 insertions(+), 1 deletion(-)
diff --git a/nexus/src/main/kotlin/tech/libeufin/nexus/bankaccount/BankAccount.kt b/nexus/src/main/kotlin/tech/libeufin/nexus/bankaccount/BankAccount.kt
@@ -39,6 +39,18 @@ import java.time.Instant
import java.time.ZonedDateTime
import java.time.format.DateTimeFormatter
+fun requireBankAccount(call: ApplicationCall, parameterKey: String): NexusBankAccountEntity {
+ val name = call.parameters[parameterKey]
+ if (name == null) {
+ throw NexusError(HttpStatusCode.InternalServerError, "no parameter for bank account")
+ }
+ val account = transaction { NexusBankAccountEntity.findById(name) }
+ if (account == null) {
+ throw NexusError(HttpStatusCode.NotFound, "bank connection '$name' not found")
+ }
+ return account
+}
+
suspend fun submitPaymentInitiation(httpClient: HttpClient, paymentInitiationId: Long) {
val r = transaction {
@@ -337,7 +349,6 @@ fun importBankAccount(call: ApplicationCall, offeredBankAccountId: String, nexus
newImportedAccount
}
}
- // importedAccount could be now-or-earlier imported.
OfferedBankAccountsTable.update(
{OfferedBankAccountsTable.offeredAccountId eq offeredBankAccountId and
(OfferedBankAccountsTable.bankConnection eq conn.id.value) }
diff --git a/nexus/src/main/kotlin/tech/libeufin/nexus/server/JSON.kt b/nexus/src/main/kotlin/tech/libeufin/nexus/server/JSON.kt
@@ -398,3 +398,7 @@ data class AccountEntryItemJson(
val entryAmount: CurrencyAmount,
val status: EntryStatus
)
+
+data class InitiatedPayments(
+ val initiatedPayments: MutableList<String> = mutableListOf()
+)
diff --git a/nexus/src/main/kotlin/tech/libeufin/nexus/server/NexusServer.kt b/nexus/src/main/kotlin/tech/libeufin/nexus/server/NexusServer.kt
@@ -477,6 +477,18 @@ fun serverMain(dbName: String, host: String) {
return@post
}
+ get("/bank-accounts/{accountid}/payment-initiations") {
+ val ret = InitiatedPayments()
+ transaction {
+ val bankAccount = requireBankAccount(call, "accountid")
+ PaymentInitiationEntity.find {
+ PaymentInitiationsTable.bankAccount eq bankAccount.id.value
+ }.forEach { ret.initiatedPayments.add(it.id.toString()) }
+ }
+ call.respond(ret)
+ return@get
+ }
+
// Shows information about one particular payment initiation.
get("/bank-accounts/{accountid}/payment-initiations/{uuid}") {
val res = transaction {