gnunet-svn
[Top][All Lists]
Advanced

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

[taler-merchant] branch master updated: move refund_delay to request bod


From: gnunet
Subject: [taler-merchant] branch master updated: move refund_delay to request body in POST /orders
Date: Sat, 25 Jul 2020 22:24:38 +0200

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

jonathan-buchanan pushed a commit to branch master
in repository merchant.

The following commit(s) were added to refs/heads/master by this push:
     new d78afeb  move refund_delay to request body in POST /orders
d78afeb is described below

commit d78afeb1a0d5c45dcd64e27ff8b7e9ca73bfce21
Author: Jonathan Buchanan <jonathan.russ.buchanan@gmail.com>
AuthorDate: Sat Jul 25 16:24:20 2020 -0400

    move refund_delay to request body in POST /orders
---
 .../taler-merchant-httpd_private-post-orders.c     | 53 +++++++++++++---------
 src/lib/merchant_api_post_orders.c                 | 12 +++--
 2 files changed, 39 insertions(+), 26 deletions(-)

diff --git a/src/backend/taler-merchant-httpd_private-post-orders.c 
b/src/backend/taler-merchant-httpd_private-post-orders.c
index 64dcce4..76126dd 100644
--- a/src/backend/taler-merchant-httpd_private-post-orders.c
+++ b/src/backend/taler-merchant-httpd_private-post-orders.c
@@ -540,6 +540,7 @@ static MHD_RESULT
 patch_order (struct MHD_Connection *connection,
              struct TMH_HandlerContext *hc,
              json_t *order,
+             struct GNUNET_TIME_Relative refund_delay,
              unsigned int inventory_products_length,
              const struct InventoryProduct inventory_products[],
              unsigned int uuids_length,
@@ -604,28 +605,8 @@ patch_order (struct MHD_Connection *connection,
   if (NULL == json_object_get (order,
                                "refund_deadline"))
   {
-    const char *refdel_s;
-    struct GNUNET_TIME_Absolute rd = { 0 };
-
-    refdel_s = MHD_lookup_connection_value (connection,
-                                            MHD_GET_ARGUMENT_KIND,
-                                            "refund_delay");
-    if (NULL != refdel_s)
-    {
-      struct GNUNET_TIME_Relative r;
-
-      if (GNUNET_OK !=
-          GNUNET_STRINGS_fancy_time_to_relative (refdel_s,
-                                                 &r))
-      {
-        return TALER_MHD_reply_with_error (connection,
-                                           MHD_HTTP_BAD_REQUEST,
-                                           TALER_EC_PARAMETER_MALFORMED,
-                                           "refund_delay");
-
-      }
-      rd = GNUNET_TIME_relative_to_absolute (r);
-    }
+    struct GNUNET_TIME_Absolute rd =
+      GNUNET_TIME_relative_to_absolute (refund_delay);
     GNUNET_assert (0 ==
                    json_object_set_new (order,
                                         "refund_deadline",
@@ -831,6 +812,7 @@ static MHD_RESULT
 add_payment_details (struct MHD_Connection *connection,
                      struct TMH_HandlerContext *hc,
                      json_t *order,
+                     struct GNUNET_TIME_Relative refund_delay,
                      const char *payment_target,
                      unsigned int inventory_products_length,
                      const struct InventoryProduct inventory_products[],
@@ -874,6 +856,7 @@ add_payment_details (struct MHD_Connection *connection,
   return patch_order (connection,
                       hc,
                       order,
+                      refund_delay,
                       inventory_products_length,
                       inventory_products,
                       uuids_length,
@@ -899,6 +882,7 @@ static MHD_RESULT
 merge_inventory (struct MHD_Connection *connection,
                  struct TMH_HandlerContext *hc,
                  json_t *order,
+                 struct GNUNET_TIME_Relative refund_delay,
                  const char *payment_target,
                  unsigned int inventory_products_length,
                  const struct InventoryProduct inventory_products[],
@@ -995,6 +979,7 @@ merge_inventory (struct MHD_Connection *connection,
   return add_payment_details (connection,
                               hc,
                               order,
+                              refund_delay,
                               payment_target,
                               inventory_products_length,
                               inventory_products,
@@ -1019,6 +1004,7 @@ TMH_private_post_orders (const struct TMH_RequestHandler 
*rh,
                          struct TMH_HandlerContext *hc)
 {
   json_t *order;
+  struct GNUNET_TIME_Relative refund_delay;
   const char *payment_target = NULL;
   unsigned int ips_len = 0;
   struct InventoryProduct *ips = NULL;
@@ -1035,7 +1021,29 @@ TMH_private_post_orders (const struct TMH_RequestHandler 
*rh,
                                        TALER_EC_PARAMETER_MISSING,
                                        "order");
   }
+  /* parse the refund_delay (optionally given) */
+  if (NULL != json_object_get (hc->request_body,
+                               "refund_delay"))
+  {
+    enum GNUNET_GenericReturnValue res;
+    struct GNUNET_JSON_Specification spec[] = {
+      TALER_JSON_spec_relative_time ("refund_delay",
+                                     &refund_delay),
+      GNUNET_JSON_spec_end ()
+    };
 
+    res = TALER_MHD_parse_json_data (connection,
+                                     hc->request_body,
+                                     spec);
+    if (GNUNET_OK != res)
+      return (GNUNET_NO == res)
+             ? MHD_YES
+             : MHD_NO;
+  }
+  else
+  {
+    refund_delay.rel_value_us = 0;
+  }
   /* parse the payment_target (optionally given) */
   {
     const json_t *pt;
@@ -1171,6 +1179,7 @@ TMH_private_post_orders (const struct TMH_RequestHandler 
*rh,
     res = merge_inventory (connection,
                            hc,
                            order,
+                           refund_delay,
                            payment_target,
                            ips_len,
                            ips,
diff --git a/src/lib/merchant_api_post_orders.c 
b/src/lib/merchant_api_post_orders.c
index f4cc529..f1617aa 100644
--- a/src/lib/merchant_api_post_orders.c
+++ b/src/lib/merchant_api_post_orders.c
@@ -251,14 +251,18 @@ TALER_MERCHANT_orders_post2 (
   po->cb_cls = cb_cls;
   po->url = TALER_url_join (backend_url,
                             "private/orders",
-                            "refund_delay",
-                            (0 != refund_delay.rel_value_us)
-                            ? delay_s
-                            : NULL,
                             NULL);
   req = json_pack ("{s:O}",
                    "order", (json_t *) order);
   GNUNET_assert (NULL != req);
+  if (0 != refund_delay.rel_value_us)
+  {
+    GNUNET_assert (0 ==
+                   json_object_set_new (req,
+                                        "refund_delay",
+                                        GNUNET_JSON_from_time_rel (
+                                          refund_delay)));
+  }
   if (NULL != payment_target)
   {
     GNUNET_assert (0 ==

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