commit 7cdd0d203f2c43b293a32ec116a5fb8efe076137
parent 51d103762d3c19ad087b1c8191cfd0f0b652db6b
Author: Marcello Stanisci <stanisci.m@gmail.com>
Date: Tue, 3 Mar 2020 16:13:31 +0100
Return status of payments.
Diffstat:
2 files changed, 45 insertions(+), 10 deletions(-)
diff --git a/nexus/src/main/kotlin/tech/libeufin/nexus/JSON.kt b/nexus/src/main/kotlin/tech/libeufin/nexus/JSON.kt
@@ -1,5 +1,6 @@
package tech.libeufin.nexus
+import tech.libeufin.util.Amount
import tech.libeufin.util.EbicsDateRange
import tech.libeufin.util.EbicsOrderParams
import tech.libeufin.util.EbicsStandardOrderParams
@@ -118,4 +119,18 @@ data class EbicsAccountInfoElement(
data class EbicsAccountsInfoResponse(
var accounts: MutableList<EbicsAccountInfoElement> = mutableListOf()
+)
+
+data class PaymentInfoElement(
+ val debtorAccount: String,
+ val creditorIban: String,
+ val creditorBic: String,
+ val creditorName: String,
+ val subject: String,
+ val sum: Amount,
+ val submitted: Boolean
+)
+
+data class PaymentsInfo(
+ var payments: MutableList<PaymentInfoElement> = mutableListOf()
)
\ No newline at end of file
diff --git a/nexus/src/main/kotlin/tech/libeufin/nexus/Main.kt b/nexus/src/main/kotlin/tech/libeufin/nexus/Main.kt
@@ -486,16 +486,14 @@ fun main() {
return@get
}
- /* need primitive that crawls the database of pending payments and generates PAIN.001
- * after those. */
-
+ /**
+ * This endpoint gathers all the data needed to create a payment and persists it
+ * into the database. However, it does NOT perform the payment itself!
+ */
post("/ebics/subscribers/{id}/accounts/{acctid}/prepare-payment") {
val acctid = expectId(call.parameters["acctid"])
val subscriberId = expectId(call.parameters["id"])
- val accountDetails: EbicsAccountInfoElement = getBankAccountDetailsFromAcctid(acctid)
- val subscriberDetails = getSubscriberDetailsFromId(subscriberId)
-
transaction {
val accountinfo = EbicsAccountInfoEntity.findById(acctid)
val subscriber = EbicsSubscriberEntity.findById(subscriberId)
@@ -506,15 +504,37 @@ fun main() {
val pain001data = call.receive<Pain001Data>()
createPain001entry(pain001data, acctid)
-
call.respond(NexusErrorJson("Payment instructions persisted in DB"))
return@post
-
- // FIXME(marcello): Put transaction in the database, generate PAIN.001 document
}
get("/ebics/subscribers/{id}/payments") {
- // FIXME(marcello): List all outgoing transfers and their status
+
+ val id = expectId(call.parameters["id"])
+ val ret = PaymentsInfo()
+ transaction {
+ EbicsAccountInfoEntity.find {
+ EbicsAccountsInfoTable.subscriber eq id
+ }.forEach {
+ val element = Pain001Entity.find {
+ Pain001Table.debtorAccount eq it.id.value
+ }.forEach {
+ ret.payments.add(
+ PaymentInfoElement(
+ debtorAccount = it.debtorAccount,
+ creditorIban = it.creditorIban,
+ creditorBic = it.creditorBic,
+ creditorName = it.creditorName,
+ subject = it.subject,
+ sum = it.sum,
+ submitted = it.submitted // whether Nexus processed and sent to the bank
+ )
+ )
+ }
+ }
+ }
+ call.respond(ret)
+ return@get
}
post("/ebics/subscribers/{id}/fetch-payment-status") {