diff options
Diffstat (limited to 'src/backend/taler-merchant-httpd_private-post-templates.c')
-rw-r--r-- | src/backend/taler-merchant-httpd_private-post-templates.c | 73 |
1 files changed, 72 insertions, 1 deletions
diff --git a/src/backend/taler-merchant-httpd_private-post-templates.c b/src/backend/taler-merchant-httpd_private-post-templates.c index a064769c..7aa72992 100644 --- a/src/backend/taler-merchant-httpd_private-post-templates.c +++ b/src/backend/taler-merchant-httpd_private-post-templates.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 @@ -47,6 +47,18 @@ templates_equal (const struct TALER_MERCHANTDB_TemplateDetails *t1, (NULL != t2->otp_id) && (0 == strcmp (t1->otp_id, t2->otp_id))) ) && + ( ( (NULL == t1->required_currency) && + (NULL == t2->required_currency) ) || + ( (NULL != t1->required_currency) && + (NULL != t2->required_currency) && + (0 == strcmp (t1->required_currency, + t2->required_currency))) ) && + ( ( (NULL == t1->editable_defaults) && + (NULL == t2->editable_defaults) ) || + ( (NULL != t1->editable_defaults) && + (NULL != t2->editable_defaults) && + (1 == json_equal (t1->editable_defaults, + t2->editable_defaults))) ) && (1 == json_equal (t1->template_contract, t2->template_contract)) ); } @@ -72,6 +84,14 @@ TMH_private_post_templates (const struct TMH_RequestHandler *rh, 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 () }; uint64_t otp_serial = 0; @@ -104,6 +124,57 @@ TMH_private_post_templates (const struct TMH_RequestHandler *rh, "template_contract"); } + 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, + "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; + } + } + } + if (NULL != tp.otp_id) { qs = TMH_db->select_otp_serial (TMH_db->cls, |