gnunet-svn
[Top][All Lists]
Advanced

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

[taler-merchant] branch master updated (01939fd2 -> 3f633005)


From: gnunet
Subject: [taler-merchant] branch master updated (01939fd2 -> 3f633005)
Date: Tue, 22 Nov 2022 14:14:57 +0100

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

priscilla-huang pushed a change to branch master
in repository merchant.

    from 01939fd2 Merge branch 'master' of git+ssh://git.taler.net/merchant
     new ae6d2de1 update
     new c00762ce template post, get, patch and delete
     new 3f633005 update

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/Makefile.am                            |  10 ++
 src/backend/taler-merchant-httpd.c                 |  46 ++++++++
 src/backend/taler-merchant-httpd_helper.c          |  44 +++++++-
 src/backend/taler-merchant-httpd_helper.h          |  12 +++
 ...taler-merchant-httpd_private-get-templates-ID.c |   3 +-
 .../taler-merchant-httpd_private-get-templates.c   |   3 +-
 .../taler-merchant-httpd_private-post-templates.c  |   6 +-
 src/include/taler_merchantdb_lib.h                 |   9 ++
 src/include/taler_merchantdb_plugin.h              |   6 +-
 ...get_products.c => merchant_api_get_templates.c} | 106 +++++++++---------
 ...st_products.c => merchant_api_post_templates.c} | 119 +++++++++------------
 11 files changed, 233 insertions(+), 131 deletions(-)
 copy src/lib/{merchant_api_get_products.c => merchant_api_get_templates.c} 
(67%)
 copy src/lib/{merchant_api_post_products.c => merchant_api_post_templates.c} 
(63%)

diff --git a/src/backend/Makefile.am b/src/backend/Makefile.am
index 2bd25251..a24e80ad 100644
--- a/src/backend/Makefile.am
+++ b/src/backend/Makefile.am
@@ -34,6 +34,8 @@ taler_merchant_httpd_SOURCES = \
   taler-merchant-httpd_private-get-tips-ID.c \
     taler-merchant-httpd_private-get-tips-ID.h \
   taler-merchant-httpd_mhd.c taler-merchant-httpd_mhd.h \
+  taler-merchant-httpd_private-delete-templates-ID.c \
+    taler-merchant-httpd_private-delete-templates-ID.h \
   taler-merchant-httpd_private-delete-instances-ID.c \
     taler-merchant-httpd_private-delete-instances-ID.h \
   taler-merchant-httpd_private-delete-products-ID.c \
@@ -64,12 +66,20 @@ taler_merchant_httpd_SOURCES = \
     taler-merchant-httpd_private-get-reserves-ID.h \
   taler-merchant-httpd_private-get-transfers.c \
     taler-merchant-httpd_private-get-transfers.h \
+  taler-merchant-httpd_private-get-templates.c \
+    taler-merchant-httpd_private-get-templates.h \
+  taler-merchant-httpd_private-get-templates-ID.c \
+    taler-merchant-httpd_private-get-templates-ID.h \
+  taler-merchant-httpd_private-patch-templates-ID.c \
+    taler-merchant-httpd_private-patch-templates-ID.h \
   taler-merchant-httpd_private-patch-instances-ID.c \
     taler-merchant-httpd_private-patch-instances-ID.h \
   taler-merchant-httpd_private-patch-orders-ID-forget.c \
     taler-merchant-httpd_private-patch-orders-ID-forget.h \
   taler-merchant-httpd_private-patch-products-ID.c \
     taler-merchant-httpd_private-patch-products-ID.h \
+  taler-merchant-httpd_private-post-templates.c \
+    taler-merchant-httpd_private-post-templates.h \
   taler-merchant-httpd_private-post-instances.c \
     taler-merchant-httpd_private-post-instances.h \
   taler-merchant-httpd_private-post-instances-ID-auth.c \
diff --git a/src/backend/taler-merchant-httpd.c 
b/src/backend/taler-merchant-httpd.c
index 67359ece..631f4e1a 100644
--- a/src/backend/taler-merchant-httpd.c
+++ b/src/backend/taler-merchant-httpd.c
@@ -1056,6 +1056,52 @@ url_handler (void *cls,
       .method = MHD_HTTP_METHOD_OPTIONS,
       .handler = &handle_server_options
     },
