gnunet-svn
[Top][All Lists]
Advanced

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

[taler-merchant] branch master updated: implement #6525, requires LASTES


From: gnunet
Subject: [taler-merchant] branch master updated: implement #6525, requires LASTEST GNUnet to work
Date: Sun, 25 Oct 2020 21:34:35 +0100

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

grothoff pushed a commit to branch master
in repository merchant.

The following commit(s) were added to refs/heads/master by this push:
     new 0e63f90  implement #6525, requires LASTEST GNUnet to work
0e63f90 is described below

commit 0e63f90cfb3fbc4271a3a82f988e61d8697c8cb6
Author: Christian Grothoff <christian@grothoff.org>
AuthorDate: Sun Oct 25 21:33:41 2020 +0100

    implement #6525, requires LASTEST GNUnet to work
---
 .../taler-merchant-httpd_private-post-orders.c     | 165 ++++++++++++++-------
 src/lib/merchant_api_post_order_claim.c            |   5 +
 src/testing/testing_api_cmd_post_orders.c          |  20 +--
 3 files changed, 121 insertions(+), 69 deletions(-)

diff --git a/src/backend/taler-merchant-httpd_private-post-orders.c 
b/src/backend/taler-merchant-httpd_private-post-orders.c
index 840cc07..312d71f 100644
--- a/src/backend/taler-merchant-httpd_private-post-orders.c
+++ b/src/backend/taler-merchant-httpd_private-post-orders.c
@@ -373,9 +373,12 @@ execute_order (struct MHD_Connection *connection,
                                      order,
                                      spec);
     if (GNUNET_OK != res)
