summaryrefslogtreecommitdiff
path: root/src/backend/taler-merchant-httpd_private-patch-templates-ID.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/backend/taler-merchant-httpd_private-patch-templates-ID.c')
-rw-r--r--src/backend/taler-merchant-httpd_private-patch-templates-ID.c85
1 files changed, 63 insertions, 22 deletions
diff --git a/src/backend/taler-merchant-httpd_private-patch-templates-ID.c b/src/backend/taler-merchant-httpd_private-patch-templates-ID.c
index 6cd060f0..e8a6c531 100644
--- a/src/backend/taler-merchant-httpd_private-patch-templates-ID.c
+++ b/src/backend/taler-merchant-httpd_private-patch-templates-ID.c
@@ -1,6 +1,6 @@
/*
This file is part of TALER
- (C) 2022 Taler Systems SA
+ (C) 2022, 2024 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
@@ -29,12 +29,6 @@
/**
- * How often do we retry the simple INSERT database transaction?
- */
-#define MAX_RETRIES 3
-
-
-/**
* Determine the cause of the PATCH failure in more detail and report.
*
* @param connection connection to report on
@@ -52,9 +46,9 @@ determine_cause (struct MHD_Connection *connection,
enum GNUNET_DB_QueryStatus qs;
qs = TMH_db->lookup_template (TMH_db->cls,
- instance_id,
- template_id,
- &tpx);
+ instance_id,
+ template_id,
+ &tpx);
switch (qs)
{
case GNUNET_DB_STATUS_HARD_ERROR:
@@ -102,8 +96,8 @@ determine_cause (struct MHD_Connection *connection,
*/
MHD_RESULT
TMH_private_patch_templates_ID (const struct TMH_RequestHandler *rh,
- struct MHD_Connection *connection,
- struct TMH_HandlerContext *hc)
+ struct MHD_Connection *connection,
+ struct TMH_HandlerContext *hc)
{
struct TMH_MerchantInstance *mi = hc->instance;
const char *template_id = hc->infix;
@@ -113,11 +107,19 @@ TMH_private_patch_templates_ID (const struct TMH_RequestHandler *rh,
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),
+ GNUNET_JSON_spec_string ("otp_id",
+ (const char **) &tp.otp_id),
NULL),
GNUNET_JSON_spec_json ("template_contract",
&tp.template_contract),
+ GNUNET_JSON_spec_mark_optional (
+ GNUNET_JSON_spec_string ("required_currency",
+ (const char **) &tp.required_currency),
+ NULL),
+ GNUNET_JSON_spec_mark_optional (
+ GNUNET_JSON_spec_json ("editable_defaults",
+ &tp.editable_defaults),
+ NULL),
GNUNET_JSON_spec_end ()
};
@@ -135,7 +137,7 @@ TMH_private_patch_templates_ID (const struct TMH_RequestHandler *rh,
: MHD_NO;
}
- if (! TMH_template_contract_valid (tp.template_contract))
+ if (! TMH_template_contract_valid (tp.template_contract))
{
GNUNET_break_op (0);
GNUNET_JSON_parse_free (spec);
@@ -144,22 +146,61 @@ TMH_private_patch_templates_ID (const struct TMH_RequestHandler *rh,
TALER_EC_GENERIC_PARAMETER_MALFORMED,
"template_contract");
}
-
-
- if (! TMH_image_data_url_valid (tp.image))
+ if ( (NULL != tp.required_currency) &&
+ (GNUNET_OK !=
+ TALER_check_currency (tp.required_currency)) )
+ {
+ 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,
+ "required_currency");
+ }
+ if ( (NULL != tp.required_currency) &&
+ (NULL != json_object_get (tp.template_contract,
+ "amount")) )
{
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");
+ "required_currency and contract::amount specified");
+ }
+ if (NULL != tp.editable_defaults)
+ {
+ const char *key;
+ json_t *val;
+
+ json_object_foreach (tp.editable_defaults, key, val)
+ {
+ if (NULL !=
+ json_object_get (tp.template_contract,
+ key))
+ {
+ char *msg;
+ MHD_RESULT ret;
+
+ GNUNET_break_op (0);
+ GNUNET_asprintf (&msg,
+ "editable_defaults::%s conflicts with template_contract",
+ key);
+ GNUNET_JSON_parse_free (spec);
+ ret = TALER_MHD_reply_with_error (connection,
+ MHD_HTTP_BAD_REQUEST,
+ TALER_EC_GENERIC_PARAMETER_MALFORMED,
+ msg);
+ GNUNET_free (msg);
+ return ret;
+ }
+ }
}
qs = TMH_db->update_template (TMH_db->cls,
- mi->settings.id,
- template_id,
- &tp);
+ mi->settings.id,
+ template_id,
+ &tp);
{
MHD_RESULT ret = MHD_NO;