commit 5b9bdf0f1a14a11beb1a30de38febc085050739e
parent 9638a496f1e0db6077e8b6ef7a38d7343f6f2dfe
Author: Marcello Stanisci <stanisci.m@gmail.com>
Date: Mon, 16 Mar 2020 19:33:24 +0100
Avoid submitting payments more than once.
Diffstat:
2 files changed, 12 insertions(+), 3 deletions(-)
diff --git a/nexus/src/main/kotlin/tech/libeufin/nexus/EbicsClient.kt b/nexus/src/main/kotlin/tech/libeufin/nexus/EbicsClient.kt
@@ -150,4 +150,4 @@ suspend fun doEbicsUploadTransaction(
throw NexusError(HttpStatusCode.InternalServerError,"unexpected return code")
}
}
-}
+}
+\ 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
@@ -520,11 +520,11 @@ fun main() {
* should be done AFTER the PAIN.002 data corresponding to a payment witnesses it.
*/
post("/ebics/admin/execute-payments") {
- val (painDoc: String, debtorAccount) = transaction {
+ val (paymentRowId, painDoc: String, debtorAccount) = transaction {
val entity = Pain001Entity.find {
Pain001Table.submitted eq false
}.firstOrNull() ?: throw NexusError(HttpStatusCode.Accepted, reason = "No ready payments found")
- kotlin.Pair(createPain001document(entity), entity.debtorAccount)
+ Triple(entity.id, createPain001document(entity), entity.debtorAccount)
}
logger.debug("Processing payment for bank account: ${debtorAccount}")
logger.debug("Uploading PAIN.001: ${painDoc}")
@@ -536,6 +536,14 @@ fun main() {
painDoc.toByteArray(Charsets.UTF_8),
EbicsStandardOrderParams()
)
+ /* flow here == no errors occurred */
+ transaction {
+ val payment = Pain001Entity.findById(paymentRowId) ?: throw NexusError(
+ HttpStatusCode.InternalServerError,
+ "Severe internal error: could not find payment in DB after having submitted it to the bank"
+ )
+ payment.submitted = true
+ }
call.respondText(
"CCT message submitted to the bank",
ContentType.Text.Plain,