gnunet-svn
[Top][All Lists]
Advanced

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

[taler-merchant] 194/277: finish FIXMEs in private-get-orders-ID:


From: gnunet
Subject: [taler-merchant] 194/277: finish FIXMEs in private-get-orders-ID:
Date: Sun, 05 Jul 2020 20:51:47 +0200

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

grothoff pushed a commit to branch master
in repository merchant.

commit e006e76011b134b3b8479f68ec64c5b3e19d0f9d
Author: Christian Grothoff <christian@grothoff.org>
AuthorDate: Fri Jun 12 09:18:03 2020 +0200

    finish FIXMEs in private-get-orders-ID:
---
 .../taler-merchant-httpd_private-get-orders-ID.c   | 76 ++++++++++++++++++++--
 1 file changed, 72 insertions(+), 4 deletions(-)

diff --git a/src/backend/taler-merchant-httpd_private-get-orders-ID.c 
b/src/backend/taler-merchant-httpd_private-get-orders-ID.c
index d43c650..5635d63 100644
--- a/src/backend/taler-merchant-httpd_private-get-orders-ID.c
+++ b/src/backend/taler-merchant-httpd_private-get-orders-ID.c
@@ -76,6 +76,16 @@ struct TransferQuery
    */
   struct GNUNET_HashCode h_wire;
 
+  /**
+   * Value deposited (including deposit fee).
+   */
+  struct TALER_Amount amount_with_fee;
+
+  /**
+   * Deposit fee paid for this coin.
+   */
+  struct TALER_Amount deposit_fee;
+
   /**
    * Public key of the coin this is about.
    */
@@ -175,6 +185,11 @@ struct GetOrderRequestContext
    */
   struct TALER_Amount deposits_total;
 
+  /**
+   * Total amount in deposit fees we paid for all coins.
+   */
+  struct TALER_Amount deposit_fees_total;
+
   /**
    * Total value of the coins that the exchange deposited into our bank
    * account (confirmed or unconfirmed), including deposit fees.
@@ -356,6 +371,17 @@ deposit_get_cb (void *cls,
       GNUNET_free (tq);
       return;
     }
+    if (0 >
+        TALER_amount_add (&gorc->deposit_fees_total,
+                          &gorc->deposit_fees_total,
+                          &tq->deposit_fee))
+    {
+      gorc_resume (gorc,
+                   TALER_EC_GET_ORDERS_AMOUNT_ARITHMETIC_FAILURE,
+                   NULL);
+      GNUNET_free (tq);
+      return;
+    }
   }
   else
   {
@@ -462,7 +488,8 @@ deposit_cb (void *cls,
                                tq);
   tq->coin_pub = *coin_pub;
   tq->h_wire = *h_wire;
-  // FIXME: keep at least deposit_fee in 'tq'! needed later!
+  tq->amount_with_fee = *amount_with_fee;
+  tq->deposit_fee = *deposit_fee;
   tq->fo = TMH_EXCHANGES_find_exchange (exchange_url,
                                         NULL,
                                         GNUNET_NO,
@@ -547,6 +574,23 @@ process_refunds_cb (void *cls,
                                      refund_amount));
     return;
   }
+
+  /* For refunded coins, we are not charged deposit fees, so subtract those
+     again */
+  for (struct TransferQuery *tq = gorc->tq_head;
+       NULL != tq;
+       tq = tq->next)
+  {
+    if (0 ==
+        GNUNET_memcmp (&tq->coin_pub,
+                       coin_pub))
+    {
+      GNUNET_assert (0 <=
+                     TALER_amount_subtract (&gorc->deposit_fees_total,
+                                            &gorc->deposit_fees_total,
+                                            &tq->deposit_fee));
+    }
+  }
   gorc->refund_amount = *refund_amount;
   gorc->refunded = true;
 }
@@ -731,7 +775,17 @@ TMH_private_get_orders_ID (const struct TMH_RequestHandler 
*rh,
           TALER_EC_GET_ORDERS_DB_FETCH_CONTRACT_TERMS_ERROR,
           "Merchant database error (contract terms corrupted)");
       }
-      // FIXME: sanity check on gorc->contract_amount.currency!
+      if (0 !=
+          strcasecmp (TMH_currency,
+                      gorc->contract_amount.currency))
+      {
+        GNUNET_break (0);
+        return TALER_MHD_reply_with_error (
+          connection,
+          MHD_HTTP_INTERNAL_SERVER_ERROR,
+          TALER_EC_GET_ORDERS_DB_FETCH_CONTRACT_TERMS_ERROR,
+          "Merchant database error (contract terms in wrong currency)");
+      }
     }
     if (GNUNET_OK !=
         TALER_JSON_hash (gorc->contract_terms,
@@ -896,6 +950,9 @@ TMH_private_get_orders_ID (const struct TMH_RequestHandler 
*rh,
     GNUNET_assert (GNUNET_OK ==
                    TALER_amount_get_zero (TMH_currency,
                                           &gorc->deposits_total));
+    GNUNET_assert (GNUNET_OK ==
+                   TALER_amount_get_zero (TMH_currency,
+                                          &gorc->deposit_fees_total));
     qs = TMH_db->lookup_transfer_details_by_order (TMH_db->cls,
                                                    gorc->order_serial,
                                                    &process_transfer_details,
@@ -926,11 +983,22 @@ TMH_private_get_orders_ID (const struct 
TMH_RequestHandler *rh,
                                            
TALER_EC_GET_ORDERS_CONTRACT_CONTENT_INVALID,
                                            "Inconsistent contract terms in 
DB");
       }
-      // FIXME: what about fees?
-      if (0 >= // FIXME: right cmp?
+      if (0 >
+          TALER_amount_subtract (&expect_total,
+                                 &expect_total,
+                                 &gorc->deposit_fees_total))
+      {
+        GNUNET_break (0);
+        return TALER_MHD_reply_with_error (connection,
+                                           MHD_HTTP_INTERNAL_SERVER_ERROR,
+                                           
TALER_EC_GET_ORDERS_CONTRACT_CONTENT_INVALID,
+                                           "Inconsistent contract terms in 
DB");
+      }
+      if (0 >=
           TALER_amount_cmp (&expect_total,
                             &gorc->deposits_total))
       {
+        /* expect_total <= gorc->deposits_total: good: we got paid */
         wired = true;
         qs = TMH_db->mark_order_wired (TMH_db->cls,
                                        gorc->order_serial);

-- 
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]