merchant

Merchant backend to process payments, run by merchants
Log | Files | Refs | Submodules | README | LICENSE

commit 7dbc601c4f472111e1666be9cc55d397d1c446e6
parent c5988eed3e5fd33367e4a86d85c7fee8258d22b6
Author: Christian Grothoff <christian@grothoff.org>
Date:   Tue, 20 Apr 2021 15:48:20 +0200

be more generous in terms of which fields are required when creating/updating products

Diffstat:
Msrc/backend/taler-merchant-httpd_private-patch-products-ID.c | 40+++++++++++++++++++++++++++-------------
Msrc/backend/taler-merchant-httpd_private-post-products.c | 34+++++++++++++++++++++++-----------
2 files changed, 50 insertions(+), 24 deletions(-)

diff --git a/src/backend/taler-merchant-httpd_private-patch-products-ID.c b/src/backend/taler-merchant-httpd_private-patch-products-ID.c @@ -110,30 +110,36 @@ TMH_private_patch_products_ID (const struct TMH_RequestHandler *rh, { struct TMH_MerchantInstance *mi = hc->instance; const char *product_id = hc->infix; - struct TALER_MERCHANTDB_ProductDetails pd; + struct TALER_MERCHANTDB_ProductDetails pd = {0}; int64_t total_stock; enum GNUNET_DB_QueryStatus qs; struct GNUNET_JSON_Specification spec[] = { GNUNET_JSON_spec_string ("description", (const char **) &pd.description), - GNUNET_JSON_spec_json ("description_i18n", - &pd.description_i18n), + GNUNET_JSON_spec_mark_optional ( + GNUNET_JSON_spec_json ("description_i18n", + &pd.description_i18n)), GNUNET_JSON_spec_string ("unit", (const char **) &pd.unit), TALER_JSON_spec_amount ("price", &pd.price), - GNUNET_JSON_spec_string ("image", - (const char **) &pd.image), - GNUNET_JSON_spec_json ("taxes", - &pd.taxes), - GNUNET_JSON_spec_json ("address", - &pd.address), + GNUNET_JSON_spec_mark_optional ( + GNUNET_JSON_spec_string ("image", + (const char **) &pd.image)), + GNUNET_JSON_spec_mark_optional ( + GNUNET_JSON_spec_json ("taxes", + &pd.taxes)), + GNUNET_JSON_spec_mark_optional ( + GNUNET_JSON_spec_json ("address", + &pd.address)), GNUNET_JSON_spec_int64 ("total_stock", &total_stock), - GNUNET_JSON_spec_uint64 ("total_lost", - &pd.total_lost), - TALER_JSON_spec_absolute_time ("next_restock", - &pd.next_restock), + GNUNET_JSON_spec_mark_optional ( + GNUNET_JSON_spec_uint64 ("total_lost", + &pd.total_lost)), + GNUNET_JSON_spec_mark_optional ( + TALER_JSON_spec_absolute_time ("next_restock", + &pd.next_restock)), GNUNET_JSON_spec_end () }; @@ -166,6 +172,14 @@ TMH_private_patch_products_ID (const struct TMH_RequestHandler *rh, pd.total_stock = INT64_MAX; else pd.total_stock = (uint64_t) total_stock; + if (NULL == pd.address) + pd.address = json_object (); + if (NULL == pd.description_i18n) + pd.description_i18n = json_object (); + if (NULL == pd.taxes) + pd.taxes = json_object (); + if (NULL == pd.image) + pd.image = ""; if (NULL != json_object_get (hc->request_body, "next_restock")) { diff --git a/src/backend/taler-merchant-httpd_private-post-products.c b/src/backend/taler-merchant-httpd_private-post-products.c @@ -83,8 +83,9 @@ TMH_private_post_products (const struct TMH_RequestHandler *rh, &product_id), GNUNET_JSON_spec_string ("description", (const char **) &pd.description), - GNUNET_JSON_spec_json ("description_i18n", - &pd.description_i18n), + GNUNET_JSON_spec_mark_optional ( + GNUNET_JSON_spec_json ("description_i18n", + &pd.description_i18n)), GNUNET_JSON_spec_mark_optional ( TALER_JSON_spec_absolute_time ("next_restock", &pd.next_restock)), @@ -92,16 +93,20 @@ TMH_private_post_products (const struct TMH_RequestHandler *rh, (const char **) &pd.unit), TALER_JSON_spec_amount ("price", &pd.price), - GNUNET_JSON_spec_string ("image", - (const char **) &pd.image), - GNUNET_JSON_spec_json ("taxes", - &pd.taxes), - GNUNET_JSON_spec_json ("address", - &pd.address), + GNUNET_JSON_spec_mark_optional ( + GNUNET_JSON_spec_string ("image", + (const char **) &pd.image)), + GNUNET_JSON_spec_mark_optional ( + GNUNET_JSON_spec_json ("taxes", + &pd.taxes)), + GNUNET_JSON_spec_mark_optional ( + GNUNET_JSON_spec_json ("address", + &pd.address)), GNUNET_JSON_spec_int64 ("total_stock", &total_stock), - TALER_JSON_spec_absolute_time ("next_restock", - &pd.next_restock), + GNUNET_JSON_spec_mark_optional ( + TALER_JSON_spec_absolute_time ("next_restock", + &pd.next_restock)), GNUNET_JSON_spec_end () }; @@ -136,7 +141,14 @@ TMH_private_post_products (const struct TMH_RequestHandler *rh, else pd.total_stock = (uint64_t) total_stock; - + if (NULL == pd.address) + pd.address = json_object (); + if (NULL == pd.description_i18n) + pd.description_i18n = json_object (); + if (NULL == pd.taxes) + pd.taxes = json_object (); + if (NULL == pd.image) + pd.image = ""; for (unsigned int i = 0; i<MAX_RETRIES; i++) { /* Test if an product of this id is known */