diff options
author | Christian Grothoff <christian@grothoff.org> | 2020-04-24 01:23:35 +0200 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2020-04-24 01:23:35 +0200 |
commit | 0b57eac8f3b99941a11f11f35feac1926cd21d31 (patch) | |
tree | 1e3cb7efa7c60ab8f85e0797979adc7f23dda086 /src | |
parent | b378eea34812a9b561be6149e40c4518070f34f7 (diff) | |
download | merchant-0b57eac8f3b99941a11f11f35feac1926cd21d31.tar.gz merchant-0b57eac8f3b99941a11f11f35feac1926cd21d31.tar.bz2 merchant-0b57eac8f3b99941a11f11f35feac1926cd21d31.zip |
implement purge
Diffstat (limited to 'src')
-rw-r--r-- | src/include/taler_merchant_service.h | 2 | ||||
-rw-r--r-- | src/include/taler_merchant_testing_lib.h | 70 | ||||
-rw-r--r-- | src/lib/merchant_api_delete_instance.c | 84 | ||||
-rw-r--r-- | src/testing/Makefile.am | 1 | ||||
-rw-r--r-- | src/testing/testing_api_cmd_patch_instance.c | 8 | ||||
-rw-r--r-- | src/testing/testing_api_cmd_post_instances.c | 8 |
6 files changed, 155 insertions, 18 deletions
diff --git a/src/include/taler_merchant_service.h b/src/include/taler_merchant_service.h index a450c6e1..42ea1fa7 100644 --- a/src/include/taler_merchant_service.h +++ b/src/include/taler_merchant_service.h @@ -855,7 +855,7 @@ struct TALER_MERCHANT_ProductsPostHandle; typedef void (*TALER_MERCHANT_ProductsPostCallback)( void *cls, - struct TALER_MERCHANT_HttpResponse *hr); + const struct TALER_MERCHANT_HttpResponse *hr); /** diff --git a/src/include/taler_merchant_testing_lib.h b/src/include/taler_merchant_testing_lib.h index 2b2a9e8e..95f945c9 100644 --- a/src/include/taler_merchant_testing_lib.h +++ b/src/include/taler_merchant_testing_lib.h @@ -247,6 +247,76 @@ TALER_TESTING_cmd_merchant_delete_instance (const char *label, unsigned int http_status); +/* ******************* /products**************** */ + + +/** + * Define a "POST /products" CMD. + * + * @param label command label. + * @param merchant_url base URL of the merchant serving the + * POST /products request. + * @param instance_id instance to add a product to, + * NULL to query the default instance + * @param product_id the ID of the product to query + * @param description description of the product + * @param description_i18n Map from IETF BCP 47 language tags to localized descriptions + * @param unit unit in which the product is measured (liters, kilograms, packages, etc.) + * @param price the price for one @a unit of the product, zero is used to imply that + * this product is not sold separately or that the price is not fixed and + * must be supplied by the front-end. If non-zero, price must include + * applicable taxes. + * @param image base64-encoded product image + * @param taxes list of taxes paid by the merchant + * @param total_stocked in @a units, -1 to indicate "infinite" (i.e. electronic books) + * @param address where the product is in stock + * @param next_restock when the next restocking is expected to happen, 0 for unknown, + * #GNUNET_TIME_UNIT_FOREVER_ABS for 'never'. + * @param http_status expected HTTP response code. + * @return the command. + */ +struct TALER_TESTING_Command +TALER_TESTING_cmd_merchant_post_products2 ( + const char *label, + const char *merchant_url, + const char *product_id, + const char *instance_id, + const char *description, + json_t *description_i18n, + const char *unit, + const struct TALER_Amount *price, + json_t *image, + json_t *taxes, + int64_t total_stocked, + json_t *address, + struct GNUNET_TIME_Absolute next_restock, + unsigned int http_status); + + +/** + * Define a "POST /products" CMD, simple version + * + * @param label command label. + * @param merchant_url base URL of the merchant serving the + * POST /products request. + * @param instance_id instance to add a product to, + * NULL to query the default instance + * @param product_id the ID of the product to create + * @param description name of the product + * @param price price of the product + * @param http_status expected HTTP response code. + * @return the command. + */ +struct TALER_TESTING_Command +TALER_TESTING_cmd_merchant_post_products (const char *label, + const char *merchant_url, + const char *instance_id, + const char *product_id, + const char *description, + const char *price, + unsigned int http_status); + + /* ******************** OLD ******************* */ /** diff --git a/src/lib/merchant_api_delete_instance.c b/src/lib/merchant_api_delete_instance.c index 5d15e57d..01852c45 100644 --- a/src/lib/merchant_api_delete_instance.c +++ b/src/lib/merchant_api_delete_instance.c @@ -115,17 +115,19 @@ handle_delete_instance_finished (void *cls, * @param ctx the context * @param backend_url HTTP base URL for the backend * @param instance_id which instance should be deleted + * @param purge purge instead of just deleting * @param instances_cb function to call with the * backend's return * @param instances_cb_cls closure for @a config_cb * @return the instances handle; NULL upon error */ -struct TALER_MERCHANT_InstanceDeleteHandle * -TALER_MERCHANT_instance_delete (struct GNUNET_CURL_Context *ctx, - const char *backend_url, - const char *instance_id, - TALER_MERCHANT_InstanceDeleteCallback cb, - void *cb_cls) +static struct TALER_MERCHANT_InstanceDeleteHandle * +instance_delete (struct GNUNET_CURL_Context *ctx, + const char *backend_url, + const char *instance_id, + bool purge, + TALER_MERCHANT_InstanceDeleteCallback cb, + void *cb_cls) { struct TALER_MERCHANT_InstanceDeleteHandle *idh; @@ -139,9 +141,16 @@ TALER_MERCHANT_instance_delete (struct GNUNET_CURL_Context *ctx, GNUNET_asprintf (&path, "instances/%s", instance_id); - idh->url = TALER_url_join (backend_url, - path, - NULL); + if (purge) + idh->url = TALER_url_join (backend_url, + path, + "purge", + "yes", + NULL); + else + idh->url = TALER_url_join (backend_url, + path, + NULL); GNUNET_free (path); } if (NULL == idh->url) @@ -177,6 +186,63 @@ TALER_MERCHANT_instance_delete (struct GNUNET_CURL_Context *ctx, /** + * Delete the private key of an instance of a backend, thereby disabling the + * instance for future requests. Will preserve the other instance data + * (i.e. for taxation). + * + * @param ctx the context + * @param backend_url HTTP base URL for the backend + * @param instance_id which instance should be deleted + * @param instances_cb function to call with the + * backend's return + * @param instances_cb_cls closure for @a config_cb + * @return the instances handle; NULL upon error + */ +struct TALER_MERCHANT_InstanceDeleteHandle * +TALER_MERCHANT_instance_delete (struct GNUNET_CURL_Context *ctx, + const char *backend_url, + const char *instance_id, + TALER_MERCHANT_InstanceDeleteCallback cb, + void *cb_cls) +{ + return instance_delete (ctx, + backend_url, + instance_id, + false, + cb, + cb_cls); +} + + +/** + * Purge all data associated with an instance. Use with + * extreme caution. + * + * @param ctx the context + * @param backend_url HTTP base URL for the backend + * @param instance_id which instance should be deleted + * @param instances_cb function to call with the + * backend's return + * @param instances_cb_cls closure for @a config_cb + * @return the instances handle; NULL upon error + */ +struct TALER_MERCHANT_InstanceDeleteHandle * +TALER_MERCHANT_instance_purge (struct GNUNET_CURL_Context *ctx, + const char *backend_url, + const char *instance_id, + TALER_MERCHANT_InstanceDeleteCallback cb, + void *cb_cls) +{ + return instance_delete (ctx, + backend_url, + instance_id, + true, + cb, + cb_cls); +} + + +/** * Cancel DELETE /instance/$ID request. Must not be called by clients after * the callback was invoked. * diff --git a/src/testing/Makefile.am b/src/testing/Makefile.am index c09c3a83..3aecec65 100644 --- a/src/testing/Makefile.am +++ b/src/testing/Makefile.am @@ -19,6 +19,7 @@ libtalermerchanttesting_la_SOURCES = \ testing_api_cmd_get_instances.c \ testing_api_cmd_delete_instance.c \ testing_api_cmd_post_instances.c \ + testing_api_cmd_post_products.c \ testing_api_cmd_patch_instance.c \ \ testing_api_cmd_check_payment.c \ diff --git a/src/testing/testing_api_cmd_patch_instance.c b/src/testing/testing_api_cmd_patch_instance.c index 0044333e..0d589bb2 100644 --- a/src/testing/testing_api_cmd_patch_instance.c +++ b/src/testing/testing_api_cmd_patch_instance.c @@ -35,7 +35,7 @@ struct PatchInstanceState { /** - * Handle for a "GET instance" request. + * Handle for a "PATCH /instance/$ID" request. */ struct TALER_MERCHANT_InstancePatchHandle *iph; @@ -50,7 +50,7 @@ struct PatchInstanceState const char *merchant_url; /** - * ID of the instance to run GET for. + * ID of the instance to run PATCH for. */ const char *instance_id; @@ -183,7 +183,7 @@ patch_instance_run (void *cls, /** - * Free the state of a "GET instance" CMD, and possibly + * Free the state of a "PATCH /instances/$ID" CMD, and possibly * cancel a pending operation thereof. * * @param cls closure. @@ -198,7 +198,7 @@ patch_instance_cleanup (void *cls, if (NULL != pis->iph) { GNUNET_log (GNUNET_ERROR_TYPE_WARNING, - "GET /instance/$ID operation did not complete\n"); + "PATCH /instance/$ID operation did not complete\n"); TALER_MERCHANT_instance_patch_cancel (pis->iph); } json_decref (pis->address); diff --git a/src/testing/testing_api_cmd_post_instances.c b/src/testing/testing_api_cmd_post_instances.c index b50162b8..f9da2dae 100644 --- a/src/testing/testing_api_cmd_post_instances.c +++ b/src/testing/testing_api_cmd_post_instances.c @@ -35,7 +35,7 @@ struct PostInstancesState { /** - * Handle for a "GET instance" request. + * Handle for a "POST instance" request. */ struct TALER_MERCHANT_InstancesPostHandle *iph; @@ -50,7 +50,7 @@ struct PostInstancesState const char *merchant_url; /** - * ID of the instance to run GET for. + * ID of the instance to run POST for. */ const char *instance_id; @@ -183,7 +183,7 @@ post_instances_run (void *cls, /** - * Free the state of a "GET instance" CMD, and possibly + * Free the state of a "POST /instances" CMD, and possibly * cancel a pending operation thereof. * * @param cls closure. @@ -198,7 +198,7 @@ post_instances_cleanup (void *cls, if (NULL != pis->iph) { GNUNET_log (GNUNET_ERROR_TYPE_WARNING, - "GET /instances/$ID operation did not complete\n"); + "POST /instances operation did not complete\n"); TALER_MERCHANT_instances_post_cancel (pis->iph); } json_decref (pis->address); |