gnunet-svn
[Top][All Lists]
Advanced

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

[taler-merchant] branch master updated (12a416ff -> ad99fc41)


From: gnunet
Subject: [taler-merchant] branch master updated (12a416ff -> ad99fc41)
Date: Tue, 29 Nov 2022 14:20:31 +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 12a416ff fix typo
     new 99211b46 webhook backend
     new ad99fc41 update

The 2 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                 |  54 ++++++++++
 src/backend/taler-merchant-httpd.h                 |   4 +-
 ...er-merchant-httpd_private-delete-webhooks-ID.c} |  18 ++--
 ...er-merchant-httpd_private-delete-webhooks-ID.h} |  14 +--
 ...taler-merchant-httpd_private-get-webhooks-ID.c} |  45 ++++----
 ...taler-merchant-httpd_private-get-webhooks-ID.h} |  14 +--
 ...=> taler-merchant-httpd_private-get-webhooks.c} |  30 +++---
 ...=> taler-merchant-httpd_private-get-webhooks.h} |  14 +--
 ...ler-merchant-httpd_private-patch-webhooks-ID.c} |  91 ++++++----------
 ...ler-merchant-httpd_private-patch-webhooks-ID.h} |  10 +-
 ...> taler-merchant-httpd_private-post-webhooks.c} | 120 +++++++++------------
 ...> taler-merchant-httpd_private-post-webhooks.h} |  12 +--
 src/backenddb/merchant-0001.sql                    |   2 +-
 14 files changed, 233 insertions(+), 205 deletions(-)
 copy src/backend/{taler-merchant-httpd_private-delete-templates-ID.c => 
taler-merchant-httpd_private-delete-webhooks-ID.c} (81%)
 copy src/backend/{taler-merchant-httpd_private-delete-templates-ID.h => 
taler-merchant-httpd_private-delete-webhooks-ID.h} (73%)
 copy src/backend/{taler-merchant-httpd_private-get-templates-ID.c => 
taler-merchant-httpd_private-get-webhooks-ID.c} (62%)
 copy src/backend/{taler-merchant-httpd_private-get-templates-ID.h => 
taler-merchant-httpd_private-get-webhooks-ID.h} (74%)
 copy src/backend/{taler-merchant-httpd_private-get-templates.c => 
taler-merchant-httpd_private-get-webhooks.c} (72%)
 copy src/backend/{taler-merchant-httpd_private-get-templates.h => 
taler-merchant-httpd_private-get-webhooks.h} (75%)
 copy src/backend/{taler-merchant-httpd_private-patch-templates-ID.c => 
taler-merchant-httpd_private-patch-webhooks-ID.c} (67%)
 copy src/backend/{taler-merchant-httpd_private-patch-templates-ID.h => 
taler-merchant-httpd_private-patch-webhooks-ID.h} (79%)
 copy src/backend/{taler-merchant-httpd_private-post-templates.c => 
taler-merchant-httpd_private-post-webhooks.c} (60%)
 copy src/backend/{taler-merchant-httpd_private-post-templates.h => 
taler-merchant-httpd_private-post-webhooks.h} (77%)

diff --git a/src/backend/Makefile.am b/src/backend/Makefile.am
index a24e80ad..de283293 100644
--- a/src/backend/Makefile.am
+++ b/src/backend/Makefile.am
@@ -36,6 +36,8 @@ taler_merchant_httpd_SOURCES = \
   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-webhooks-ID.c \
+    taler-merchant-httpd_private-delete-webhooks-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 \
@@ -70,8 +72,14 @@ taler_merchant_httpd_SOURCES = \
     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-get-webhooks.c \
+    taler-merchant-httpd_private-get-webhooks.h \
+  taler-merchant-httpd_private-get-webhooks-ID.c \
+    taler-merchant-httpd_private-get-webhooks-ID.h \
   taler-merchant-httpd_private-patch-templates-ID.c \
     taler-merchant-httpd_private-patch-templates-ID.h \
+  taler-merchant-httpd_private-patch-webhooks-ID.c \
+    taler-merchant-httpd_private-patch-webhooks-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 \
@@ -80,6 +88,8 @@ taler_merchant_httpd_SOURCES = \
     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-webhooks.c \
+    taler-merchant-httpd_private-post-webhooks.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 95484c37..d16a55ee 100644
--- a/src/backend/taler-merchant-httpd.c
+++ b/src/backend/taler-merchant-httpd.c
@@ -34,12 +34,15 @@
 #include "taler-merchant-httpd_get-orders-ID.h"
 #include "taler-merchant-httpd_get-tips-ID.h"
 #include "taler-merchant-httpd_mhd.h"
+#include "taler-merchant-httpd_private-delete-webhooks-ID.h"
 #include "taler-merchant-httpd_private-delete-templates-ID.h"
 #include "taler-merchant-httpd_private-delete-instances-ID.h"
 #include "taler-merchant-httpd_private-delete-products-ID.h"
 #include "taler-merchant-httpd_private-delete-orders-ID.h"
 #include "taler-merchant-httpd_private-delete-reserves-ID.h"
 #include "taler-merchant-httpd_private-delete-transfers-ID.h"
+#include "taler-merchant-httpd_private-get-webhooks.h"
+#include "taler-merchant-httpd_private-get-webhooks-ID.h"
 #include "taler-merchant-httpd_private-get-templates.h"
 #include "taler-merchant-httpd_private-get-templates-ID.h"
 #include "taler-merchant-httpd_private-get-instances.h"
@@ -54,10 +57,12 @@
 #include "taler-merchant-httpd_private-get-tips-ID.h"
 #include "taler-merchant-httpd_private-get-tips.h"
 #include "taler-merchant-httpd_private-get-transfers.h"
+#include "taler-merchant-httpd_private-patch-webhooks-ID.h"
 #include "taler-merchant-httpd_private-patch-templates-ID.h"
 #include "taler-merchant-httpd_private-patch-instances-ID.h"
 #include "taler-merchant-httpd_private-patch-orders-ID-forget.h"
 #include "taler-merchant-httpd_private-patch-products-ID.h"
