gnunet-svn
[Top][All Lists]
Advanced

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

[taler-merchant] branch master updated (26e4d3e2 -> 118e0257)


From: gnunet
Subject: [taler-merchant] branch master updated (26e4d3e2 -> 118e0257)
Date: Wed, 11 May 2022 20:51:22 +0200

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

sebasjm pushed a change to branch master
in repository merchant.

    from 26e4d3e2 min age and auth fix
     new 4b77ed9f fix: should calculate contract hash when was not send as req 
param
     new 3670a062 fix: order is "refund_pending" if any of the refund is pending
     new 118e0257 feat: calculate and return how much refund has been taken 
already

The 3 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:
 src/backend/taler-merchant-httpd_get-orders-ID.c   | 108 ++++++++++++++-------
 .../taler-merchant-httpd_private-get-orders-ID.c   |   4 +-
 2 files changed, 76 insertions(+), 36 deletions(-)

diff --git a/src/backend/taler-merchant-httpd_get-orders-ID.c 
b/src/backend/taler-merchant-httpd_get-orders-ID.c
index c563f7c2..76dfefd5 100644
--- a/src/backend/taler-merchant-httpd_get-orders-ID.c
+++ b/src/backend/taler-merchant-httpd_get-orders-ID.c
@@ -124,6 +124,12 @@ struct GetOrderData
    */
   struct TALER_Amount refund_amount;
 
+  /**
+   * Total refunds already collected.
+   * if @e refunded is set to true.
+   */
+  struct TALER_Amount refund_taken;
+
   /**
    * Return code: #TALER_EC_NONE if successful.
    */
@@ -154,8 +160,9 @@ struct GetOrderData
   /**
    * Set to true if a refund is still available for the
    * wallet for this payment.
+   * @deprecated: true if refund_taken < refund_amount
    */
-  bool refund_available;
+  bool refund_pending;
 
   /**
    * Set to true if the client requested HTML, otherwise we generate JSON.
@@ -756,16 +763,18 @@ process_refunds_cb (void *cls,
               TALER_amount2s (refund_amount),
               TALER_B2S (coin_pub),
               reason);
-  god->refund_available |= pending;
-  if (god->refunded)
-  {
+  god->refund_pending |= pending;
+  if (!pending) 
+  {      
     GNUNET_assert (0 <=
-                   TALER_amount_add (&god->refund_amount,
-                                     &god->refund_amount,
-                                     refund_amount));
-    return;
+                  TALER_amount_add (&god->refund_taken,
+                                    &god->refund_taken,
+                                    refund_amount));
   }
-  god->refund_amount = *refund_amount;
+  GNUNET_assert (0 <=
+                  TALER_amount_add (&god->refund_amount,
+                                    &god->refund_amount,
+                                    refund_amount));
   god->refunded = true;
 }
 
@@ -1052,33 +1061,53 @@ TMH_get_orders_ID (const struct TMH_RequestHandler *rh,
   /* Check if client provided the right hash code of the contract terms */
   if (NULL != god->contract_terms)
   {
-    struct TALER_PrivateContractHashP h;
-
     contract_available = true;
-    if (GNUNET_OK !=
-        TALER_JSON_contract_hash (god->contract_terms,
-                                  &h))
+
+    if (GNUNET_YES == GNUNET_is_zero (&god->h_contract_terms)) 
     {
-      GNUNET_break (0);
-      return TALER_MHD_reply_with_error (connection,
-                                         MHD_HTTP_INTERNAL_SERVER_ERROR,
-                                         
TALER_EC_GENERIC_FAILED_COMPUTE_JSON_HASH,
-                                         "contract terms");
+
+      if (GNUNET_OK !=
+          TALER_JSON_contract_hash (god->contract_terms,
+                                    &god->h_contract_terms))
+      {
+        GNUNET_break (0);
+        return TALER_MHD_reply_with_error (connection,
+                                          MHD_HTTP_INTERNAL_SERVER_ERROR,
+                                          
TALER_EC_GENERIC_FAILED_COMPUTE_JSON_HASH,
+                                          "contract terms");
+      }
+
     }
-    contract_match = (0 ==
-                      GNUNET_memcmp (&h,
-                                     &god->h_contract_terms));
-    if ( (GNUNET_NO ==
-          GNUNET_is_zero (&god->h_contract_terms)) &&
-         (! contract_match) )
+    else
     {
-      GNUNET_break_op (0);
-      return TALER_MHD_reply_with_error (
-        connection,
-        MHD_HTTP_FORBIDDEN,
-        TALER_EC_MERCHANT_GENERIC_CONTRACT_HASH_DOES_NOT_MATCH_ORDER,
-        NULL);
+
+      struct TALER_PrivateContractHashP h;
+
+      if (GNUNET_OK !=
+          TALER_JSON_contract_hash (god->contract_terms,
+                                    &h))
+      {
+        GNUNET_break (0);
+        return TALER_MHD_reply_with_error (connection,
+                                          MHD_HTTP_INTERNAL_SERVER_ERROR,
+                                          
TALER_EC_GENERIC_FAILED_COMPUTE_JSON_HASH,
+                                          "contract terms");
+      }
+      contract_match = (0 ==
+                        GNUNET_memcmp (&h,
+                                      &god->h_contract_terms));
+      if ( !contract_match ) 
+      {
+        GNUNET_break_op (0);
+        return TALER_MHD_reply_with_error (
+          connection,
+          MHD_HTTP_FORBIDDEN,
+          TALER_EC_MERCHANT_GENERIC_CONTRACT_HASH_DOES_NOT_MATCH_ORDER,
+          NULL);
+      }
+      
     }
+
   }
 
   if (contract_available)