+    /* GET /templates: */
+    {
+      .url_prefix = "/templates/",
+      .method = MHD_HTTP_METHOD_GET,
+      .handler = &TMH_private_get_templates
+    },
+    /* POST /templates: */
+    {
+      .url_prefix = "/templates/",
+      .method = MHD_HTTP_METHOD_POST,
+      .handler = &TMH_private_post_templates,
+      /* allow template data of up to 8 MB, that should be plenty;
+         note that exceeding #GNUNET_MAX_MALLOC_CHECKED (40 MB)
+         would require further changes to the allocation logic
+         in the code... */
+      .max_upload = 1024 * 1024 * 8
+    },
+    /* GET /templates/$ID/: */
+    {
+      .url_prefix = "/templates/",
+      .method = MHD_HTTP_METHOD_GET,
+      .have_id_segment = true,
+      .allow_deleted_instance = true,
+      .handler = &TMH_private_get_templates_ID
+    },
+    /* DELETE /templates/$ID/: */
+    {
+      .url_prefix = "/templates/",
+      .method = MHD_HTTP_METHOD_DELETE,
+      .have_id_segment = true,
+      .allow_deleted_instance = true,
+      .handler = &TMH_private_delete_templates_ID
+    },
+    /* PATCH /templates/$ID/: */
+    {
+      .url_prefix = "/templates/",
+      .method = MHD_HTTP_METHOD_PATCH,
+      .have_id_segment = true,
+      .allow_deleted_instance = true,
+      .handler = &TMH_private_patch_templates_ID,
+      /* allow template data of up to 8 MB, that should be plenty;
+         note that exceeding #GNUNET_MAX_MALLOC_CHECKED (40 MB)
+         would require further changes to the allocation logic
+         in the code... */
+      .max_upload = 1024 * 1024 * 8
+    },
     {
       .url_prefix = NULL
     }
diff --git a/src/backend/taler-merchant-httpd_helper.c 
b/src/backend/taler-merchant-httpd_helper.c
index 595b82cf..a5de1781 100644
--- a/src/backend/taler-merchant-httpd_helper.c
+++ b/src/backend/taler-merchant-httpd_helper.c
@@ -88,7 +88,6 @@ TMH_payto_uri_array_valid (const json_t *payto_uris)
   return payto_ok;
 }
 
-
 bool
 TMH_location_object_valid (const json_t *location)
 {
@@ -316,6 +315,49 @@ TMH_image_data_url_valid (const char *image_data_url)
   return true;
 }
 
+bool
+TMH_template_contract_valid (const json_t *template_contract)
+{
+  const char *summary;
+  struct TALER_Amount amount = { .value = 0};
+  uint32_t minimum_age = 0;
+  struct GNUNET_TIME_Relative pay_duration= { 0 };
+  struct GNUNET_JSON_Specification spec[] = {
+    GNUNET_JSON_spec_mark_optional (
+      GNUNET_JSON_spec_string ("summary",
+                               &summary),
+      NULL),
+    GNUNET_JSON_spec_mark_optional (
+      TALER_JSON_spec_amount ("amount",
+                              TMH_currency,
+                              &amount),
+      NULL),
+    GNUNET_JSON_spec_mark_optional (
+      GNUNET_JSON_spec_uint32 ("minimum_age",
+                               &minimum_age),
+      NULL),
+    GNUNET_JSON_spec_mark_optional (
+      GNUNET_JSON_spec_relative_time ("pay_duration",
+                                     &pay_duration),
+      NULL),
+    GNUNET_JSON_spec_end ()
+  };
+  const char *ename;
+  unsigned int eline;
+
+  if (GNUNET_OK !=
+      GNUNET_JSON_parse (template_contract,
+                         spec,
+                         &ename,
+                         &eline))
+  {
+    GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+                "Invalid template_contract for field %s\n",
+                ename);
+    return false;
+  }
+  return true;
+}
 
 bool
 TMH_taxes_array_valid (const json_t *taxes)
