commit 295ce2bc3fbb3adbae7a96a36c62151d671ce253
parent 1b2dc8e3fbffc20e1920fcc0250405d820a69d99
Author: MS <ms@taler.net>
Date: Thu, 2 Nov 2023 10:54:46 +0100
nexus db
method to set the failure message of initiated payments.
Diffstat:
3 files changed, 47 insertions(+), 1 deletion(-)
diff --git a/nexus/src/main/kotlin/tech/libeufin/nexus/Database.kt b/nexus/src/main/kotlin/tech/libeufin/nexus/Database.kt
@@ -340,6 +340,28 @@ class Database(dbConfig: String): java.io.Closeable {
}
/**
+ * Sets the failure message to an initiated payment. This text may
+ * come soon: as an internal failure at Nexus itself, or as the bank
+ * HTTP response of POSTing the EBICS document, or later: when asking
+ * the bank a pain.002 report.
+ *
+ * @param rowId row ID of the record to set.
+ * @param failureMessage error message from the bank.
+ * @return true on success, false if no payment was affected.
+ */
+ suspend fun initiatedPaymentSetFailureMessage(rowId: Long, failureMessage: String): Boolean = runConn { conn ->
+ val stmt = conn.prepareStatement("""
+ UPDATE initiated_outgoing_transactions
+ SET failure_message = ?
+ WHERE initiated_outgoing_transaction_id=?
+ """
+ )
+ stmt.setString(1, failureMessage)
+ stmt.setLong(2, rowId)
+ return@runConn stmt.maybeUpdate()
+ }
+
+ /**
* Gets any initiated payment that was not submitted to the
* bank yet.
*
diff --git a/nexus/src/test/kotlin/ConfigLoading.kt b/nexus/src/test/kotlin/ConfigLoading.kt
@@ -24,7 +24,7 @@ class ConfigLoading {
val handle = TalerConfig(NEXUS_CONFIG_SOURCE)
handle.load()
val cfg = EbicsSetupConfig(handle)
- cfg.config.requirePath("nexus-ebics-fetch", "statement_log_directory")
+ cfg.config.requirePath("nexus-fetch", "statement_log_directory")
}
diff --git a/nexus/src/test/kotlin/DatabaseTest.kt b/nexus/src/test/kotlin/DatabaseTest.kt
@@ -128,6 +128,30 @@ class IncomingPaymentsTest {
}
class PaymentInitiationsTest {
+ // Testing the insertion of the failure message.
+ @Test
+ fun setFailureMessage() {
+ val db = prepDb(TalerConfig(NEXUS_CONFIG_SOURCE))
+ runBlocking {
+ assertEquals(
+ db.initiatedPaymentCreate(genInitPay("not submitted, has row ID == 1")),
+ PaymentInitiationOutcome.SUCCESS
+ )
+ assertFalse(db.initiatedPaymentSetFailureMessage(3, "3 not existing"))
+ assertTrue(db.initiatedPaymentSetFailureMessage(1, "expired"))
+ // Checking the value from the database.
+ db.runConn { conn ->
+ val idOne = conn.execSQLQuery("""
+ SELECT failure_message
+ FROM initiated_outgoing_transactions
+ WHERE initiated_outgoing_transaction_id = 1;
+ """.trimIndent())
+ assertTrue(idOne.next())
+ val maybeMessage = idOne.getString("failure_message")
+ assertEquals("expired", maybeMessage)
+ }
+ }
+ }
// Tests the flagging of payments as submitted.
@Test
fun paymentInitiationSetAsSubmitted() {