aboutsummaryrefslogtreecommitdiff
path: root/src/backend
diff options
context:
space:
mode:
authorpriscilla <priscilla.huang@efrei.net>2022-11-22 08:07:11 -0500
committerpriscilla <priscilla.huang@efrei.net>2022-11-22 08:14:50 -0500
commitc00762ce8297fbb4ea9590a0fb7e014adb9d8dcf (patch)
tree850a6e56ff658e0fd6c861219af73067eaca2e22 /src/backend
parentae6d2de1610ceb06e58b945a04a3d184b95d3e44 (diff)
template post, get, patch and delete
Diffstat (limited to 'src/backend')
-rw-r--r--src/backend/taler-merchant-httpd_helper.c44
-rw-r--r--src/backend/taler-merchant-httpd_helper.h12
-rw-r--r--src/backend/taler-merchant-httpd_private-post-templates.c6
3 files changed, 58 insertions, 4 deletions
diff --git a/src/backend/taler-merchant-httpd_helper.c b/src/backend/taler-merchant-httpd_helper.c
index 595b82cf..a5de1781 100644
--- a/src/backend/taler-merchant-httpd_helper.c
+++ b/src/backend/taler-merchant-httpd_helper.c
@@ -88,7 +88,6 @@ TMH_payto_uri_array_valid (const json_t *payto_uris)
return payto_ok;
}
-
bool
TMH_location_object_valid (const json_t *location)
{
@@ -316,6 +315,49 @@ TMH_image_data_url_valid (const char *image_data_url)
return true;
}
+bool
+TMH_template_contract_valid (const json_t *template_contract)
+{
+ const char *summary;
+ struct TALER_Amount amount = { .value = 0};
+ uint32_t minimum_age = 0;
+ struct GNUNET_TIME_Relative pay_duration= { 0 };
+ struct GNUNET_JSON_Specification spec[] = {
+ GNUNET_JSON_spec_mark_optional (
+ GNUNET_JSON_spec_string ("summary",
+ &summary),
+ NULL),
+ GNUNET_JSON_spec_mark_optional (
+ TALER_JSON_spec_amount ("amount",
+ TMH_currency,
+ &amount),
+ NULL),
+ GNUNET_JSON_spec_mark_optional (
+ GNUNET_JSON_spec_uint32 ("minimum_age",
+ &minimum_age),
+ NULL),
+ GNUNET_JSON_spec_mark_optional (
+ GNUNET_JSON_spec_relative_time ("pay_duration",
+ &pay_duration),
+ NULL),
+ GNUNET_JSON_spec_end ()
+ };
+ const char *ename;
+ unsigned int eline;
+
+ if (GNUNET_OK !=
+ GNUNET_JSON_parse (template_contract,
+ spec,
+ &ename,
+ &eline))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Invalid template_contract for field %s\n",
+ ename);
+ return false;
+ }
+ return true;
+}
bool
TMH_taxes_array_valid (const json_t *taxes)
diff --git a/src/backend/taler-merchant-httpd_helper.h b/src/backend/taler-merchant-httpd_helper.h
index 659bddc2..dae9caaf 100644
--- a/src/backend/taler-merchant-httpd_helper.h
+++ b/src/backend/taler-merchant-httpd_helper.h
@@ -88,6 +88,18 @@ TMH_image_data_url_valid (const char *image_data_url);
/**
+ * Check if @a template_contract is a valid template_contract object in the sense of Taler's API
+ * definition.
+ *
+ * @param template_contract object to check
+ * @return true if @a template_location is an object
+ * representing a template_location.
+ */
+bool
+TMH_template_contract_valid (const json_t *template_contract);
+
+
+/**
* Setup new wire method for the given @ payto_uri.
*
* @param payto_uri already validated payto URI
diff --git a/src/backend/taler-merchant-httpd_private-post-templates.c b/src/backend/taler-merchant-httpd_private-post-templates.c
index 1e6206bb..a2112486 100644
--- a/src/backend/taler-merchant-httpd_private-post-templates.c
+++ b/src/backend/taler-merchant-httpd_private-post-templates.c
@@ -46,11 +46,11 @@ templates_equal (const struct TALER_MERCHANTDB_TemplateDetails *t1,
const struct TALER_MERCHANTDB_TemplateDetails *t2)
{
return ( (0 == strcmp (t1->template_description,
- t2->tempate_description)) &&
+ t2->template_description)) &&
(0 == strcmp (t1->image,
t2->image)) &&
- (1 == json_equal (p1->template_contract,
- p2->template_contract));
+ (1 == json_equal (t1->template_contract,
+ t2->template_contract)));
}