gnunet-svn
[Top][All Lists]
Advanced

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

[taler-merchant] 13/19: fix order serialization so test are passing


From: gnunet
Subject: [taler-merchant] 13/19: fix order serialization so test are passing
Date: Fri, 22 Dec 2023 17:25:12 +0100

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

grothoff pushed a commit to branch master
in repository merchant.

commit ebb6c68e941a96b19242f486aff06ca81952e908
Author: Christian Blättler <blatc2@bfh.ch>
AuthorDate: Mon Dec 18 09:11:41 2023 +0100

    fix order serialization so test are passing
---
 .../taler-merchant-httpd_private-post-orders.c     | 84 +++++++++++++---------
 1 file changed, 49 insertions(+), 35 deletions(-)

diff --git a/src/backend/taler-merchant-httpd_private-post-orders.c 
b/src/backend/taler-merchant-httpd_private-post-orders.c
index 008c378d..9d00b0b9 100644
--- a/src/backend/taler-merchant-httpd_private-post-orders.c
+++ b/src/backend/taler-merchant-httpd_private-post-orders.c
@@ -24,7 +24,9 @@
  * @author Marcello Stanisci
  */
 #include "platform.h"
+#include <gnunet/gnunet_common.h>
 #include <gnunet/gnunet_json_lib.h>
+#include <gnunet/gnunet_time_lib.h>
 #include <jansson.h>
 #include <string.h>
 #include <taler/taler_signatures.h>
@@ -280,6 +282,11 @@ struct OrderContext
      */
     struct GNUNET_TIME_Timestamp delivery_date;
 
+    /**
+     * Delivery location.
+     */
+    json_t *delivery_location;
+
     /**
      * Payment deadline.
      */
@@ -317,11 +324,6 @@ struct OrderContext
      */
     struct TALER_Amount max_fee;
 
-    /**
-     * Delivery location.
-     */
-    const json_t *delivery_location;
-
     /**
      * Specifies for how long the wallet should try to get an
      * automatic refund for the purchase.
@@ -1245,25 +1247,25 @@ get_exchange_keys (void *cls,
 static void
 serialize_order (struct OrderContext *oc)
 {
-  /* TODO: add public_reorder_url
-               fulfillment_message
-               fulfillment_message_i18n
-               nonce
-               extra (?)
-   */
-
   oc->serialize_order.contract = GNUNET_JSON_PACK (
     GNUNET_JSON_pack_string ("summary",
                               oc->patch_order.summary),
-    GNUNET_JSON_pack_object_steal ("summary_i18n",
-                                   oc->patch_order.summary_i18n),
-    GNUNET_JSON_pack_string ("public_reorder_url",
-                              oc->patch_order.public_reorder_url),
-    GNUNET_JSON_pack_string ("fulfillment_message",
-                              oc->patch_order.fulfillment_message),
-    GNUNET_JSON_pack_object_steal ("fulfillment_message_i18n",
-                                   oc->patch_order.fulfillment_message_i18n),
-    GNUNET_JSON_pack_object_steal ("products",
+    GNUNET_JSON_pack_allow_null (
+      GNUNET_JSON_pack_object_steal ("summary_i18n",
+                                    oc->patch_order.summary_i18n)),
+    GNUNET_JSON_pack_allow_null (
+      GNUNET_JSON_pack_string ("public_reorder_url",
+                                oc->patch_order.public_reorder_url)),
+    GNUNET_JSON_pack_allow_null (
+      GNUNET_JSON_pack_string ("fulfillment_message",
+                                oc->patch_order.fulfillment_message)),
+    GNUNET_JSON_pack_allow_null (
+      GNUNET_JSON_pack_object_steal ("fulfillment_message_i18n",
+                                    oc->patch_order.fulfillment_message_i18n)),
+    GNUNET_JSON_pack_allow_null (
+      GNUNET_JSON_pack_string ("fulfillment_url",
+                                oc->patch_order.fulfillment_url)),
+    GNUNET_JSON_pack_array_steal ("products",
                                    oc->merge_inventory.products),
     GNUNET_JSON_pack_data_auto ("h_wire",
                                 &oc->add_payment_details.wm->h_wire),
@@ -1271,22 +1273,18 @@ serialize_order (struct OrderContext *oc)
                               oc->add_payment_details.wm->wire_method),
     GNUNET_JSON_pack_string ("order_id",
                               oc->patch_order.order_id),
-    GNUNET_JSON_pack_allow_null (
-      GNUNET_JSON_pack_string ("fulfillment_url",
-                                oc->patch_order.fulfillment_url)),
     GNUNET_JSON_pack_timestamp ("timestamp",
                                 oc->patch_order.timestamp),
-    GNUNET_JSON_pack_timestamp ("refund_deadline",
-                                oc->patch_order.refund_deadline),
     GNUNET_JSON_pack_timestamp ("pay_deadline",
                                 oc->patch_order.pay_deadline),
     GNUNET_JSON_pack_timestamp ("wire_transfer_deadline",
                                 oc->patch_order.wire_deadline),
-    GNUNET_JSON_pack_time_rel ("auto_refund",
-                               oc->patch_order.auto_refund),
     GNUNET_JSON_pack_allow_null (
       GNUNET_JSON_pack_timestamp ("delivery_date",
                                   oc->patch_order.delivery_date)),
+    GNUNET_JSON_pack_allow_null (
+      GNUNET_JSON_pack_object_steal ("delivery_location",
+                                      oc->patch_order.delivery_location)),
     GNUNET_JSON_pack_string ("merchant_base_url",
                               oc->patch_order.merchant_base_url),
     GNUNET_JSON_pack_object_steal ("merchant",
@@ -1299,11 +1297,26 @@ serialize_order (struct OrderContext *oc)
                             &oc->set_max_fee.max_fee),
     TALER_JSON_pack_amount ("amount",
                             &oc->patch_order.brutto),
-    GNUNET_JSON_pack_string ("nonce",
-                              oc->patch_order.nonce),
-    GNUNET_JSON_pack_object_steal ("extra",
-                                   oc->patch_order.extra)
+    GNUNET_JSON_pack_allow_null (
+      GNUNET_JSON_pack_object_steal ("extra",
+                                    oc->patch_order.extra))
   );