+#include "taler-merchant-httpd_private-post-webhooks.h"
 #include "taler-merchant-httpd_private-post-templates.h"
 #include "taler-merchant-httpd_private-post-instances.h"
 #include "taler-merchant-httpd_private-post-instances-ID-auth.h"
@@ -1103,6 +1108,55 @@ url_handler (void *cls,
          in the code... */
       .max_upload = 1024 * 1024 * 8
     },
+    {
+      .url_prefix = NULL
+    },
+    /* GET /webhooks: */
+    {
+      .url_prefix = "/webhooks/",
+      .method = MHD_HTTP_METHOD_GET,
+      .handler = &TMH_private_get_webhooks
+    },
+    /* POST /webhooks: */
+    {
+      .url_prefix = "/webhooks/",
+      .method = MHD_HTTP_METHOD_POST,
+      .handler = &TMH_private_post_webhooks,
+      /* allow webhook 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 /webhooks/$ID/: */
+    {
+      .url_prefix = "/webhooks/",
+      .method = MHD_HTTP_METHOD_GET,
+      .have_id_segment = true,
+      .allow_deleted_instance = true,
+      .handler = &TMH_private_get_webhooks_ID
+    },
+    /* DELETE /webhooks/$ID/: */
+    {
+      .url_prefix = "/webhooks/",
+      .method = MHD_HTTP_METHOD_DELETE,
+      .have_id_segment = true,
+      .allow_deleted_instance = true,
+      .handler = &TMH_private_delete_webhooks_ID
+    },
+    /* PATCH /webhooks/$ID/: */
+    {
+      .url_prefix = "/webhooks/",
+      .method = MHD_HTTP_METHOD_PATCH,
+      .have_id_segment = true,
+      .allow_deleted_instance = true,
+      .handler = &TMH_private_patch_webhooks_ID,
+      /* allow webhook 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.h 
b/src/backend/taler-merchant-httpd.h
index 5dbb0c94..e8911b32 100644
--- a/src/backend/taler-merchant-httpd.h
+++ b/src/backend/taler-merchant-httpd.h
@@ -381,7 +381,7 @@ struct TMH_RequestHandler
 
   /**
    * URL prefix the handler is for, includes the '/',
-   * so "/orders", "/templates" or "/products".  Does *not* include
+   * so "/orders", "/templates", "/webhooks" or "/products".  Does *not* 
include
    * "/private", that is controlled by the array in which
    * the handler is defined.  Must not contain any
    * '/' except for the leading '/'.
@@ -390,7 +390,7 @@ struct TMH_RequestHandler
 
   /**
    * Does this request include an identifier segment
-   * (product_id, reserve_pub, order_id, tip_id, template_id) in the
+   * (product_id, reserve_pub, order_id, tip_id, template_id, webhook_id) in 
the
    * second segment?
    */
   bool have_id_segment;
diff --git a/src/backend/taler-merchant-httpd_private-delete-templates-ID.c 
b/src/backend/taler-merchant-httpd_private-delete-webhooks-ID.c
similarity index 81%
copy from src/backend/taler-merchant-httpd_private-delete-templates-ID.c
copy to src/backend/taler-merchant-httpd_private-delete-webhooks-ID.c
index c9a04295..6a8db79c 100644
--- a/src/backend/taler-merchant-httpd_private-delete-templates-ID.c
+++ b/src/backend/taler-merchant-httpd_private-delete-webhooks-ID.c
@@ -14,17 +14,17 @@
   TALER; see the file COPYING.  If not, see <http://www.gnu.org/licenses/>
 */
 /**
- * @file taler-merchant-httpd_private-delete-templates-ID.c
- * @brief implement DELETE /templates/$ID
+ * @file taler-merchant-httpd_private-delete-webhooks-ID.c
+ * @brief implement DELETE /webhooks/$ID
  * @author Priscilla HUANG
  */
 #include "platform.h"
-#include "taler-merchant-httpd_private-delete-templates-ID.h"
+#include "taler-merchant-httpd_private-delete-webhooks-ID.h"
 #include <taler/taler_json_lib.h>
 
 
 /**
- * Handle a DELETE "/templates/$ID" request.
+ * Handle a DELETE "/webhooks/$ID" request.
  *
  * @param rh context of the handler
  * @param connection the MHD connection to handle
@@ -32,7 +32,7 @@
  * @return MHD result code
  */
 MHD_RESULT
-TMH_private_delete_templates_ID (const struct TMH_RequestHandler *rh,
+TMH_private_delete_webhooks_ID (const struct TMH_RequestHandler *rh,
                                 struct MHD_Connection *connection,
                                 struct TMH_HandlerContext *hc)
 {
@@ -42,7 +42,7 @@ TMH_private_delete_templates_ID (const struct 
TMH_RequestHandler *rh,
   (void) rh;
   GNUNET_assert (NULL != mi);
   GNUNET_assert (NULL != hc->infix);
-  qs = TMH_db->delete_template (TMH_db->cls,
+  qs = TMH_db->delete_webhook (TMH_db->cls,
                                mi->settings.id,
                                hc->infix);
   switch (qs)
@@ -51,13 +51,13 @@ TMH_private_delete_templates_ID (const struct 
TMH_RequestHandler *rh,
     return TALER_MHD_reply_with_error (connection,
                                        MHD_HTTP_INTERNAL_SERVER_ERROR,
                                        TALER_EC_GENERIC_DB_STORE_FAILED,
-                                       "delete_template");
+                                       "delete_webhook");
   case GNUNET_DB_STATUS_SOFT_ERROR:
     GNUNET_break (0);
     return TALER_MHD_reply_with_error (connection,
                                        MHD_HTTP_INTERNAL_SERVER_ERROR,
                                        
TALER_EC_GENERIC_INTERNAL_INVARIANT_FAILURE,
-                                       "delete_template (soft)");
+                                       "delete_webhook (soft)");
 
   case GNUNET_DB_STATUS_SUCCESS_ONE_RESULT:
     return TALER_MHD_reply_static (connection,
@@ -71,4 +71,4 @@ TMH_private_delete_templates_ID (const struct 
TMH_RequestHandler *rh,
 }
 
 
-/* end of taler-merchant-httpd_private-delete-templates-ID.c */
+/* end of taler-merchant-httpd_private-delete-webhooks-ID.c */
diff --git a/src/backend/taler-merchant-httpd_private-delete-templates-ID.h 
b/src/backend/taler-merchant-httpd_private-delete-webhooks-ID.h
similarity index 73%
copy from src/backend/taler-merchant-httpd_private-delete-templates-ID.h
copy to src/backend/taler-merchant-httpd_private-delete-webhooks-ID.h
index ec90a90d..ba77fb7a 100644
--- a/src/backend/taler-merchant-httpd_private-delete-templates-ID.h
+++ b/src/backend/taler-merchant-httpd_private-delete-webhooks-ID.h
@@ -14,18 +14,18 @@
   TALER; see the file COPYING.  If not, see <http://www.gnu.org/licenses/>
 */
 /**
- * @file taler-merchant-httpd_private-delete-templates-ID.h
- * @brief implement DELETE /templates/$ID/
+ * @file taler-merchant-httpd_private-delete-webhooks-ID.h
+ * @brief implement DELETE /webhooks/$ID/
  * @author Priscilla HUANG
  */
-#ifndef TALER_MERCHANT_HTTPD_PRIVATE_DELETE_TEMPLATES_ID_H
-#define TALER_MERCHANT_HTTPD_PRIVATE_DELETE_TEMPLATES_ID_H
+#ifndef TALER_MERCHANT_HTTPD_PRIVATE_DELETE_WEBHOOKS_ID_H
+#define TALER_MERCHANT_HTTPD_PRIVATE_DELETE_WEBHOOKS_ID_H
 
 #include "taler-merchant-httpd.h"
 
 
 /**
- * Handle a DELETE "/templates/$ID" request.
+ * Handle a DELETE "/webhooks/$ID" request.
  *
  * @param rh context of the handler
  * @param connection the MHD connection to handle
@@ -33,9 +33,9 @@
  * @return MHD result code
  */
 MHD_RESULT
-TMH_private_delete_templates_ID (const struct TMH_RequestHandler *rh,
+TMH_private_delete_webhooks_ID (const struct TMH_RequestHandler *rh,
                                 struct MHD_Connection *connection,
                                 struct TMH_HandlerContext *hc);
 
-/* end of taler-merchant-httpd_private-delete-templates-ID.h */
+/* end of taler-merchant-httpd_private-delete-webhooks-ID.h */
 #endif
diff --git a/src/backend/taler-merchant-httpd_private-get-templates-ID.c 
b/src/backend/taler-merchant-httpd_private-get-webhooks-ID.c
similarity index 62%
copy from src/backend/taler-merchant-httpd_private-get-templates-ID.c
copy to src/backend/taler-merchant-httpd_private-get-webhooks-ID.c
index 76e28fac..2780d145 100644
--- a/src/backend/taler-merchant-httpd_private-get-templates-ID.c
+++ b/src/backend/taler-merchant-httpd_private-get-webhooks-ID.c
@@ -14,17 +14,17 @@
   TALER; see the file COPYING.  If not, see <http://www.gnu.org/licenses/>
 */
 /**
- * @file taler-merchant-httpd_private-get-templates-ID.c
- * @brief implement GET /templates/$ID
+ * @file taler-merchant-httpd_private-get-webhooks-ID.c
+ * @brief implement GET /webhooks/$ID
  * @author Priscilla HUANG
  */
 #include "platform.h"
-#include "taler-merchant-httpd_private-get-templates-ID.h"
+#include "taler-merchant-httpd_private-get-webhooks-ID.h"
 #include <taler/taler_json_lib.h>
 
 
 /**
- * Handle a GET "/templates/$ID" request.
+ * Handle a GET "/webhooks/$ID" request.
  *
  * @param rh context of the handler
  * @param connection the MHD connection to handle
@@ -32,32 +32,32 @@
  * @return MHD result code
  */
 MHD_RESULT
-TMH_private_get_templates_ID (const struct TMH_RequestHandler *rh,
+TMH_private_get_webhooks_ID (const struct TMH_RequestHandler *rh,
                              struct MHD_Connection *connection,
                              struct TMH_HandlerContext *hc)
 {
   struct TMH_MerchantInstance *mi = hc->instance;
-  struct TALER_MERCHANTDB_TemplateDetails tp = { 0 };
+  struct TALER_MERCHANTDB_WebhookDetails wb = { 0 };
   enum GNUNET_DB_QueryStatus qs;
 
   GNUNET_assert (NULL != mi);
-  qs = TMH_db->lookup_template (TMH_db->cls,
+  qs = TMH_db->lookup_webhook (TMH_db->cls,
                                mi->settings.id,
                                hc->infix,
-                               &tp);
+                               &wb);
   if (0 > qs)
   {
     GNUNET_break (0);
     return TALER_MHD_reply_with_error (connection,
                                        MHD_HTTP_INTERNAL_SERVER_ERROR,
                                        TALER_EC_GENERIC_DB_FETCH_FAILED,
-                                       "lookup_template");
+                                       "lookup_webhook");
   }
   if (0 == qs)
   {
     return TALER_MHD_reply_with_error (connection,
                                        MHD_HTTP_NOT_FOUND,
-                                       
TALER_EC_MERCHANT_GENERIC_TEMPLATE_UNKNOWN,
+                                       
TALER_EC_MERCHANT_GENERIC_WEBHOOK_UNKNOWN,
                                        hc->infix);
   }
   {
@@ -66,18 +66,25 @@ TMH_private_get_templates_ID (const struct 
TMH_RequestHandler *rh,
     ret = TALER_MHD_REPLY_JSON_PACK (
       connection,
       MHD_HTTP_OK,
-      GNUNET_JSON_pack_string ("template_description",
-                               tp.template_description),
-      GNUNET_JSON_pack_string ("image",
-                               tp.image),
-      GNUNET_JSON_pack_object_steal ("template_contract",
-                                     tp.template_contract));
-    GNUNET_free (tp.template_description);
-    GNUNET_free (tp.image);
+      GNUNET_JSON_pack_string ("event_type",
+                               wb.event_type),
+      GNUNET_JSON_pack_string ("url",
+                               wb.url),
+      GNUNET_JSON_pack_string ("http_method",
+                               wb.http_method),
+      GNUNET_JSON_pack_string ("header_template",
+                               wb.header_template),
+      GNUNET_JSON_pack_string ("body_template",
+                               wb.body_template));
+    GNUNET_free (wb.event_type);
+    GNUNET_free (wb.url);
+    GNUNET_free (wb.http_method);
+    GNUNET_free (wb.header_template);
+    GNUNET_free (wb.body_template);
 
     return ret;
   }
 }
 
 
-/* end of taler-merchant-httpd_private-get-templates-ID.c */
+/* end of taler-merchant-httpd_private-get-webhooks-ID.c */
diff --git a/src/backend/taler-merchant-httpd_private-get-templates-ID.h 
b/src/backend/taler-merchant-httpd_private-get-webhooks-ID.h
similarity index 74%
copy from src/backend/taler-merchant-httpd_private-get-templates-ID.h
copy to src/backend/taler-merchant-httpd_private-get-webhooks-ID.h
index b16207d5..261edb41 100644
--- a/src/backend/taler-merchant-httpd_private-get-templates-ID.h
+++ b/src/backend/taler-merchant-httpd_private-get-webhooks-ID.h
@@ -14,18 +14,18 @@
   TALER; see the file COPYING.  If not, see <http://www.gnu.org/licenses/>
 */
 /**
- * @file taler-merchant-httpd_private-get-templates-ID.h
- * @brief implement GET /templates/$ID/
+ * @file taler-merchant-httpd_private-get-webhooks-ID.h
+ * @brief implement GET /webhooks/$ID/
  * @author Priscilla HUANG
  */
-#ifndef TALER_MERCHANT_HTTPD_PRIVATE_GET_TEMPLATES_ID_H
-#define TALER_MERCHANT_HTTPD_PRIVATE_GET_TEMPLATES_ID_H
+#ifndef TALER_MERCHANT_HTTPD_PRIVATE_GET_WEBHOOKS_ID_H
+#define TALER_MERCHANT_HTTPD_PRIVATE_GET_WEBHOOKS_ID_H
 
 #include "taler-merchant-httpd.h"
 
 
 /**
- * Handle a GET "/templates/$ID" request.
+ * Handle a GET "/webhooks/$ID" request.
  *
  * @param rh context of the handler
  * @param connection the MHD connection to handle
@@ -33,9 +33,9 @@
  * @return MHD result code
  */
 MHD_RESULT
-TMH_private_get_templates_ID (const struct TMH_RequestHandler *rh,
+TMH_private_get_webhooks_ID (const struct TMH_RequestHandler *rh,
                              struct MHD_Connection *connection,
                              struct TMH_HandlerContext *hc);
 
-/* end of taler-merchant-httpd_private-get-templates-ID.h */
+/* end of taler-merchant-httpd_private-get-webhooks-ID.h */
 #endif
diff --git a/src/backend/taler-merchant-httpd_private-get-templates.c 
b/src/backend/taler-merchant-httpd_private-get-webhooks.c
similarity index 72%
copy from src/backend/taler-merchant-httpd_private-get-templates.c
copy to src/backend/taler-merchant-httpd_private-get-webhooks.c
index 86237f07..cda4eda9 100644
--- a/src/backend/taler-merchant-httpd_private-get-templates.c
+++ b/src/backend/taler-merchant-httpd_private-get-webhooks.c
@@ -14,24 +14,24 @@
   TALER; see the file COPYING.  If not, see <http://www.gnu.org/licenses/>
 */
 /**
- * @file taler-merchant-httpd_private-get-templates.c
- * @brief implement GET /templates
+ * @file taler-merchant-httpd_private-get-webhooks.c
+ * @brief implement GET /webhooks
  * @author Priscilla HUANG
  */
 #include "platform.h"
-#include "taler-merchant-httpd_private-get-templates.h"
+#include "taler-merchant-httpd_private-get-webhooks.h"
 
 
 /**
- * Add template details to our JSON array.
+ * Add webhook details to our JSON array.
  *
  * @param cls a `json_t *` JSON array to build
- * @param template_id ID of the template
+ * @param webhook_id ID of the webhook
  */
 static void
-add_template (void *cls,
-              const char *template_id,
-              const char *template_description)
+add_webhook (void *cls,
+              const char *webhook_id,
+              const char *event_type)
 {
   json_t *pa = cls;
 
@@ -39,13 +39,13 @@ add_template (void *cls,
                  json_array_append_new (
                    pa,
                    GNUNET_JSON_PACK (
-                     GNUNET_JSON_pack_string ("template_id",
-                                              template_id))));
+                     GNUNET_JSON_pack_string ("webhook_id",
+                                              webhook_id))));
 }
 
 
 MHD_RESULT
-TMH_private_get_templates (const struct TMH_RequestHandler *rh,
+TMH_private_get_webhooks (const struct TMH_RequestHandler *rh,
                           struct MHD_Connection *connection,
                           struct TMH_HandlerContext *hc)
 {
@@ -54,9 +54,9 @@ TMH_private_get_templates (const struct TMH_RequestHandler 
*rh,
 
   pa = json_array ();
   GNUNET_assert (NULL != pa);
-  qs = TMH_db->lookup_templates (TMH_db->cls,
+  qs = TMH_db->lookup_webhooks (TMH_db->cls,
                                 hc->instance->settings.id,
-                                &add_template,
+                                &add_webhook,
                                 pa);
   if (0 > qs)
   {
@@ -69,9 +69,9 @@ TMH_private_get_templates (const struct TMH_RequestHandler 
*rh,
   }
   return TALER_MHD_REPLY_JSON_PACK (connection,
                                     MHD_HTTP_OK,
-                                    GNUNET_JSON_pack_array_steal ("templates",
+                                    GNUNET_JSON_pack_array_steal ("webhooks",
                                                                   pa));
 }
 
 
-/* end of taler-merchant-httpd_private-get-templates.c */
+/* end of taler-merchant-httpd_private-get-webhooks.c */
diff --git a/src/backend/taler-merchant-httpd_private-get-templates.h 
b/src/backend/taler-merchant-httpd_private-get-webhooks.h
similarity index 75%
copy from src/backend/taler-merchant-httpd_private-get-templates.h
copy to src/backend/taler-merchant-httpd_private-get-webhooks.h
index 3194d1c7..297e5ace 100644
--- a/src/backend/taler-merchant-httpd_private-get-templates.h
+++ b/src/backend/taler-merchant-httpd_private-get-webhooks.h
@@ -14,18 +14,18 @@
   TALER; see the file COPYING.  If not, see <http://www.gnu.org/licenses/>
 */
 /**
- * @file taler-merchant-httpd_private-get-templates.h
- * @brief implement GET /templates
+ * @file taler-merchant-httpd_private-get-webhooks.h
+ * @brief implement GET /webhooks
  * @author Priscilla HUANG
  */
-#ifndef TALER_MERCHANT_HTTPD_PRIVATE_GET_TEMPLATES_H
-#define TALER_MERCHANT_HTTPD_PRIVATE_GET_TEMPLATES_H
+#ifndef TALER_MERCHANT_HTTPD_PRIVATE_GET_WEBHOOKS_H
+#define TALER_MERCHANT_HTTPD_PRIVATE_GET_WEBHOOKS_H
 
 #include "taler-merchant-httpd.h"
 
 
 /**
- * Handle a GET "/templates" request.
+ * Handle a GET "/webhooks" request.
  *
  * @param rh context of the handler
  * @param connection the MHD connection to handle
@@ -33,9 +33,9 @@
  * @return MHD result code
  */
 MHD_RESULT
-TMH_private_get_templates (const struct TMH_RequestHandler *rh,
+TMH_private_get_webhooks (const struct TMH_RequestHandler *rh,
                           struct MHD_Connection *connection,
                           struct TMH_HandlerContext *hc);
 
-/* end of taler-merchant-httpd_private-get-templates.h */
+/* end of taler-merchant-httpd_private-get-webhooks.h */
 #endif
diff --git a/src/backend/taler-merchant-httpd_private-patch-templates-ID.c 
b/src/backend/taler-merchant-httpd_private-patch-webhooks-ID.c
similarity index 67%
copy from src/backend/taler-merchant-httpd_private-patch-templates-ID.c
copy to src/backend/taler-merchant-httpd_private-patch-webhooks-ID.c
index 9494d506..3144687b 100644
--- a/src/backend/taler-merchant-httpd_private-patch-templates-ID.c
+++ b/src/backend/taler-merchant-httpd_private-patch-webhooks-ID.c
@@ -18,12 +18,12 @@
 */
 
 /**
- * @file taler-merchant-httpd_private-patch-templates-ID.c
- * @brief implementing PATCH /templates/$ID request handling
+ * @file taler-merchant-httpd_private-patch-webhooks-ID.c
+ * @brief implementing PATCH /webhooks/$ID request handling
  * @author Priscilla HUANG
  */
 #include "platform.h"
-#include "taler-merchant-httpd_private-patch-templates-ID.h"
+#include "taler-merchant-httpd_private-patch-webhooks-ID.h"
 #include "taler-merchant-httpd_helper.h"
 #include <taler/taler_json_lib.h>
 
@@ -39,22 +39,22 @@
  *
  * @param connection connection to report on
  * @param instance_id instance we are processing
- * @param template_id ID of the product to patch
- * @param tp template details we failed to set
+ * @param webhook_id ID of the webhook to patch
+ * @param wb webhook details we failed to set
  */
 static MHD_RESULT
 determine_cause (struct MHD_Connection *connection,
                  const char *instance_id,
-                 const char *template_id,
-                 const struct TALER_MERCHANTDB_TemplateDetails *tp)
+                 const char *webhook_id,
+                 const struct TALER_MERCHANTDB_WebhookDetails *wb)
 {
-  struct TALER_MERCHANTDB_TemplateDetails tpx;
+  struct TALER_MERCHANTDB_WebhookDetails wpx;
   enum GNUNET_DB_QueryStatus qs;
 
-  qs = TMH_db->lookup_template (TMH_db->cls,
+  qs = TMH_db->lookup_webhook (TMH_db->cls,
                                instance_id,
-                               template_id,
-                               &tpx);
+                               webhook_id,
+                               &wpx);
   switch (qs)
   {
   case GNUNET_DB_STATUS_HARD_ERROR:
@@ -72,8 +72,8 @@ determine_cause (struct MHD_Connection *connection,
   case GNUNET_DB_STATUS_SUCCESS_NO_RESULTS:
     return TALER_MHD_reply_with_error (connection,
                                        MHD_HTTP_NOT_FOUND,
-                                       
TALER_EC_MERCHANT_GENERIC_TEMPLATE_UNKNOWN,
-                                       template_id);
+                                       
TALER_EC_MERCHANT_GENERIC_WEBHOOK_UNKNOWN,
+                                       webhook_id);
   case GNUNET_DB_STATUS_SUCCESS_ONE_RESULT:
     break; /* do below */
   }
@@ -82,7 +82,7 @@ determine_cause (struct MHD_Connection *connection,
     enum TALER_ErrorCode ec;
 
     ec = TALER_EC_GENERIC_INTERNAL_INVARIANT_FAILURE;
-    TALER_MERCHANTDB_template_details_free (&tpx);
+    TALER_MERCHANTDB_webhook_details_free (&wpx);
     GNUNET_break (TALER_EC_GENERIC_INTERNAL_INVARIANT_FAILURE != ec);
     return TALER_MHD_reply_with_error (connection,
                                        MHD_HTTP_CONFLICT,
@@ -101,30 +101,31 @@ determine_cause (struct MHD_Connection *connection,
  * @return MHD result code
  */
 MHD_RESULT
-TMH_private_patch_templates_ID (const struct TMH_RequestHandler *rh,
+TMH_private_patch_webhooks_ID (const struct TMH_RequestHandler *rh,
                                struct MHD_Connection *connection,
                                struct TMH_HandlerContext *hc)
 {
   struct TMH_MerchantInstance *mi = hc->instance;
-  const char *template_id = hc->infix;
-  struct TALER_MERCHANTDB_TemplateDetails tp = {0};
+  const char *webhook_id = hc->infix;
+  struct TALER_MERCHANTDB_WebhookDetails wb = {0};
   enum GNUNET_DB_QueryStatus qs;
   struct GNUNET_JSON_Specification spec[] = {
-    GNUNET_JSON_spec_string ("template_description",
-                             (const char **) &tp.template_description),
-    GNUNET_JSON_spec_mark_optional (
-      GNUNET_JSON_spec_string ("image",
-                               (const char **) &tp.image),
-      NULL),
-    GNUNET_JSON_spec_mark_optional (
-      GNUNET_JSON_spec_json ("template_contract",
-                             &tp.template_contract),
-      NULL),
+    GNUNET_JSON_spec_string ("event_type",
+                             (const char **) &wb.event_type),
+    GNUNET_JSON_spec_string ("url",
+                             (const char **) &wb.url),
+    GNUNET_JSON_spec_string ("http_method",
+                             (const char **) &wb.http_method),
+    GNUNET_JSON_spec_string ("header_template",
+                             (const char **) &wb.header_template),
+    GNUNET_JSON_spec_string ("body_template",
+                             (const char **) &wb.body_template),
+
     GNUNET_JSON_spec_end ()
   };
 
   GNUNET_assert (NULL != mi);
-  GNUNET_assert (NULL != template_id);
+  GNUNET_assert (NULL != webhook_id);
   {
     enum GNUNET_GenericReturnValue res;
 
@@ -137,33 +138,11 @@ TMH_private_patch_templates_ID (const struct 
TMH_RequestHandler *rh,
              : MHD_NO;
   }
 
-    if (! TMH_template_contract_valid (tp.template_contract))
-  {
-    GNUNET_break_op (0);
-    GNUNET_JSON_parse_free (spec);
-    return TALER_MHD_reply_with_error (connection,
-                                       MHD_HTTP_BAD_REQUEST,
-                                       TALER_EC_GENERIC_PARAMETER_MALFORMED,
-                                       "template_contract");
-  }
-
-
-  if (NULL == tp.image)
-    tp.image = "";
-  if (! TMH_image_data_url_valid (tp.image))
-  {
-    GNUNET_break_op (0);
-    GNUNET_JSON_parse_free (spec);
-    return TALER_MHD_reply_with_error (connection,
-                                       MHD_HTTP_BAD_REQUEST,
-                                       TALER_EC_GENERIC_PARAMETER_MALFORMED,
-                                       "image");
-  }
 
-  qs = TMH_db->update_template (TMH_db->cls,
+  qs = TMH_db->update_webhook (TMH_db->cls,
                                mi->settings.id,
-                               template_id,
-                               &tp);
+                               webhook_id,
+                               &wb);
   {
     MHD_RESULT ret = MHD_NO;
 
@@ -186,8 +165,8 @@ TMH_private_patch_templates_ID (const struct 
TMH_RequestHandler *rh,
     case GNUNET_DB_STATUS_SUCCESS_NO_RESULTS:
       ret = determine_cause (connection,
                              mi->settings.id,
-                             template_id,
-                             &tp);
+                             webhook_id,
+                             &wb);
       break;
     case GNUNET_DB_STATUS_SUCCESS_ONE_RESULT:
       ret = TALER_MHD_reply_static (connection,
@@ -203,4 +182,4 @@ TMH_private_patch_templates_ID (const struct 
TMH_RequestHandler *rh,
 }
 
 
-/* end of taler-merchant-httpd_private-patch-templates-ID.c */
+/* end of taler-merchant-httpd_private-patch-webhooks-ID.c */
diff --git a/src/backend/taler-merchant-httpd_private-patch-templates-ID.h 
b/src/backend/taler-merchant-httpd_private-patch-webhooks-ID.h
similarity index 79%
copy from src/backend/taler-merchant-httpd_private-patch-templates-ID.h
copy to src/backend/taler-merchant-httpd_private-patch-webhooks-ID.h
index 80347cf8..c393b284 100644
--- a/src/backend/taler-merchant-httpd_private-patch-templates-ID.h
+++ b/src/backend/taler-merchant-httpd_private-patch-webhooks-ID.h
@@ -18,12 +18,12 @@
 */
 
 /**
- * @file taler-merchant-httpd_private-patch-templates-ID.h
- * @brief implementing PATCH /templates request handling
+ * @file taler-merchant-httpd_private-patch-webhooks-ID.h
+ * @brief implementing PATCH /webhooks request handling
  * @author Priscilla HUANG
  */
-#ifndef TALER_MERCHANT_HTTPD_PRIVATE_PATCH_TEMPLATES_ID_H
-#define TALER_MERCHANT_HTTPD_PRIVATE_PATCH_TEMPLATES_ID_H
+#ifndef TALER_MERCHANT_HTTPD_PRIVATE_PATCH_WEBHOOKS_ID_H
+#define TALER_MERCHANT_HTTPD_PRIVATE_PATCH_WEBHOOKS_ID_H
 #include "taler-merchant-httpd.h"
 
 
@@ -36,7 +36,7 @@
  * @return MHD result code
  */
 MHD_RESULT
-TMH_private_patch_templates_ID (const struct TMH_RequestHandler *rh,
+TMH_private_patch_webhooks_ID (const struct TMH_RequestHandler *rh,
                                struct MHD_Connection *connection,
                                struct TMH_HandlerContext *hc);
 
diff --git a/src/backend/taler-merchant-httpd_private-post-templates.c 
b/src/backend/taler-merchant-httpd_private-post-webhooks.c
similarity index 60%
copy from src/backend/taler-merchant-httpd_private-post-templates.c
copy to src/backend/taler-merchant-httpd_private-post-webhooks.c
index 55dd7954..57fa3a65 100644
--- a/src/backend/taler-merchant-httpd_private-post-templates.c
+++ b/src/backend/taler-merchant-httpd_private-post-webhooks.c
@@ -18,12 +18,12 @@
 */
 
 /**
- * @file taler-merchant-httpd_private-post-templates.c
- * @brief implementing POST /templates request handling
+ * @file taler-merchant-httpd_private-post-webhooks.c
+ * @brief implementing POST /webhooks request handling
  * @author Priscilla HUANG
  */
 #include "platform.h"
-#include "taler-merchant-httpd_private-post-templates.h"
+#include "taler-merchant-httpd_private-post-webhooks.h"
 #include "taler-merchant-httpd_helper.h"
 #include <taler/taler_json_lib.h>
 
@@ -35,47 +35,51 @@
 
 
 /**
- * Check if the two templates are identical.
+ * Check if the two webhooks are identical.
  *
- * @param t1 template to compare
- * @param t2 other template to compare
+ * @param w1 webhook to compare
+ * @param w2 other webhook to compare
  * @return true if they are 'equal', false if not or of payto_uris is not an 
array
  */
 static bool
-templates_equal (const struct TALER_MERCHANTDB_TemplateDetails *t1,
-                const struct TALER_MERCHANTDB_TemplateDetails *t2)
+webhooks_equal (const struct TALER_MERCHANTDB_WebhookDetails *w1,
+                const struct TALER_MERCHANTDB_WebhookDetails *w2)
 {
-  return ( (0 == strcmp (t1->template_description,
-                         t2->template_description)) &&
-           (0 == strcmp (t1->image,
-                         t2->image)) &&
-           (1 == json_equal (t1->template_contract,
-                             t2->template_contract)));
+  return ( (0 == strcmp (w1->event_type,
+                         w2->event_type)) &&
+           (0 == strcmp (w1->url,
+                         w2->url)) &&
+           (0 == strcmp (w1->http_method,
+                         w2->http_method)) &&
+           (0 == strcmp (w1->header_template,
+                         w2->header_template)) &&
+           (0 == strcmp (w1->body_template,
+                         w2->body_template)));
 }
 
 
 MHD_RESULT
-TMH_private_post_templates (const struct TMH_RequestHandler *rh,
+TMH_private_post_webhooks (const struct TMH_RequestHandler *rh,
                            struct MHD_Connection *connection,
                            struct TMH_HandlerContext *hc)
 {
   struct TMH_MerchantInstance *mi = hc->instance;
-  struct TALER_MERCHANTDB_TemplateDetails tp = { 0 };
-  const char *template_id;
+  struct TALER_MERCHANTDB_WebhookDetails wb = { 0 };
+  const char *webhook_id;
   enum GNUNET_DB_QueryStatus qs;
   struct GNUNET_JSON_Specification spec[] = {
-    GNUNET_JSON_spec_string ("template_id",
-                             &template_id),
-    GNUNET_JSON_spec_string ("template_description",
-                             (const char **) &tp.template_description),
-    GNUNET_JSON_spec_mark_optional (
-      GNUNET_JSON_spec_string ("image",
-                               (const char **) &tp.image),
-      NULL),
-    GNUNET_JSON_spec_mark_optional (
-      GNUNET_JSON_spec_json ("template_contract",
-                             &tp.template_contract),
-      NULL),
+    GNUNET_JSON_spec_string ("webhook_id",
+                             &webhook_id),
+    GNUNET_JSON_spec_string ("event_type",
+                             (const char **) &wb.event_type),
+    GNUNET_JSON_spec_string ("url",
+                             (const char **) &wb.url),
+    GNUNET_JSON_spec_string ("http_method",
+                             (const char **) &wb.http_method),
+    GNUNET_JSON_spec_string ("header_template",
+                             (const char **) &wb.header_template),
+    GNUNET_JSON_spec_string ("body_template",
+                             (const char **) &wb.body_template),
     GNUNET_JSON_spec_end ()
   };
 
@@ -96,42 +100,16 @@ TMH_private_post_templates (const struct 
TMH_RequestHandler *rh,
   }
 
 
-  if (NULL == tp.template_contract)
-    tp.template_contract = json_object ();;
-
-
-  if (! TMH_template_contract_valid (tp.template_contract))
-  {
-    GNUNET_break_op (0);
-    GNUNET_JSON_parse_free (spec);
-    return TALER_MHD_reply_with_error (connection,
-                                       MHD_HTTP_BAD_REQUEST,
-                                       TALER_EC_GENERIC_PARAMETER_MALFORMED,
-                                       "template_contract");
-  }
-
-
-  if (NULL == tp.image)
-    tp.image = "";
-  if (! TMH_image_data_url_valid (tp.image))
-  {
-    GNUNET_break_op (0);
-    GNUNET_JSON_parse_free (spec);
-    return TALER_MHD_reply_with_error (connection,
-                                       MHD_HTTP_BAD_REQUEST,
-                                       TALER_EC_GENERIC_PARAMETER_MALFORMED,
-                                       "image");
-  }
 
   /* finally, interact with DB until no serialization error */
   for (unsigned int i = 0; i<MAX_RETRIES; i++)
   {
-    /* Test if a template of this id is known */
-    struct TALER_MERCHANTDB_TemplateDetails etp;
+    /* Test if a webhook of this id is known */
+    struct TALER_MERCHANTDB_WebhookDetails ewb;
 
     if (GNUNET_OK !=
         TMH_db->start (TMH_db->cls,
-                       "/post templates"))
+                       "/post webhooks"))
     {
       GNUNET_break (0);
       GNUNET_JSON_parse_free (spec);
@@ -140,10 +118,10 @@ TMH_private_post_templates (const struct 
TMH_RequestHandler *rh,
                                          TALER_EC_GENERIC_DB_START_FAILED,
                                          NULL);
     }
-    qs = TMH_db->lookup_template (TMH_db->cls,
+    qs = TMH_db->lookup_webhook (TMH_db->cls,
                                  mi->settings.id,
-                                 template_id,
-                                 &etp);
+                                 webhook_id,
+                                 &ewb);
     switch (qs)
     {
     case GNUNET_DB_STATUS_HARD_ERROR:
@@ -162,13 +140,13 @@ TMH_private_post_templates (const struct 
TMH_RequestHandler *rh,
       /* Good, we can proceed! */
       break;
     case GNUNET_DB_STATUS_SUCCESS_ONE_RESULT:
-      /* idempotency check: is etp == tp? */
+      /* idempotency check: is ewb == wb? */
       {
         bool eq;
 
-        eq = templates_equal (&tp,
-                             &etp);
-        TALER_MERCHANTDB_template_details_free (&etp);
+        eq = webhooks_equal (&wb,
+                             &ewb);
+        TALER_MERCHANTDB_webhook_details_free (&ewb);
         TMH_db->rollback (TMH_db->cls);
         GNUNET_JSON_parse_free (spec);
         return eq
@@ -179,15 +157,15 @@ TMH_private_post_templates (const struct 
TMH_RequestHandler *rh,
                                     0)
           : TALER_MHD_reply_with_error (connection,
                                         MHD_HTTP_CONFLICT,
-                                        
TALER_EC_MERCHANT_PRIVATE_POST_TEMPLATES_CONFLICT_TEMPLATE_EXISTS,
-                                        template_id);
+                                        
TALER_EC_MERCHANT_PRIVATE_POST_WEBHOOKS_CONFLICT_WEBHOOK_EXISTS,
+                                        webhook_id);
       }
     } /* end switch (qs) */
 
-    qs = TMH_db->insert_template (TMH_db->cls,
+    qs = TMH_db->insert_webhook (TMH_db->cls,
                                  mi->settings.id,
-                                 template_id,
-                                 &tp);
+                                 webhook_id,
+                                 &wb);
     if (GNUNET_DB_STATUS_HARD_ERROR == qs)
     {
       TMH_db->rollback (TMH_db->cls);
@@ -223,4 +201,4 @@ retry:
 }
 
 
-/* end of taler-merchant-httpd_private-post-templates.c */
+/* end of taler-merchant-httpd_private-post-webhooks.c */
diff --git a/src/backend/taler-merchant-httpd_private-post-templates.h 
b/src/backend/taler-merchant-httpd_private-post-webhooks.h
similarity index 77%
copy from src/backend/taler-merchant-httpd_private-post-templates.h
copy to src/backend/taler-merchant-httpd_private-post-webhooks.h
index fc946e46..24a7ccd4 100644
--- a/src/backend/taler-merchant-httpd_private-post-templates.h
+++ b/src/backend/taler-merchant-httpd_private-post-webhooks.h
@@ -18,17 +18,17 @@
 */
 
 /**
- * @file taler-merchant-httpd_private-post-templates.h
- * @brief implementing POST /templates request handling
+ * @file taler-merchant-httpd_private-post-webhooks.h
+ * @brief implementing POST /webhooks request handling
  * @author Priscilla HUANG
  */
-#ifndef TALER_MERCHANT_HTTPD_PRIVATE_POST_TEMPLATES_H
-#define TALER_MERCHANT_HTTPD_PRIVATE_POST_TEMPLATES_H
+#ifndef TALER_MERCHANT_HTTPD_PRIVATE_POST_WEBHOOKS_H
+#define TALER_MERCHANT_HTTPD_PRIVATE_POST_WEBHOOKS_H
 #include "taler-merchant-httpd.h"
 
 
 /**
- * Generate a template entry.
+ * Generate a webhook entry.
  *
  * @param rh context of the handler
  * @param connection the MHD connection to handle
@@ -36,7 +36,7 @@
  * @return MHD result code
  */
 MHD_RESULT
-TMH_private_post_templates (const struct TMH_RequestHandler *rh,
+TMH_private_post_webhooks (const struct TMH_RequestHandler *rh,
                            struct MHD_Connection *connection,
                            struct TMH_HandlerContext *hc);
 
diff --git a/src/backenddb/merchant-0001.sql b/src/backenddb/merchant-0001.sql
index a74306d1..cd4ae9f3 100644
--- a/src/backenddb/merchant-0001.sql
+++ b/src/backenddb/merchant-0001.sql
@@ -175,7 +175,7 @@ COMMENT ON COLUMN merchant_inventory.total_lost
 COMMENT ON COLUMN merchant_inventory.address
   IS 'JSON formatted Location of where the product is stocked';
 COMMENT ON COLUMN merchant_inventory.next_restock
-  IS 'GNUnet absolute time indicating when the next restock is expected. 0 for 
unknown.';
+  IS 'GNUnet absolute time i    ndicating when the next restock is expected. 0 
for unknown.';
 COMMENT ON COLUMN merchant_inventory.minimum_age
   IS 'Minimum age of the customer in years, to be used if an exchange supports 
the age restriction extension.';
 

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