+    {
+      GNUNET_break_op (0);
       return (GNUNET_NO == res)
              ? MHD_YES
              : MHD_NO;
+    }
   }
   if (0 !=
       strcasecmp (total.currency,
@@ -592,11 +595,69 @@ patch_order (struct MHD_Connection *connection,
 {
   const struct TALER_MERCHANTDB_InstanceSettings *settings =
     &hc->instance->settings;
-  const char *order_id;
+  const char *order_id = NULL;
+  const char *fulfillment_url = NULL;
+  const char *merchant_base_url = NULL;
+  json_t *jmerchant = NULL;
+  struct TALER_Amount max_wire_fee = { 0 };
+  struct TALER_Amount max_fee = { 0 };
+  uint32_t wire_fee_amortization = 0;
+  struct GNUNET_TIME_Absolute timestamp = { 0 };
+  struct GNUNET_TIME_Absolute refund_deadline
+    = GNUNET_TIME_UNIT_FOREVER_ABS;
+  struct GNUNET_TIME_Absolute pay_deadline = { 0 };
+  struct GNUNET_TIME_Absolute wire_deadline
+    = GNUNET_TIME_UNIT_FOREVER_ABS;
+  struct GNUNET_JSON_Specification spec[] = {
+    GNUNET_JSON_spec_mark_optional (
+      GNUNET_JSON_spec_string ("merchant_base_url",
+                               &merchant_base_url)),
+    GNUNET_JSON_spec_mark_optional (
+      GNUNET_JSON_spec_json ("merchant",
+                             &jmerchant)),
+    GNUNET_JSON_spec_mark_optional (
+      GNUNET_JSON_spec_string ("order_id",
+                               &order_id)),
+    GNUNET_JSON_spec_mark_optional (
+      GNUNET_JSON_spec_string ("fulfillment_url",
+                               &fulfillment_url)),
+    GNUNET_JSON_spec_mark_optional (
+      TALER_JSON_spec_absolute_time ("timestamp",
+                                     &timestamp)),
+    GNUNET_JSON_spec_mark_optional (
+      TALER_JSON_spec_absolute_time ("refund_deadline",
+                                     &refund_deadline)),
+    GNUNET_JSON_spec_mark_optional (
+      TALER_JSON_spec_absolute_time ("pay_deadline",
+                                     &pay_deadline)),
+    GNUNET_JSON_spec_mark_optional (
+      TALER_JSON_spec_absolute_time ("wire_transfer_deadline",
+                                     &wire_deadline)),
+    GNUNET_JSON_spec_mark_optional (
+      TALER_JSON_spec_amount ("max_fee",
+                              &max_fee)),
+    GNUNET_JSON_spec_mark_optional (
+      TALER_JSON_spec_amount ("max_wire_fee",
+                              &max_wire_fee)),
+    GNUNET_JSON_spec_mark_optional (
+      GNUNET_JSON_spec_uint32 ("wire_fee_amortization",
+                               &wire_fee_amortization)),
+    GNUNET_JSON_spec_end ()
+  };
+  enum GNUNET_GenericReturnValue ret;
+
+  ret = TALER_MHD_parse_json_data (connection,
+                                   order,
+                                   spec);
+  if (GNUNET_OK != ret)
+  {
+    GNUNET_break_op (0);
+    return (GNUNET_NO == ret)
+           ? MHD_YES
+           : MHD_NO;
+  }
 
   /* Add order_id if it doesn't exist. */
-  order_id = json_string_value (json_object_get (order,
-                                                 "order_id"));
   if (NULL == order_id)
   {
     char buf[256];
@@ -630,6 +691,9 @@ patch_order (struct MHD_Connection *connection,
                                           sizeof (buf) - off);
     *last = '\0';
     jbuf = json_string (buf);
+    GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+                "Assigning order ID `%s' server-side\n",
+                buf);
     GNUNET_break (0 ==
                   json_object_set_new (order,
                                        "order_id",
@@ -639,62 +703,54 @@ patch_order (struct MHD_Connection *connection,
   }
 
   /* Patch fulfillment URL with order_id (implements #6467). */
+  if (NULL != fulfillment_url)
   {
-    const char *fulfillment_url;
+    const char *pos;
 
-    fulfillment_url = json_string_value (json_object_get (order,
-                                                          "fulfillment_url"));
-    if (NULL != fulfillment_url)
+    pos = strstr (fulfillment_url,
+                  "${ORDER_ID}");
+    if (NULL != pos)
     {
-      const char *pos;
-
-      pos = strstr (fulfillment_url,
-                    "${ORDER_ID}");
-      if (NULL != pos)
-      {
-        /* replace ${ORDER_ID} with the real order_id */
-        char *nurl;
-
-        GNUNET_asprintf (&nurl,
-                         "%.*s%s%s",
-                         /* first output URL until ${ORDER_ID} */
-                         (int) (pos - fulfillment_url),
-                         fulfillment_url,
-                         /* replace ${ORDER_ID} with the right order_id */
-                         order_id,
-                         /* append rest of original URL */
-                         pos + strlen ("${ORDER_ID}"));
-        /* replace in JSON of the order */
-        GNUNET_break (0 ==
-                      json_object_set_new (order,
-                                           "fulfillment_url",
-                                           json_string (nurl)));
-        GNUNET_free (nurl);
-      }
+      /* replace ${ORDER_ID} with the real order_id */
+      char *nurl;
+
+      GNUNET_asprintf (&nurl,
+                       "%.*s%s%s",
+                       /* first output URL until ${ORDER_ID} */
+                       (int) (pos - fulfillment_url),
+                       fulfillment_url,
+                       /* replace ${ORDER_ID} with the right order_id */
+                       order_id,
+                       /* append rest of original URL */
+                       pos + strlen ("${ORDER_ID}"));
+      /* replace in JSON of the order */
+      GNUNET_break (0 ==
+                    json_object_set_new (order,
+                                         "fulfillment_url",
+                                         json_string (nurl)));
+      GNUNET_free (nurl);
     }
   }
 
   {
     struct GNUNET_TIME_Absolute now = GNUNET_TIME_absolute_get ();
+    
     (void) GNUNET_TIME_round_abs (&now);
-
-    /* Add timestamp if it doesn't exist */
-    if (NULL == json_object_get (order,
-                                 "timestamp"))
+    /* Add timestamp if it doesn't exist (or is zero) */
+    if (0 == timestamp.abs_value_us)
     {
       GNUNET_assert (0 ==
                      json_object_set_new (order,
                                           "timestamp",
                                           GNUNET_JSON_from_time_abs (now)));
     }
-    
+
     /* If no refund_deadline given, set one based on refund_delay.  */
-    if (NULL == json_object_get (order,
-                                 "refund_deadline"))
+    if (GNUNET_TIME_UNIT_FOREVER_ABS.abs_value_us == 
refund_deadline.abs_value_us)
     {
       struct GNUNET_TIME_Absolute rd =
         GNUNET_TIME_relative_to_absolute (refund_delay);
-      
+
       (void) GNUNET_TIME_round_abs (&rd);
       if (0 == refund_delay.rel_value_us)
         rd = now; /* if delay was 0, ensure that refund_deadline == timestamp 
*/
@@ -705,8 +761,7 @@ patch_order (struct MHD_Connection *connection,
     }
   }
 
-  if (NULL == json_object_get (order,
-                               "pay_deadline"))
+  if (0 == pay_deadline.abs_value_us)
   {
     struct GNUNET_TIME_Absolute t;
 
@@ -718,10 +773,10 @@ patch_order (struct MHD_Connection *connection,
                                         GNUNET_JSON_from_time_abs (t)));
   }
 
-  if (NULL == json_object_get (order,
-                               "wire_transfer_deadline"))
+  if (GNUNET_TIME_UNIT_FOREVER_ABS.abs_value_us == wire_deadline.abs_value_us)
   {
     struct GNUNET_TIME_Absolute t;
+
     t = GNUNET_TIME_relative_to_absolute (
       settings->default_wire_transfer_delay);
     (void) GNUNET_TIME_round_abs (&t);
@@ -731,8 +786,8 @@ patch_order (struct MHD_Connection *connection,
                                         GNUNET_JSON_from_time_abs (t)));
   }
 
-  if (NULL == json_object_get (order,
-                               "max_wire_fee"))
+  if (GNUNET_OK !=
+      TALER_amount_is_valid (&max_wire_fee))
   {
     GNUNET_assert (0 ==
                    json_object_set_new (order,
@@ -741,8 +796,8 @@ patch_order (struct MHD_Connection *connection,
                                           (&settings->default_max_wire_fee)));
   }
 
-  if (NULL == json_object_get (order,
-                               "max_fee"))
+  if (GNUNET_OK !=
+      TALER_amount_is_valid (&max_fee))
   {
     GNUNET_assert (0 ==
                    json_object_set_new (
@@ -752,8 +807,7 @@ patch_order (struct MHD_Connection *connection,
                        (&settings->default_max_deposit_fee)));
   }
 
-  if (NULL == json_object_get (order,
-                               "wire_fee_amortization"))
+  if (0 == wire_fee_amortization)
   {
     GNUNET_assert (0 ==
                    json_object_set_new (
@@ -763,8 +817,7 @@ patch_order (struct MHD_Connection *connection,
                        ((json_int_t) 
settings->default_wire_fee_amortization)));
   }
 
-  if (NULL == json_object_get (order,
-                               "merchant_base_url"))
+  if (NULL == merchant_base_url)
   {
     char *url;
 
@@ -777,10 +830,8 @@ patch_order (struct MHD_Connection *connection,
     GNUNET_free (url);
   }
 
-
   /* Fill in merchant information if necessary */
-  if (NULL != json_object_get (order,
-                               "merchant"))
+  if (NULL != jmerchant)
   {
     GNUNET_break_op (0);
     return TALER_MHD_reply_with_error (
@@ -791,8 +842,6 @@ patch_order (struct MHD_Connection *connection,
   }
   else
   {
-    json_t *jmerchant;
-
     jmerchant = json_object ();
     GNUNET_assert (NULL != jmerchant);
     GNUNET_assert (0 ==
@@ -975,6 +1024,8 @@ merge_inventory (struct MHD_Connection *connection,
   if (NULL == json_object_get (order,
                                "products"))
   {
+    json_dumpf (order, stderr, JSON_INDENT (2));
+    GNUNET_assert (NULL != order);
     GNUNET_assert (0 ==
                    json_object_set_new (order,
                                         "products",
diff --git a/src/lib/merchant_api_post_order_claim.c 
b/src/lib/merchant_api_post_order_claim.c
index f37e597..ab7d26b 100644
--- a/src/lib/merchant_api_post_order_claim.c
+++ b/src/lib/merchant_api_post_order_claim.c
@@ -177,6 +177,11 @@ TALER_MERCHANT_order_claim (struct GNUNET_CURL_Context 
*ctx,
   struct TALER_MERCHANT_OrderClaimHandle *och;
   json_t *req_obj;
 
+  if (NULL == order_id)
+  {
+    GNUNET_break (0);
+    return NULL;
+  }
   req_obj = json_pack ("{s:o}",
                        "nonce",
                        GNUNET_JSON_from_data_auto (nonce));
diff --git a/src/testing/testing_api_cmd_post_orders.c 
b/src/testing/testing_api_cmd_post_orders.c
index 7f0ef26..b9ea27e 100644
--- a/src/testing/testing_api_cmd_post_orders.c
+++ b/src/testing/testing_api_cmd_post_orders.c
@@ -317,7 +317,7 @@ order_cb (void *cls,
     break;
   case MHD_HTTP_CONFLICT:
     TALER_TESTING_interpreter_next (ps->is);
-    break;
+    return;
   default:
     {
       char *s = json_dumps (hr->reply,
@@ -338,7 +338,7 @@ order_cb (void *cls,
     return;
   }
 
-  if (false == ps->with_claim)
+  if (! ps->with_claim)
   {
     TALER_TESTING_interpreter_next (ps->is);
     return;
@@ -385,7 +385,7 @@ orders_run (void *cls,
   }
 
   if (NULL == json_object_get (order,
-                               "order_id"))
+                               "order_id")) 
   {
     struct GNUNET_TIME_Absolute now;
     char *order_id;
@@ -395,9 +395,10 @@ orders_run (void *cls,
     order_id = GNUNET_STRINGS_data_to_string_alloc
                  (&now.abs_value_us,
                  sizeof (now.abs_value_us));
-    json_object_set_new (order,
-                         "order_id",
-                         json_string (order_id));
+    GNUNET_assert (0 ==
+                   json_object_set_new (order,
+                                        "order_id",
+                                        json_string (order_id)));
     GNUNET_free (order_id);
   }
   GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_WEAK,
@@ -430,11 +431,9 @@ orders_run2 (void *cls,
   const char *order_str = ps->order;
   json_t *order;
   json_error_t error;
-
   char *products_string = GNUNET_strdup (ps->products);
   char *locks_string = GNUNET_strdup (ps->locks);
   char *token;
-
   struct TALER_MERCHANT_InventoryProduct *products = NULL;
   unsigned int products_length = 0;
   struct GNUNET_Uuid *locks = NULL;
@@ -596,8 +595,7 @@ orders_cleanup (void *cls,
   if (NULL != ps->och)
   {
     GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
-                "Command '%s' did not complete"
-                " (orders lookup)\n",
+                "Command '%s' did not complete (orders lookup)\n",
                 cmd->label);
     TALER_MERCHANT_order_claim_cancel (ps->och);
     ps->och = NULL;
@@ -646,7 +644,6 @@ make_order_json (const char *order_id,
 {
   struct GNUNET_TIME_Absolute refund = refund_deadline;
   struct GNUNET_TIME_Absolute pay = pay_deadline;
-
   json_t *contract_terms;
 
   GNUNET_TIME_round_abs (&refund);
@@ -667,7 +664,6 @@ make_order_json (const char *order_id,
     "item", "headphones",
     "item", "earbuds"
     );
-
   GNUNET_assert (GNUNET_OK ==
                  TALER_JSON_expand_path (contract_terms,
                                          "$.dummy_obj",

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