diff --git a/src/backend/taler-merchant-httpd_helper.h 
b/src/backend/taler-merchant-httpd_helper.h
index 659bddc2..dae9caaf 100644
--- a/src/backend/taler-merchant-httpd_helper.h
+++ b/src/backend/taler-merchant-httpd_helper.h
@@ -87,6 +87,18 @@ bool
 TMH_image_data_url_valid (const char *image_data_url);
 
 
+/**
+ * Check if @a template_contract is a valid template_contract  object in the 
sense of Taler's API
+ * definition.
+ *
+ * @param template_contract object to check
+ * @return true if @a template_location is an object
+ *         representing a template_location.
+ */
+bool
+TMH_template_contract_valid (const json_t *template_contract);
+
+
 /**
  * Setup new wire method for the given @ payto_uri.
  *
diff --git a/src/backend/taler-merchant-httpd_private-get-templates-ID.c 
b/src/backend/taler-merchant-httpd_private-get-templates-ID.c
index 80fccd40..c9f64ae5 100644
--- a/src/backend/taler-merchant-httpd_private-get-templates-ID.c
+++ b/src/backend/taler-merchant-httpd_private-get-templates-ID.c
@@ -71,9 +71,10 @@ TMH_private_get_templates_ID (const struct 
TMH_RequestHandler *rh,
       GNUNET_JSON_pack_string ("image",
                                tp.image),
       GNUNET_JSON_pack_object_steal ("template_contract",
-                                     tp.template_contract),
+                                     tp.template_contract));
     GNUNET_free (tp.template_description);
     GNUNET_free (tp.image);
+
     return ret;
   }
 }
diff --git a/src/backend/taler-merchant-httpd_private-get-templates.c 
b/src/backend/taler-merchant-httpd_private-get-templates.c
index 20cd0cdc..fe5d729f 100644
--- a/src/backend/taler-merchant-httpd_private-get-templates.c
+++ b/src/backend/taler-merchant-httpd_private-get-templates.c
@@ -30,7 +30,8 @@
  */
 static void
 add_template (void *cls,
-             const char *template_id)
+              const char *template_id,
+              const char *template_description)
 {
   json_t *pa = cls;
 
diff --git a/src/backend/taler-merchant-httpd_private-post-templates.c 
b/src/backend/taler-merchant-httpd_private-post-templates.c
index 1e6206bb..a2112486 100644
--- a/src/backend/taler-merchant-httpd_private-post-templates.c
+++ b/src/backend/taler-merchant-httpd_private-post-templates.c
@@ -46,11 +46,11 @@ templates_equal (const struct 
TALER_MERCHANTDB_TemplateDetails *t1,
                 const struct TALER_MERCHANTDB_TemplateDetails *t2)
 {
   return ( (0 == strcmp (t1->template_description,
-                         t2->tempate_description)) &&
+                         t2->template_description)) &&
            (0 == strcmp (t1->image,
                          t2->image)) &&
-           (1 == json_equal (p1->template_contract,
-                             p2->template_contract));
+           (1 == json_equal (t1->template_contract,
+                             t2->template_contract)));
 }
 
 
diff --git a/src/include/taler_merchantdb_lib.h 
b/src/include/taler_merchantdb_lib.h
index 9cce9aac..8d84db79 100644
--- a/src/include/taler_merchantdb_lib.h
+++ b/src/include/taler_merchantdb_lib.h
@@ -59,6 +59,15 @@ TALER_MERCHANTDB_product_details_free (
   struct TALER_MERCHANTDB_ProductDetails *pd);
 
 
+/**
+ * Free members of @a tp, but not @a tp itself.
+ *
+ * @param[in] tp template details to clean up
+ */
+void
+TALER_MERCHANTDB_template_details_free (
+  struct TALER_MERCHANTDB_TemplateDetails *tp);
+
 #endif  /* MERCHANT_DB_H */
 
 /* end of taler_merchantdb_lib.h */
diff --git a/src/include/taler_merchantdb_plugin.h 
b/src/include/taler_merchantdb_plugin.h
index 51c5ec02..bfc2d51a 100644
--- a/src/include/taler_merchantdb_plugin.h
+++ b/src/include/taler_merchantdb_plugin.h
@@ -321,17 +321,17 @@ struct TALER_MERCHANTDB_TemplateDetails
   /**
    * Description of the template.
    */
