gnunet-svn
[Top][All Lists]
Advanced

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

[taler-merchant] branch master updated (23e06d71 -> bca27225)


From: gnunet
Subject: [taler-merchant] branch master updated (23e06d71 -> bca27225)
Date: Thu, 15 Dec 2022 12:37:38 +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 23e06d71 testing webhooks
     new ed8954ef using templates
     new bca27225 using templates

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                            |  2 +
 .../taler-merchant-httpd_post-using-templates.c    | 98 ++++++++++++++++++++++
 ...=> taler-merchant-httpd_post-using-templates.h} | 23 +++--
 .../taler-merchant-httpd_private-post-templates.c  |  6 +-
 4 files changed, 112 insertions(+), 17 deletions(-)
 create mode 100644 src/backend/taler-merchant-httpd_post-using-templates.c
 copy src/backend/{taler-merchant-httpd_private-get-tips.h => 
taler-merchant-httpd_post-using-templates.h} (62%)

diff --git a/src/backend/Makefile.am b/src/backend/Makefile.am
index de283293..1fb445b3 100644
--- a/src/backend/Makefile.am
+++ b/src/backend/Makefile.am
@@ -120,6 +120,8 @@ taler_merchant_httpd_SOURCES = \
     taler-merchant-httpd_post-orders-ID-refund.h \
   taler-merchant-httpd_post-tips-ID-pickup.c \
     taler-merchant-httpd_post-tips-ID-pickup.h \
+  taler-merchant-httpd_post-using-templates.c \
+    taler-merchant-httpd_post-using-templates.h \
   taler-merchant-httpd_qr.c \
     taler-merchant-httpd_qr.h \
   taler-merchant-httpd_reserves.c \
diff --git a/src/backend/taler-merchant-httpd_post-using-templates.c 
b/src/backend/taler-merchant-httpd_post-using-templates.c
new file mode 100644
index 00000000..7e8a2a59
--- /dev/null
+++ b/src/backend/taler-merchant-httpd_post-using-templates.c
@@ -0,0 +1,98 @@
+/*
+  This file is part of TALER
+  (C) 2020 Taler Systems SA
+
+  TALER is free software; you can redistribute it and/or modify
+  it under the terms of the GNU Affero General Public License as
+  published by the Free Software Foundation; either version 3,
+  or (at your option) any later version.
+
+  TALER is distributed in the hope that it will be useful, but
+  WITHOUT ANY WARRANTY; without even the implied warranty of
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+  GNU General Public License for more details.
+
+  You should have received a copy of the GNU General Public
+  License along with TALER; see the file COPYING.  If not,
+  see <http://www.gnu.org/licenses/>
+*/
+
+/**
+ * @file taler-merchant-httpd_post-using-templates.c
+ * @brief implementing POST /using-templates request handling
+ * @author Priscilla HUANG
+ */
+#include "platform.h"
+#include "taler-merchant-httpd_post-using-templates.h"
+#include "taler-merchant-httpd_private-post-orders.h"
+#include "taler-merchant-httpd_helper.h"
+#include <taler/taler_json_lib.h>
+
+MHD_RESULT
+TMH_private_post_using_templates ( struct MHD_Connection *connection,
+                                   struct TMH_HandlerContext *hc)
+{
+  MHD_RESULT mret;
+  struct TALER_MERCHANTDB_TemplateDetails tp = { 0 };
+  const char *template_id = NULL;
+  const char *subject = NULL;
+  const char *taler_url = NULL;
+  struct TALER_Amount amount;
+
+  //template data + POST argument data to handler
+  json_t *fake_body = GNUNET_JSON_PACK (
+    GNUNET_JSON_pack_string ("template_id",
+                             template_id),
+    GNUNET_JSON_pack_string ("template_description",
+                              tp.template_description),
+    GNUNET_JSON_pack_string ("image",
+                             tp.image),
+    GNUNET_JSON_pack_object_incref ("template_contract",
+                                    tp.template_contract),
+    GNUNET_JSON_pack_allow_null (
+    TALER_JSON_pack_amount ("amount",
+                            &amount)),
+    GNUNET_JSON_pack_allow_null (
+    GNUNET_JSON_pack_string ("subject",
+                             subject)),
+    GNUNET_JSON_pack_string ("taler_url",
+                             taler_url)
+   );
+
+  //Verification that the variable have the right form
+  if (NULL == tp.template_contract)
+    tp.template_contract = json_object ();
+
+
+  if (! TMH_template_contract_valid (tp.template_contract))
+  {
+    GNUNET_break_op (0);
+    json_decref (fake_body);
+    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);
+    json_decref (fake_body);
+    return TALER_MHD_reply_with_error (connection,
+                                       MHD_HTTP_BAD_REQUEST,
+                                       TALER_EC_GENERIC_PARAMETER_MALFORMED,
+                                       "image");
+  }
+  struct TMH_HandlerContext fake_hc = {
+    .request_body = fake_body,
+    .instance = hc->instance
+  };
+  mret = TMH_private_post_orders (NULL, /* not even used */
+                                 connection,
+                                 &fake_hc);
+  json_decref (fake_body);
+  return mret;
+}
diff --git a/src/backend/taler-merchant-httpd_private-get-tips.h 
b/src/backend/taler-merchant-httpd_post-using-templates.h
similarity index 62%
copy from src/backend/taler-merchant-httpd_private-get-tips.h
copy to src/backend/taler-merchant-httpd_post-using-templates.h
index d1ce18f0..db9d48e3 100644
--- a/src/backend/taler-merchant-httpd_private-get-tips.h
+++ b/src/backend/taler-merchant-httpd_post-using-templates.h
@@ -1,6 +1,6 @@
 /*
   This file is part of TALER
-  (C) 2020 Taler Systems SA
+  (C) 2014, 2015, 2019 Taler Systems SA
 
   TALER is free software; you can redistribute it and/or modify it under the
   terms of the GNU General Public License as published by the Free Software
@@ -14,28 +14,25 @@
   TALER; see the file COPYING.  If not, see <http://www.gnu.org/licenses/>
 */
 /**
- * @file taler-merchant-httpd_private-get-tips.h
- * @brief headers for GET /private/tips handler
- * @author Jonathan Buchanan
+ * @file taler-merchant-httpd_post-using-templates.h
+ * @brief headers for POST /using-templates handler
+ * @author Priscilla Huang
  */