+
+  /* Pack does not work here, because it doesn't set zero-values for 
timestamps */
+  GNUNET_assert (0 ==
+                 json_object_set_new (oc->serialize_order.contract,
+                                      "refund_deadline",
+                                      GNUNET_JSON_from_timestamp (
+                                        oc->patch_order.refund_deadline)));
+
+  if (!GNUNET_TIME_relative_is_zero(oc->patch_order.auto_refund)) {
+    GNUNET_assert (0 ==
+                   json_object_set_new (oc->serialize_order.contract,
+                                      "auto_refund",
+                                      GNUNET_JSON_from_time_rel (
+                                        oc->patch_order.auto_refund)));
+  }
+
   oc->phase++;
 }
 
@@ -1419,6 +1432,7 @@ patch_order (struct OrderContext *oc)
   oc->patch_order.merchant_base_url = NULL;
   oc->patch_order.timestamp = GNUNET_TIME_UNIT_ZERO_TS;
   oc->patch_order.refund_deadline = GNUNET_TIME_UNIT_FOREVER_TS;
+  oc->patch_order.auto_refund = GNUNET_TIME_UNIT_ZERO;
   oc->patch_order.pay_deadline = GNUNET_TIME_UNIT_ZERO_TS;
   oc->patch_order.wire_deadline = GNUNET_TIME_UNIT_FOREVER_TS;
   oc->patch_order.delivery_location = NULL;
@@ -1487,8 +1501,8 @@ patch_order (struct OrderContext *oc)
                               &oc->patch_order.max_fee),
       &no_fee),
     GNUNET_JSON_spec_mark_optional (
-      GNUNET_JSON_spec_object_const ("delivery_location",
-                                    &oc->patch_order.delivery_location),
+      GNUNET_JSON_spec_json ("delivery_location",
+                               &oc->patch_order.delivery_location),
       NULL),
     GNUNET_JSON_spec_mark_optional (
       GNUNET_JSON_spec_timestamp ("delivery_date",
@@ -1898,7 +1912,7 @@ merge_inventory (struct OrderContext *oc)
    */
   {
     oc->merge_inventory.products = json_object_get (oc->init.order,
-                                     "products");
+                                                "products");
     if (NULL == oc->merge_inventory.products)
     {
       oc->merge_inventory.products = json_array ();

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