gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[libeufin] branch master updated (4bead8c6 -> 545bce3b)


From: gnunet
Subject: [libeufin] branch master updated (4bead8c6 -> 545bce3b)
Date: Wed, 22 Nov 2023 08:09:55 +0100

This is an automated email from the git hooks/post-receive script.

ms pushed a change to branch master
in repository libeufin.

    from 4bead8c6 nexus fetch: adapting the parser to camt.054 2019
     new 7a0acd61 nexus fetch: fix helper invocation
     new 545bce3b nexus fetch, bouncing low amounts

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 database-versioning/libeufin-nexus-procedures.sql  |  5 +-
 .../main/kotlin/tech/libeufin/nexus/Database.kt    | 12 ++---
 .../main/kotlin/tech/libeufin/nexus/EbicsFetch.kt  | 19 ++++++--
 nexus/src/test/kotlin/DatabaseTest.kt              | 53 ++++++++++++++++++++++
 4 files changed, 76 insertions(+), 13 deletions(-)

diff --git a/database-versioning/libeufin-nexus-procedures.sql 
b/database-versioning/libeufin-nexus-procedures.sql
index 7a36b91a..918bedf3 100644
--- a/database-versioning/libeufin-nexus-procedures.sql
+++ b/database-versioning/libeufin-nexus-procedures.sql
@@ -9,6 +9,7 @@ CREATE OR REPLACE FUNCTION create_incoming_and_bounce(
   ,IN in_bank_transfer_id TEXT
   ,IN in_timestamp BIGINT
   ,IN in_request_uid TEXT
+  ,IN in_refund_amount taler_amount
   ,OUT out_ok BOOLEAN
 ) RETURNS BOOLEAN
 LANGUAGE plpgsql AS $$