-#ifndef TALER_MERCHANT_HTTPD_PRIVATE_GET_TIPS_H
-#define TALER_MERCHANT_HTTPD_PRIVATE_GET_TIPS_H
-#include <microhttpd.h>
-#include "taler-merchant-httpd.h"
+#ifndef TALER_MERCHANT_HTTPD_POST_USING_TEMPLATES_H
+#define TALER_MERCHANT_HTTPD_POST_USING_TEMPLATES_H
 
+#include "taler-merchant-httpd.h"
 
 /**
- * Manages a GET /private/tips call.
+ * Generate a template that customer can use it. Returns an MHD_RESULT.
  *
- * @param rh context of the handler
  * @param connection the MHD connection to handle
  * @param[in,out] hc context with further information about the request
  * @return MHD result code
  */
 MHD_RESULT
-TMH_private_get_tips (const struct TMH_RequestHandler *rh,
-                      struct MHD_Connection *connection,
-                      struct TMH_HandlerContext *hc);
+TMH_private_post_using_templates (struct MHD_Connection *connection,
+                                  struct TMH_HandlerContext *hc);
 
 
 #endif
diff --git a/src/backend/taler-merchant-httpd_private-post-templates.c 
b/src/backend/taler-merchant-httpd_private-post-templates.c
index 55dd7954..38daf664 100644
--- a/src/backend/taler-merchant-httpd_private-post-templates.c
+++ b/src/backend/taler-merchant-httpd_private-post-templates.c
@@ -72,10 +72,8 @@ TMH_private_post_templates (const struct TMH_RequestHandler 
*rh,
       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_json ("template_contract",
+                           &tp.template_contract),
     GNUNET_JSON_spec_end ()
   };
 

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