commit 86323f313cb09a9665ecb035da8e9d560e7a5542
parent c35074bffd2fb38539deca64890fcece2f048e56
Author: Christian Grothoff <christian@grothoff.org>
Date: Mon, 19 Dec 2022 13:29:56 +0100
Merge branch 'master' of git+ssh://git.taler.net/merchant
Diffstat:
10 files changed, 232 insertions(+), 12 deletions(-)
diff --git 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
@@ -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
@@ -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-delete-templates-ID.c b/src/backend/taler-merchant-httpd_private-delete-templates-ID.c
@@ -58,7 +58,11 @@ TMH_private_delete_templates_ID (const struct TMH_RequestHandler *rh,
MHD_HTTP_INTERNAL_SERVER_ERROR,
TALER_EC_GENERIC_INTERNAL_INVARIANT_FAILURE,
"delete_template (soft)");
-
+ case GNUNET_DB_STATUS_SUCCESS_NO_RESULTS:
+ return TALER_MHD_reply_with_error (connection,
+ MHD_HTTP_NOT_FOUND,
+ TALER_EC_MERCHANT_GENERIC_TEMPLATE_UNKNOWN,
+ hc->infix);
case GNUNET_DB_STATUS_SUCCESS_ONE_RESULT:
return TALER_MHD_reply_static (connection,
MHD_HTTP_NO_CONTENT,
diff --git a/src/backend/taler-merchant-httpd_private-delete-webhooks-ID.c b/src/backend/taler-merchant-httpd_private-delete-webhooks-ID.c
@@ -58,7 +58,11 @@ TMH_private_delete_webhooks_ID (const struct TMH_RequestHandler *rh,
MHD_HTTP_INTERNAL_SERVER_ERROR,
TALER_EC_GENERIC_INTERNAL_INVARIANT_FAILURE,
"delete_webhook (soft)");
-
+ case GNUNET_DB_STATUS_SUCCESS_NO_RESULTS:
+ return TALER_MHD_reply_with_error (connection,
+ MHD_HTTP_NOT_FOUND,
+ TALER_EC_MERCHANT_GENERIC_WEBHOOK_UNKNOWN,
+ hc->infix);
case GNUNET_DB_STATUS_SUCCESS_ONE_RESULT:
return TALER_MHD_reply_static (connection,
MHD_HTTP_NO_CONTENT,
diff --git 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 ()
};
diff --git a/src/include/taler_merchant_service.h b/src/include/taler_merchant_service.h
@@ -4309,7 +4309,7 @@ TALER_MERCHANT_template_patch (
const char *template_id,
const char *template_description,
const char *image,
- const json_t *template_contract,
+ json_t *template_contract,
TALER_MERCHANT_TemplatePatchCallback cb,
void *cb_cls);
diff --git a/src/lib/merchant_api_patch_template.c b/src/lib/merchant_api_patch_template.c
@@ -162,7 +162,7 @@ TALER_MERCHANT_template_patch (
const char *template_id,
const char *template_description,
const char *image,
- const json_t *template_contract,
+ json_t *template_contract,
TALER_MERCHANT_TemplatePatchCallback cb,
void *cb_cls)
{
diff --git a/src/testing/test_kyc_api.c b/src/testing/test_kyc_api.c
@@ -6,7 +6,7 @@
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
diff --git a/src/testing/test_merchant_api.c b/src/testing/test_merchant_api.c
@@ -1335,7 +1335,7 @@ run (void *cls,
"data:image/jpeg;base64,RAWDATA",
json_pack ("{s:s}",
"summary",
- "EUR:1"),
+ "EUR"),
MHD_HTTP_NO_CONTENT),
TALER_TESTING_cmd_merchant_get_template ("get-template-t2",
merchant_url,
@@ -1350,11 +1350,11 @@ run (void *cls,
TALER_TESTING_cmd_merchant_patch_template ("patch-templates-t3-nx",
merchant_url,
"template-3",
- "nx updated template",
+ "updated template",
"data:image/jpeg;base64,RAWDATA",
json_pack ("{s:s}",
"summary",
- "EUR:1"),
+ "EUR"),
MHD_HTTP_NOT_FOUND),
TALER_TESTING_cmd_merchant_delete_template ("get-templates-empty",
merchant_url,
@@ -1367,6 +1367,80 @@ run (void *cls,
TALER_TESTING_cmd_end ()
};
+ struct TALER_TESTING_Command webhooks[] = {
+ TALER_TESTING_cmd_merchant_get_webhooks ("get-webhooks-empty",
+ merchant_url,
+ MHD_HTTP_OK,
+ NULL),
+ TALER_TESTING_cmd_merchant_post_webhooks ("post-webhooks-w1",
+ merchant_url,
+ "webhook-1",
+ "Paid",
+ MHD_HTTP_NO_CONTENT),
+ TALER_TESTING_cmd_merchant_post_webhooks ("post-webhooks-w1-idem",
+ merchant_url,
+ "webhook-1",
+ "Paid",
+ MHD_HTTP_NO_CONTENT),
+ TALER_TESTING_cmd_merchant_post_webhooks ("post-webhooks-w1-non-idem",
+ merchant_url,
+ "webhook-1",
+ "Refund",
+ MHD_HTTP_CONFLICT),
+ TALER_TESTING_cmd_merchant_get_webhooks ("get-webhooks-w1",
+ merchant_url,
+ MHD_HTTP_OK,
+ "post-webhooks-w1",
+ NULL),
+ TALER_TESTING_cmd_merchant_get_webhook ("get-webhook-w1",
+ merchant_url,
+ "webhook-1",
+ MHD_HTTP_OK,
+ "post-webhooks-w1"),
+ TALER_TESTING_cmd_merchant_post_webhooks ("post-webhooks-w2",
+ merchant_url,
+ "webhook-2",
+ "Paid",
+ MHD_HTTP_NO_CONTENT),
+ TALER_TESTING_cmd_merchant_patch_webhook ("patch-webhooks-w2",
+ merchant_url,
+ "webhook-2",
+ "Refund2",
+ "https://example.com",
+ "POST",
+ "Authorization:WHWOXZXPLL",
+ "Amount",
+ MHD_HTTP_NO_CONTENT),
+ TALER_TESTING_cmd_merchant_get_webhook ("get-webhook-w2",
+ merchant_url,
+ "webhook-2",
+ MHD_HTTP_OK,
+ "patch-webhooks-w2"),
+ TALER_TESTING_cmd_merchant_get_webhook ("get-webhook-nx",
+ merchant_url,
+ "webhook-nx",
+ MHD_HTTP_NOT_FOUND,
+ NULL),
+ TALER_TESTING_cmd_merchant_patch_webhook ("patch-webhooks-w3-nx",
+ merchant_url,
+ "webhook-3",
+ "Paid2",
+ "https://example.com",
+ "POST",
+ "Authorization:WHWOXZXPLL",
+ "Amount",
+ MHD_HTTP_NOT_FOUND),
+ TALER_TESTING_cmd_merchant_delete_webhook ("get-webhooks-empty",
+ merchant_url,
+ "w1",
+ MHD_HTTP_NOT_FOUND),
+ TALER_TESTING_cmd_merchant_delete_webhook ("get-webhooks-empty",
+ merchant_url,
+ "webhook-1",
+ MHD_HTTP_NO_CONTENT),
+ TALER_TESTING_cmd_end ()
+ };
+
struct TALER_TESTING_Command commands[] = {
/* general setup */
TALER_TESTING_cmd_auditor_add ("add-auditor-OK",
@@ -1719,6 +1793,8 @@ run (void *cls,
auth),
TALER_TESTING_cmd_batch ("templates",
templates),
+ TALER_TESTING_cmd_batch ("webhooks",
+ webhooks),
/**
* End the suite.
*/