@@ -39,7 +40,7 @@ INSERT INTO initiated_outgoing_transactions (
   ,initiation_time
   ,request_uid
   ) VALUES (
-    in_amount
+    in_refund_amount
     ,'refund: ' || in_wire_transfer_subject
     ,in_debit_payto_uri
     ,in_timestamp
@@ -56,7 +57,7 @@ INSERT INTO bounced_transactions (
 out_ok = TRUE;
 END $$;
 
-COMMENT ON FUNCTION create_incoming_and_bounce(taler_amount, TEXT, BIGINT, 
TEXT, TEXT, BIGINT, TEXT)
+COMMENT ON FUNCTION create_incoming_and_bounce(taler_amount, TEXT, BIGINT, 
TEXT, TEXT, BIGINT, TEXT, taler_amount)
   IS 'creates one incoming transaction with a bounced state and initiates its 
related refund.';
 
 CREATE OR REPLACE FUNCTION create_outgoing_payment(
diff --git a/nexus/src/main/kotlin/tech/libeufin/nexus/Database.kt 
b/nexus/src/main/kotlin/tech/libeufin/nexus/Database.kt
index 7e4c98e5..778db5b9 100644
--- a/nexus/src/main/kotlin/tech/libeufin/nexus/Database.kt
+++ b/nexus/src/main/kotlin/tech/libeufin/nexus/Database.kt
@@ -309,19 +309,19 @@ class Database(dbConfig: String): java.io.Closeable {
               ,?
               ,?
               ,?
+              ,(?,?)::taler_amount
             )""")
-
-        var finalAmount = paymentData.amount
-        if (refundAmount != null) finalAmount = refundAmount
-
-        stmt.setLong(1, finalAmount.value)
-        stmt.setInt(2, finalAmount.fraction)
+        stmt.setLong(1, paymentData.amount.value)
+        stmt.setInt(2, paymentData.amount.fraction)
         stmt.setString(3, paymentData.wireTransferSubject)
         stmt.setLong(4, executionTime)
         stmt.setString(5, paymentData.debitPaytoUri)
         stmt.setString(6, paymentData.bankTransferId)
         stmt.setLong(7, refundTimestamp)
         stmt.setString(8, requestUid)
+        val finalRefundAmount: TalerAmount = refundAmount ?: paymentData.amount
+        stmt.setLong(9, finalRefundAmount.value)
+        stmt.setInt(10, finalRefundAmount.fraction)
         val res = stmt.executeQuery()
         res.use {
             if (!it.next()) return@runConn false
diff --git a/nexus/src/main/kotlin/tech/libeufin/nexus/EbicsFetch.kt 
b/nexus/src/main/kotlin/tech/libeufin/nexus/EbicsFetch.kt
index 768dde2f..509a5493 100644
--- a/nexus/src/main/kotlin/tech/libeufin/nexus/EbicsFetch.kt
+++ b/nexus/src/main/kotlin/tech/libeufin/nexus/EbicsFetch.kt
@@ -202,8 +202,10 @@ fun getTalerAmount(
     if (currency.isEmpty()) throw Exception("Wrong helper invocation: currency 
is empty")
     val split = noCurrencyAmount.split(".")
     // only 1 (no fraction) or 2 (with fraction) sizes allowed.
-    if (split.size != 1 && split.size != 2) throw 
Exception("${errorMessagePrefix}invalid amount: $noCurrencyAmount")
-    val value = split[0].toLongOrNull() ?: throw 
Exception("${errorMessagePrefix}value part not a long")
+    if (split.size != 1 && split.size != 2)
+        throw Exception("${errorMessagePrefix}invalid amount: 
$noCurrencyAmount")
+    val value = split[0].toLongOrNull()
+        ?: throw Exception("${errorMessagePrefix}value part '${split[0]}' not 
a long")
     if (split.size == 1) return TalerAmount(
         value = value,
         fraction = 0,
@@ -342,6 +344,10 @@ private suspend fun ingestIncomingPayment(
             incomingPayment.amount,
             ctx.minimumAmount
         )) {
+        logger.debug("Incoming payment with UID 
'${incomingPayment.bankTransferId}'" +
+                " is too low: ${incomingPayment.amount}."
+        )
+
         /**
          * Setting the refund amount to zero makes the initiated
          * payment _never_ paid back.  Inserting this row merely
@@ -357,6 +363,9 @@ private suspend fun ingestIncomingPayment(
     }
     val reservePub = getTalerReservePub(db, incomingPayment)
     if (reservePub == null) {
+        logger.debug("Incoming payment with UID 
'${incomingPayment.bankTransferId}'" +
+                " has invalid subject: ${incomingPayment.wireTransferSubject}."
+        )
         db.incomingPaymentCreateBounced(
             incomingPayment,
             UUID.randomUUID().toString().take(35)
@@ -616,9 +625,9 @@ class EbicsFetch: CliktCommand("Fetches bank records.  
Defaults to camt.054 noti
         if (minAmountCfg != null) {
             minAmount = doOrFail {
                 getTalerAmount(
-                    cfg.currency,
-                    minAmountCfg,
-                    "[nexus-fetch]/minimum_amount, "
+                    noCurrencyAmount = minAmountCfg,
+                    currency = cfg.currency,
+                    "[nexus-fetch]/minimum_amount '$minAmountCfg', "
                 )
             }
         }
diff --git a/nexus/src/test/kotlin/DatabaseTest.kt 
b/nexus/src/test/kotlin/DatabaseTest.kt
index cacec157..03a709a7 100644
--- a/nexus/src/test/kotlin/DatabaseTest.kt
+++ b/nexus/src/test/kotlin/DatabaseTest.kt
@@ -45,6 +45,59 @@ class OutgoingPaymentsTest {
 
 // @Ignore // enable after having modified the bouncing logic in Kotlin
 class IncomingPaymentsTest {
+    @Test
+    fun bounceWithCustomRefund() {
+        val db = prepDb(TalerConfig(NEXUS_CONFIG_SOURCE))
+        runBlocking {
+            // creating and bouncing one incoming transaction.
+            assertTrue(
+                db.incomingPaymentCreateBounced(
+                    genIncPay("incoming and bounced"),
+                    "UID",
+                    TalerAmount(2, 53000000, "KUDOS")
+                )
+            )
+            db.runConn {
+                // check incoming shows up.
+                val checkIncoming = it.prepareStatement("""
+                    SELECT 
+                      (amount).val as amount_value
+                      ,(amount).frac as amount_frac
+                     FROM incoming_transactions
+                     WHERE incoming_transaction_id = 1;
+                """).executeQuery()
+                assertTrue(checkIncoming.next())
+                assertEquals(44, checkIncoming.getLong("amount_value"))
+                assertEquals(0, checkIncoming.getLong("amount_frac"))
+                // check bounced has the custom value
+                val findBounced = it.prepareStatement("""
+                    SELECT 
+                      initiated_outgoing_transaction_id
+                      FROM bounced_transactions
+                      WHERE incoming_transaction_id = 1;
+                """).executeQuery()
+                assertTrue(findBounced.next())
+                val initiatedId = 
findBounced.getLong("initiated_outgoing_transaction_id")
+                assertEquals(1, initiatedId)
+                val findInitiatedAmount = it.prepareStatement("""
+                    SELECT
+                      (amount).val as amount_value
+                      ,(amount).frac as amount_frac
+                    FROM initiated_outgoing_transactions
+                    WHERE initiated_outgoing_transaction_id = 1;
+                """).executeQuery()
+                assertTrue(findInitiatedAmount.next())
+                assertEquals(
+                    53000000,
+                    findInitiatedAmount.getInt("amount_frac")
+                )
+                assertEquals(
+                    2,
+                    findInitiatedAmount.getInt("amount_value")
+                )
+            }
+        }
+    }
     // Tests creating and bouncing incoming payments in one DB transaction.
     @Test
     fun incomingAndBounce() {

-- 
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]