@@ -1341,6 +1370,9 @@ TMH_get_orders_ID (const struct TMH_RequestHandler *rh,
   GNUNET_assert (GNUNET_OK ==
                  TALER_amount_set_zero (TMH_currency,
                                         &god->refund_amount));
+  GNUNET_assert (GNUNET_OK ==
+                 TALER_amount_set_zero (TMH_currency,
+                                        &god->refund_taken));
   qs = TMH_db->lookup_refunds_detailed (TMH_db->cls,
                                         hc->instance->settings.id,
                                         &god->h_contract_terms,
@@ -1360,7 +1392,7 @@ TMH_get_orders_ID (const struct TMH_RequestHandler *rh,
           (1 != TALER_amount_cmp (&god->refund_amount,
                                   &god->sc.refund_expected)) )) ||
        ( (god->sc.awaiting_refund_obtained) &&
-         (god->refund_available) ) )
+         (god->refund_pending) ) )
   {
     /* Client is waiting for a refund larger than what we have, suspend
        until timeout */
@@ -1387,7 +1419,7 @@ TMH_get_orders_ID (const struct TMH_RequestHandler *rh,
   {
     enum GNUNET_GenericReturnValue res;
 
-    if (god->refund_available)
+    if (god->refund_pending)
     {
       char *qr;
       char *uri;
@@ -1421,6 +1453,8 @@ TMH_get_orders_ID (const struct TMH_RequestHandler *rh,
                                    get_order_summary (god)),
           TALER_JSON_pack_amount ("refund_amount",
                                   &god->refund_amount),
+          TALER_JSON_pack_amount ("refund_taken",
+                                  &god->refund_taken),
           GNUNET_JSON_pack_string ("taler_refund_uri",
                                    uri),
           GNUNET_JSON_pack_string ("taler_refund_qrcode_svg",
@@ -1446,7 +1480,9 @@ TMH_get_orders_ID (const struct TMH_RequestHandler *rh,
         GNUNET_JSON_pack_string ("order_summary",
                                  get_order_summary (god)),
         TALER_JSON_pack_amount ("refund_amount",
-                                &god->refund_amount));
+                                &god->refund_amount),
+        TALER_JSON_pack_amount ("refund_taken",
+                                &god->refund_taken));
       res = TMH_return_from_template (god->sc.con,
                                       MHD_HTTP_OK,
                                       "show_order_details",
@@ -1471,7 +1507,9 @@ TMH_get_orders_ID (const struct TMH_RequestHandler *rh,
     GNUNET_JSON_pack_bool ("refunded",
                            god->refunded),
     GNUNET_JSON_pack_bool ("refund_pending",
-                           god->refund_available),
+                           god->refund_pending),
+    TALER_JSON_pack_amount ("refund_taken",
+                           &god->refund_taken),
     TALER_JSON_pack_amount ("refund_amount",
                             &god->refund_amount));
 }
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 58c05604..828d1d65 100644
--- a/src/backend/taler-merchant-httpd_private-get-orders-ID.c
+++ b/src/backend/taler-merchant-httpd_private-get-orders-ID.c
@@ -776,6 +776,8 @@ process_refunds_cb (void *cls,
                    GNUNET_JSON_PACK (
                      TALER_JSON_pack_amount ("amount",
                                              refund_amount),
+                     GNUNET_JSON_pack_bool ("pending",
+                                            pending),
                      GNUNET_JSON_pack_timestamp ("timestamp",
                                                  timestamp),
                      GNUNET_JSON_pack_string ("reason",
@@ -801,7 +803,7 @@ process_refunds_cb (void *cls,
                                    &gorc->refund_amount,
                                    refund_amount));
   gorc->refunded = true;
-  gorc->refund_pending = pending;
+  gorc->refund_pending |= pending;
 }
 
 

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