aboutsummaryrefslogtreecommitdiff
path: root/src/backend
diff options
context:
space:
mode:
authorpriscilla <priscilla.huang@efrei.net>2022-12-15 06:34:54 -0500
committerpriscilla <priscilla.huang@efrei.net>2022-12-15 06:34:54 -0500
commited8954ef866ee460cfc4f3146d721c13fb250db1 (patch)
tree27fdcb4be21b24fd647a85d4d114897ad81854f7 /src/backend
parent23e06d71884b593cc7e379cafece085be1680d53 (diff)
using templates
Diffstat (limited to 'src/backend')
-rw-r--r--src/backend/#taler-merchant-httpd_post-using-templates.c#98
l---------src/backend/.#taler-merchant-httpd_post-using-templates.c1
-rw-r--r--src/backend/Makefile.am2
-rw-r--r--src/backend/taler-merchant-httpd_post-using-templates.c98
-rw-r--r--src/backend/taler-merchant-httpd_post-using-templates.h38
-rw-r--r--src/backend/taler-merchant-httpd_private-post-templates.c6
6 files changed, 239 insertions, 4 deletions
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_post-using-templates.c b/src/backend/.#taler-merchant-httpd_post-using-templates.c
new file mode 120000
index 00000000..b6990f46
--- /dev/null
+++ b/src/backend/.#taler-merchant-httpd_post-using-templates.c
@@ -0,0 +1 @@
+priscilla@dhcp-147-87-107-42.1292:1671094327 \ No newline at end of file
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..e36dc646
--- /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_post-using-templates.h b/src/backend/taler-merchant-httpd_post-using-templates.h
new file mode 100644
index 00000000..db9d48e3
--- /dev/null
+++ b/src/backend/taler-merchant-httpd_post-using-templates.h
@@ -0,0 +1,38 @@
+/*
+ This file is part of TALER
+ (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
+ 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.h
+ * @brief headers for POST /using-templates handler
+ * @author Priscilla Huang
+ */
+#ifndef TALER_MERCHANT_HTTPD_POST_USING_TEMPLATES_H
+#define TALER_MERCHANT_HTTPD_POST_USING_TEMPLATES_H
+
+#include "taler-merchant-httpd.h"
+
+/**
+ * Generate a template that customer can use it. Returns an MHD_RESULT.
+ *
+ * @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_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 ()
};