-  const char *template_description;
+  char *template_description;
 
   /**
    * Base64-encoded product image, or NULL.
    */
-  const char *image;
+  char *image;
 
   /**
    * In this template contract, we can have additional information.
    */
-  const json_t *template_contract;
+  json_t *template_contract;
 };
 
 
diff --git a/src/lib/merchant_api_get_products.c 
b/src/lib/merchant_api_get_templates.c
similarity index 67%
copy from src/lib/merchant_api_get_products.c
copy to src/lib/merchant_api_get_templates.c
index c3cc30e7..7082ee23 100644
--- a/src/lib/merchant_api_get_products.c
+++ b/src/lib/merchant_api_get_templates.c
@@ -15,8 +15,8 @@
   <http://www.gnu.org/licenses/>
 */
 /**
- * @file merchant_api_get_products.c
- * @brief Implementation of the GET /products request of the merchant's HTTP 
API
+ * @file merchant_api_get_templates.c
+ * @brief Implementation of the GET /templates request of the merchant's HTTP 
API
  * @author Christian Grothoff
  */
 #include "platform.h"
@@ -34,7 +34,7 @@
 /**
  * Handle for a GET /products operation.
  */
-struct TALER_MERCHANT_ProductsGetHandle
+struct TALER_MERCHANT_TemplatesGetHandle
 {
   /**
    * The url for this request.
@@ -49,7 +49,7 @@ struct TALER_MERCHANT_ProductsGetHandle
   /**
    * Function to call with the result.
    */
-  TALER_MERCHANT_ProductsGetCallback cb;
+  TALER_MERCHANT_TemplatesGetCallback cb;
 
   /**
    * Closure for @a cb.
@@ -65,28 +65,28 @@ struct TALER_MERCHANT_ProductsGetHandle
 
 
 /**
- * Parse product information from @a ia.
+ * Parse template information from @a ia.
  *
- * @param ia JSON array (or NULL!) with product data
+ * @param ia JSON array (or NULL!) with template data
  * @param pgh operation handle
  * @return #GNUNET_OK on success
  */
 static int
-parse_products (const json_t *ia,
-                struct TALER_MERCHANT_ProductsGetHandle *pgh)
+parse_templates (const json_t *ia,
+                struct TALER_MERCHANT_TemplatesGetHandle *tgh)
 {
   unsigned int ies_len = json_array_size (ia);
-  struct TALER_MERCHANT_InventoryEntry ies[ies_len];
+  struct TALER_MERCHANT_TemplateEntry ies[ies_len];
   size_t index;
   json_t *value;
   int ret;
 
   ret = GNUNET_OK;
   json_array_foreach (ia, index, value) {
-    struct TALER_MERCHANT_InventoryEntry *ie = &ies[index];
+    struct TALER_MERCHANT_TemplateEntry *ie = &ies[index];
     struct GNUNET_JSON_Specification spec[] = {
-      GNUNET_JSON_spec_string ("product_id",
-                               &ie->product_id),
+      GNUNET_JSON_spec_string ("template_id",
+                               &ie->template_id),
       GNUNET_JSON_spec_end ()
     };
 
@@ -108,11 +108,11 @@ parse_products (const json_t *ia,
       .http_status = MHD_HTTP_OK
     };
 
-    pgh->cb (pgh->cb_cls,
+    tgh->cb (tgh->cb_cls,
              &hr,
              ies_len,
              ies);
-    pgh->cb = NULL; /* just to be sure */
+    tgh->cb = NULL; /* just to be sure */
   }
   return ret;
 }
@@ -120,36 +120,36 @@ parse_products (const json_t *ia,
 
 /**
  * Function called when we're done processing the
- * HTTP /products request.
+ * HTTP /templates request.
  *
- * @param cls the `struct TALER_MERCHANT_ProductsGetHandle`
+ * @param cls the `struct TALER_MERCHANT_TemplatesGetHandle`
  * @param response_code HTTP response code, 0 on error
  * @param response response body, NULL if not in JSON
  */
 static void
-handle_get_products_finished (void *cls,
+handle_get_templates_finished (void *cls,
                               long response_code,
                               const void *response)
 {
-  struct TALER_MERCHANT_ProductsGetHandle *pgh = cls;
+  struct TALER_MERCHANT_TemplatesGetHandle *tgh = cls;
   const json_t *json = response;
   struct TALER_MERCHANT_HttpResponse hr = {
     .http_status = (unsigned int) response_code,
     .reply = json
   };
 
-  pgh->job = NULL;
+  tgh->job = NULL;
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-              "Got /products response with status code %u\n",
+              "Got /templates response with status code %u\n",
               (unsigned int) response_code);
   switch (response_code)
   {
   case MHD_HTTP_OK:
     {
-      json_t *products;
+      json_t *templates;
       struct GNUNET_JSON_Specification spec[] = {
-        GNUNET_JSON_spec_json ("products",
-                               &products),
+        GNUNET_JSON_spec_json ("templates",
+                               &templates),
         GNUNET_JSON_spec_end ()
       };
 
@@ -163,13 +163,13 @@ handle_get_products_finished (void *cls,
       }
       else
       {
-        if ( (! json_is_array (products)) ||
+        if ( (! json_is_array (templates)) ||
              (GNUNET_OK ==
-              parse_products (products,
-                              pgh)) )
+              parse_templates (templates,
+                              tgh)) )
         {
           GNUNET_JSON_parse_free (spec);
-          TALER_MERCHANT_products_get_cancel (pgh);
+          TALER_MERCHANT_templates_get_cancel (tgh);
           return;
         }
         else
@@ -196,56 +196,56 @@ handle_get_products_finished (void *cls,
                 (int) hr.ec);
     break;
   }
-  pgh->cb (pgh->cb_cls,
+  tgh->cb (tgh->cb_cls,
            &hr,
            0,
            NULL);
-  TALER_MERCHANT_products_get_cancel (pgh);
+  TALER_MERCHANT_templates_get_cancel (tgh);
 }
 
 
-struct TALER_MERCHANT_ProductsGetHandle *
-TALER_MERCHANT_products_get (
+struct TALER_MERCHANT_TemplatesGetHandle *
+TALER_MERCHANT_templates_get (
   struct GNUNET_CURL_Context *ctx,
   const char *backend_url,
-  TALER_MERCHANT_ProductsGetCallback cb,
+  TALER_MERCHANT_TemplatesGetCallback cb,
   void *cb_cls)
 {
-  struct TALER_MERCHANT_ProductsGetHandle *pgh;
+  struct TALER_MERCHANT_TemplatesGetHandle *tgh;
   CURL *eh;
 
-  pgh = GNUNET_new (struct TALER_MERCHANT_ProductsGetHandle);
-  pgh->ctx = ctx;
-  pgh->cb = cb;
-  pgh->cb_cls = cb_cls;
-  pgh->url = TALER_url_join (backend_url,
-                             "private/products",
+  tgh = GNUNET_new (struct TALER_MERCHANT_TemplatesGetHandle);
+  tgh->ctx = ctx;
+  tgh->cb = cb;
+  tgh->cb_cls = cb_cls;
+  tgh->url = TALER_url_join (backend_url,
+                             "private/templates",
                              NULL);
-  if (NULL == pgh->url)
+  if (NULL == tgh->url)
   {
     GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
                 "Could not construct request URL.\n");
-    GNUNET_free (pgh);
+    GNUNET_free (tgh);
     return NULL;
   }
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
               "Requesting URL '%s'\n",
-              pgh->url);
-  eh = TALER_MERCHANT_curl_easy_get_ (pgh->url);
-  pgh->job = GNUNET_CURL_job_add (ctx,
+              tgh->url);
+  eh = TALER_MERCHANT_curl_easy_get_ (tgh->url);
+  tgh->job = GNUNET_CURL_job_add (ctx,
                                   eh,
-                                  &handle_get_products_finished,
-                                  pgh);
-  return pgh;
+                                  &handle_get_templates_finished,
+                                  tgh);
+  return tgh;
 }
 
 
 void
-TALER_MERCHANT_products_get_cancel (
-  struct TALER_MERCHANT_ProductsGetHandle *pgh)
+TALER_MERCHANT_templates_get_cancel (
+  struct TALER_MERCHANT_TemplatesGetHandle *tgh)
 {
-  if (NULL != pgh->job)
-    GNUNET_CURL_job_cancel (pgh->job);
-  GNUNET_free (pgh->url);
-  GNUNET_free (pgh);
+  if (NULL != tgh->job)
+    GNUNET_CURL_job_cancel (tgh->job);
+  GNUNET_free (tgh->url);
+  GNUNET_free (tgh);
 }
diff --git a/src/lib/merchant_api_post_products.c 
b/src/lib/merchant_api_post_templates.c
similarity index 63%
copy from src/lib/merchant_api_post_products.c
copy to src/lib/merchant_api_post_templates.c
index 43799032..7723d10c 100644
--- a/src/lib/merchant_api_post_products.c
+++ b/src/lib/merchant_api_post_templates.c
@@ -17,8 +17,8 @@
   If not, see <http://www.gnu.org/licenses/>
 */
 /**
- * @file merchant_api_post_products.c
- * @brief Implementation of the POST /products request
+ * @file merchant_api_post_templates.c
+ * @brief Implementation of the POST /templates request
  *        of the merchant's HTTP API
  * @author Christian Grothoff
  */
@@ -34,9 +34,9 @@
 
 
 /**
- * Handle for a POST /products/$ID operation.
+ * Handle for a POST /templates/$ID operation.
  */
-struct TALER_MERCHANT_ProductsPostHandle
+struct TALER_MERCHANT_TemplatesPostHandle
 {
 
   /**
@@ -52,7 +52,7 @@ struct TALER_MERCHANT_ProductsPostHandle
   /**
    * Function to call with the result.
    */
-  TALER_MERCHANT_ProductsPostCallback cb;
+  TALER_MERCHANT_TemplatesPostCallback cb;
 
   /**
    * Closure for @a cb.
@@ -76,25 +76,25 @@ struct TALER_MERCHANT_ProductsPostHandle
  * Function called when we're done processing the
  * HTTP POST /products request.
  *
- * @param cls the `struct TALER_MERCHANT_ProductsPostHandle`
+ * @param cls the `struct TALER_MERCHANT_TemplatesPostHandle`
  * @param response_code HTTP response code, 0 on error
  * @param response response body, NULL if not in JSON
  */
 static void
-handle_post_products_finished (void *cls,
+handle_post_templates_finished (void *cls,
                                long response_code,
                                const void *response)
 {
-  struct TALER_MERCHANT_ProductsPostHandle *pph = cls;
+  struct TALER_MERCHANT_TemplatesPostHandle *tph = cls;
   const json_t *json = response;
   struct TALER_MERCHANT_HttpResponse hr = {
     .http_status = (unsigned int) response_code,
     .reply = json
   };
 
-  pph->job = NULL;
+  tph->job = NULL;
   GNUNET_log (GNUNET_ERROR_TYPE_INFO,
-              "POST /products completed with response code %u\n",
+              "POST /templates completed with response code %u\n",
               (unsigned int) response_code);
   switch (response_code)
   {
@@ -151,102 +151,83 @@ handle_post_products_finished (void *cls,
     GNUNET_break_op (0);
     break;
   }
-  pph->cb (pph->cb_cls,
+  tph->cb (tph->cb_cls,
            &hr);
-  TALER_MERCHANT_products_post_cancel (pph);
+  TALER_MERCHANT_templates_post_cancel (tph);
 }
 
 
-struct TALER_MERCHANT_ProductsPostHandle *
-TALER_MERCHANT_products_post (
+struct TALER_MERCHANT_TemplatesPostHandle *
+TALER_MERCHANT_templates_post (
   struct GNUNET_CURL_Context *ctx,
   const char *backend_url,
-  const char *product_id,
-  const char *description,
-  const json_t *description_i18n,
-  const char *unit,
-  const struct TALER_Amount *price,
+  const char *template_id,
+  const char *template_description,
   const char *image,
-  const json_t *taxes,
-  int64_t total_stock,
-  const json_t *address,
-  struct GNUNET_TIME_Timestamp next_restock,
-  TALER_MERCHANT_ProductsPostCallback cb,
+  const json_t *template_contract,
+  TALER_MERCHANT_TemplatesPostCallback cb,
   void *cb_cls)
 {
-  struct TALER_MERCHANT_ProductsPostHandle *pph;
+  struct TALER_MERCHANT_TemplatesPostHandle *tph;
   json_t *req_obj;
 
   req_obj = GNUNET_JSON_PACK (
-    GNUNET_JSON_pack_string ("product_id",
-                             product_id),
-    GNUNET_JSON_pack_string ("description",
-                             description),
-    GNUNET_JSON_pack_object_incref ("description_i18n",
-                                    (json_t *) description_i18n),
-    GNUNET_JSON_pack_string ("unit",
-                             unit),
-    TALER_JSON_pack_amount ("price",
-                            price),
+    GNUNET_JSON_pack_string ("template_id",
+                             template_id),
+    GNUNET_JSON_pack_string ("template_description",
+                             template_description),
     GNUNET_JSON_pack_string ("image",
                              image),
-    GNUNET_JSON_pack_array_incref ("taxes",
-                                   (json_t *) taxes),
-    GNUNET_JSON_pack_uint64 ("total_stock",
-                             total_stock),
-    GNUNET_JSON_pack_object_incref ("address",
-                                    (json_t *) address),
-    GNUNET_JSON_pack_allow_null (
-      GNUNET_JSON_pack_timestamp ("next_restock",
-                                  next_restock)));
-  pph = GNUNET_new (struct TALER_MERCHANT_ProductsPostHandle);
-  pph->ctx = ctx;
-  pph->cb = cb;
-  pph->cb_cls = cb_cls;
-  pph->url = TALER_url_join (backend_url,
-                             "private/products",
+    GNUNET_JSON_pack_object_incref ("template_contract",
+                                    (json_t *) template_contract));
+  tph = GNUNET_new (struct TALER_MERCHANT_TemplatesPostHandle);
+  tph->ctx = ctx;
+  tph->cb = cb;
+  tph->cb_cls = cb_cls;
+  tph->url = TALER_url_join (backend_url,
+                             "private/templates",
                              NULL);
-  if (NULL == pph->url)
+  if (NULL == tph->url)
   {
     GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
                 "Could not construct request URL.\n");
     json_decref (req_obj);
-    GNUNET_free (pph);
+    GNUNET_free (tph);
     return NULL;
   }
   {
     CURL *eh;
 
-    eh = TALER_MERCHANT_curl_easy_get_ (pph->url);
+    eh = TALER_MERCHANT_curl_easy_get_ (tph->url);
     GNUNET_assert (GNUNET_OK ==
-                   TALER_curl_easy_post (&pph->post_ctx,
+                   TALER_curl_easy_post (&tph->post_ctx,
                                          eh,
                                          req_obj));
     json_decref (req_obj);
-    pph->job = GNUNET_CURL_job_add2 (ctx,
+    tph->job = GNUNET_CURL_job_add2 (ctx,
                                      eh,
-                                     pph->post_ctx.headers,
-                                     &handle_post_products_finished,
-                                     pph);
-    GNUNET_assert (NULL != pph->job);
+                                     tph->post_ctx.headers,
+                                     &handle_post_templates_finished,
+                                     tph);
+    GNUNET_assert (NULL != tph->job);
   }
-  return pph;
+  return tph;
 }
 
 
 void
-TALER_MERCHANT_products_post_cancel (
-  struct TALER_MERCHANT_ProductsPostHandle *pph)
+TALER_MERCHANT_templates_post_cancel (
+  struct TALER_MERCHANT_TemplatesPostHandle *tph)
 {
-  if (NULL != pph->job)
+  if (NULL != tph->job)
   {
-    GNUNET_CURL_job_cancel (pph->job);
-    pph->job = NULL;
+    GNUNET_CURL_job_cancel (tph->job);
+    tph->job = NULL;
   }
-  TALER_curl_easy_post_finished (&pph->post_ctx);
-  GNUNET_free (pph->url);
-  GNUNET_free (pph);
+  TALER_curl_easy_post_finished (&tph->post_ctx);
+  GNUNET_free (tph->url);
+  GNUNET_free (tph);
 }
 
 
-/* end of merchant_api_post_products.c */
+/* end of merchant_api_post_templates.c */

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