gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[taler-merchant] 22/277: work on /products and /instances C API


From: gnunet
Subject: [taler-merchant] 22/277: work on /products and /instances C API
Date: Sun, 05 Jul 2020 20:48:55 +0200

This is an automated email from the git hooks/post-receive script.

grothoff pushed a commit to branch master
in repository merchant.

commit 4913f563537f78215b7512fad7f41ef971bc3e97
Author: Christian Grothoff <christian@grothoff.org>
AuthorDate: Mon Apr 20 22:15:25 2020 +0200

    work on /products and /instances C API
---
 .../taler-merchant-httpd_private-get-products.c    |  14 +-
 ...aler-merchant-httpd_private-patch-products-ID.c |   1 +
 src/backenddb/merchant-0001.sql                    |   6 +-
 src/backenddb/plugin_merchantdb_postgres.c         |  32 +-
 src/include/taler_merchant_service.h               | 437 ++++++++++++++++++++-
 src/include/taler_merchantdb_plugin.h              |  17 +-
 src/lib/merchant_api_delete_instances_ID.c         |  66 ++--
 7 files changed, 486 insertions(+), 87 deletions(-)

diff --git a/src/backend/taler-merchant-httpd_private-get-products.c 
b/src/backend/taler-merchant-httpd_private-get-products.c
index 21729a5..00b0463 100644
--- a/src/backend/taler-merchant-httpd_private-get-products.c
+++ b/src/backend/taler-merchant-httpd_private-get-products.c
@@ -27,14 +27,10 @@
  *
  * @param cls a `json_t *` JSON array to build
  * @param product_id ID of the product
- * @param in_stock how many are currently in stock (possibly locked), -1 for 
infinite
- * @param unit in which unit is the stock measured in
  */
 static void
 add_product (void *cls,
-             const char *product_id,
-             long long in_stock,
-             const char *unit)
+             const char *product_id)
 {
   json_t *pa = cls;
 
@@ -42,13 +38,9 @@ add_product (void *cls,
                  json_array_append_new (
                    pa,
                    json_pack (
-                     "{s:s, s:I, s:s}",
+                     "{s:s}",
                      "product_id",
-                     product_id,
-                     "stock",
-                     (json_int_t) in_stock,
-                     "unit",
-                     unit)));
+                     product_id)));
 }
 
 
diff --git a/src/backend/taler-merchant-httpd_private-patch-products-ID.c 
b/src/backend/taler-merchant-httpd_private-patch-products-ID.c
index 6821d3d..6ffc73f 100644
--- a/src/backend/taler-merchant-httpd_private-patch-products-ID.c
+++ b/src/backend/taler-merchant-httpd_private-patch-products-ID.c
@@ -150,6 +150,7 @@ TMH_private_patch_products_ID (const struct 
TMH_RequestHandler *rh,
     GNUNET_JSON_spec_end ()
   };
 
+  pd.total_sold = 0; /* will be ignored anyway */
   GNUNET_assert (NULL != mi);
   GNUNET_assert (NULL != product_id);
   {
diff --git a/src/backenddb/merchant-0001.sql b/src/backenddb/merchant-0001.sql
index ad39e79..2c867b3 100644
--- a/src/backenddb/merchant-0001.sql
+++ b/src/backenddb/merchant-0001.sql
@@ -154,7 +154,7 @@ COMMENT ON COLUMN merchant_inventory.total_stock
 COMMENT ON COLUMN merchant_inventory.total_sold
   IS 'Number of products sold, must be below total_stock, non-negative, may 
never be lowered';
 COMMENT ON COLUMN merchant_inventory.total_lost
-  IS 'Number of products that used to be in stock but were lost (spoiled, 
damaged), may never be lowered';
+  IS 'Number of products that used to be in stock but were lost (spoiled, 
damaged), may never be lowered; total_stock >= total_sold + total_lost must 
always hold';
 COMMENT ON COLUMN merchant_inventory.address
   IS 'JSON formatted Location of where the product is stocked';
 COMMENT ON COLUMN merchant_inventory.next_restock
@@ -174,7 +174,7 @@ CREATE INDEX IF NOT EXISTS 
merchant_inventory_locks_by_expiration
   ON merchant_inventory_locks
     (expiration);
 COMMENT ON TABLE merchant_inventory_locks
-  IS 'locks on inventory helt by shopping carts';
+  IS 'locks on inventory helt by shopping carts; note that locks MAY not be 
honored if merchants increase total_lost for inventory';
 COMMENT ON COLUMN merchant_inventory_locks.total_locked
   IS 'how many units of the product does this lock reserve';
 COMMENT ON COLUMN merchant_inventory_locks.expiration
@@ -215,7 +215,7 @@ CREATE INDEX IF NOT EXISTS 
merchant_orders_locks_by_order_and_product
   ON merchant_order_locks
     (order_serial, product_serial);
 COMMENT ON TABLE merchant_order_locks
-  IS 'locks on orders awaiting claim and payment';
+  IS 'locks on orders awaiting claim and payment; note that locks MAY not be 
honored if merchants increase total_lost for inventory';
 COMMENT ON COLUMN merchant_order_locks.total_locked
   IS 'how many units of the product does this lock reserve';
 
diff --git a/src/backenddb/plugin_merchantdb_postgres.c 
b/src/backenddb/plugin_merchantdb_postgres.c
index e23649d..b654b44 100644
--- a/src/backenddb/plugin_merchantdb_postgres.c
+++ b/src/backenddb/plugin_merchantdb_postgres.c
@@ -755,15 +755,9 @@ lookup_products_cb (void *cls,
   for (unsigned int i = 0; i < num_results; i++)
   {
     char *product_id;
-    uint64_t in_stock;
-    char *unit;
     struct GNUNET_PQ_ResultSpec rs[] = {
       GNUNET_PQ_result_spec_string ("product_id",
                                     &product_id),
-      GNUNET_PQ_result_spec_uint64 ("total_stock",
-                                    &in_stock),
-      GNUNET_PQ_result_spec_string ("unit",
-                                    &unit),
       GNUNET_PQ_result_spec_end
     };
 
@@ -777,9 +771,7 @@ lookup_products_cb (void *cls,
       return;
     }
     plc->cb (plc->cb_cls,
-             product_id,
-             (UINT64_MAX == in_stock) ? -1LL : (long long) in_stock,
-             unit);
+             product_id);
     GNUNET_PQ_cleanup_result (rs);
   }
 }
@@ -963,6 +955,10 @@ postgres_insert_product (void *cls,
  * @param product_id product to lookup
  * @param[out] pd set to the product details on success, can be NULL
  *             (in that case we only want to check if the product exists)
+ *             total_sold in @a pd is ignored, total_lost must not
+ *             exceed total_stock minus the existing total_sold;
+ *             total_sold and total_stock must be larger or equal to
+ *             the existing value;
  * @return database result code, #GNUNET_DB_SUCCESS_NO_RESULTS if the
  *         non-decreasing constraints are not met *or* if the product
  *         does not yet exist.
@@ -971,7 +967,7 @@ static enum GNUNET_DB_QueryStatus
 postgres_update_product (void *cls,
                          const char *instance_id,
                          const char *product_id,
-                         struct TALER_MERCHANTDB_ProductDetails *pd)
+                         const struct TALER_MERCHANTDB_ProductDetails *pd)
 {
   struct PostgresClosure *pg = cls;
   struct GNUNET_PQ_QueryParam params[] = {
@@ -984,7 +980,6 @@ postgres_update_product (void *cls,
     TALER_PQ_query_param_json (pd->taxes),
     TALER_PQ_query_param_amount (&pd->price),
     GNUNET_PQ_query_param_uint64 (&pd->total_stocked),
-    GNUNET_PQ_query_param_uint64 (&pd->total_sold),
     GNUNET_PQ_query_param_uint64 (&pd->total_lost),
     TALER_PQ_query_param_json (pd->address),
     GNUNET_PQ_query_param_absolute_time (&pd->next_restock),
@@ -4022,8 +4017,6 @@ libtaler_plugin_merchantdb_postgres_init (void *cls)
     GNUNET_PQ_make_prepare ("lookup_products",
                             "SELECT"
                             " product_id"
-                            ",total_stock"
-                            ",unit"
                             " FROM merchant_inventory"
                             " JOIN merchant_instances"
                             "   USING (merchant_serial)"
@@ -4097,19 +4090,18 @@ libtaler_plugin_merchantdb_postgres_init (void *cls)
                             ",price_val=$8"
                             ",price_frac=$9"
                             ",total_stock=$10"
-                            ",total_sold=$11"
-                            ",total_lost=$12"
-                            ",address=$13"
-                            ",next_restock=$14"
+                            ",total_lost=$11"
+                            ",address=$12"
+                            ",next_restock=$13"
                             " WHERE merchant_serial="
                             "   (SELECT merchant_serial"
                             "      FROM merchant_instances"
                             "      WHERE merchant_id=$1)"
                             "   AND product_id=$2"
                             "   AND total_stock <= $10"
-                            "   AND total_sold <= $11"
-                            "   AND total_lost <= $12",
-                            14),
+                            "   AND $10 - total_sold >= $11"
+                            "   AND total_lost <= $11",
+                            13),
 
     /* for postgres_lock_product() */
     GNUNET_PQ_make_prepare ("lock_product",
diff --git a/src/include/taler_merchant_service.h 
b/src/include/taler_merchant_service.h
index c33c719..271e4c5 100644
--- a/src/include/taler_merchant_service.h
+++ b/src/include/taler_merchant_service.h
@@ -336,7 +336,7 @@ TALER_MERCHANT_instances_get_cancel (
 /**
  * Handle for a DELETE /instances operation.
  */
-struct TALER_MERCHANT_InstancesDeleteHandle;
+struct TALER_MERCHANT_InstanceDeleteHandle;
 
 
 /**
@@ -346,7 +346,7 @@ struct TALER_MERCHANT_InstancesDeleteHandle;
  * @param hr HTTP response data
  */
 typedef void
-(*TALER_MERCHANT_InstancesDeleteCallback)(
+(*TALER_MERCHANT_InstanceDeleteCallback)(
   void *cls,
   const struct TALER_MERCHANT_HttpResponse *hr);
 
@@ -364,12 +364,12 @@ typedef void
  * @param instances_cb_cls closure for @a config_cb
  * @return the instances handle; NULL upon error
  */
-struct TALER_MERCHANT_InstancesDeleteHandle *
-TALER_MERCHANT_instances_delete_instance (
+struct TALER_MERCHANT_InstanceDeleteHandle *
+TALER_MERCHANT_instance_delete (
   struct GNUNET_CURL_Context *ctx,
   const char *backend_url,
   const char *instance_id,
-  TALER_MERCHANT_InstancesDeleteCallback instances_cb,
+  TALER_MERCHANT_InstanceDeleteCallback instances_cb,
   void *instances_cb_cls);
 
 
@@ -385,12 +385,12 @@ TALER_MERCHANT_instances_delete_instance (
  * @param instances_cb_cls closure for @a config_cb
  * @return the instances handle; NULL upon error
  */
-struct TALER_MERCHANT_InstancesDeleteHandle *
-TALER_MERCHANT_instances_purge_instance (
+struct TALER_MERCHANT_InstanceDeleteHandle *
+TALER_MERCHANT_instance_purge (
   struct GNUNET_CURL_Context *ctx,
   const char *backend_url,
   const char *instance_id,
-  TALER_MERCHANT_InstancesDeleteCallback instances_cb,
+  TALER_MERCHANT_InstanceDeleteCallback instances_cb,
   void *instances_cb_cls);
 
 
@@ -401,8 +401,8 @@ TALER_MERCHANT_instances_purge_instance (
  * @param idh request to cancel.
  */
 void
-TALER_MERCHANT_instances_delete_cancel (
-  struct TALER_MERCHANT_InstancesDeleteHandle *idh);
+TALER_MERCHANT_instance_delete_cancel (
+  struct TALER_MERCHANT_InstanceDeleteHandle *idh);
 
 
 /**
@@ -411,8 +411,421 @@ TALER_MERCHANT_instances_delete_cancel (
  *
  * @param arg request to cancel.
  */
-#define TALER_MERCHANT_instances_purge_cancel(arg) \
-  TALER_MERCHANT_instances_delete_cancel (arg)
+#define TALER_MERCHANT_instance_purge_cancel(arg) \
+  TALER_MERCHANT_instance_delete_cancel (arg)
+
+
+/* ********************* /products *********************** */
+
+
+/**
+ * Handle for a GET /products operation.
+ */
+struct TALER_MERCHANT_ProductsGetHandle;
+
+/**
+ * Individual product from the inventory (minimal information
+ * returned via GET /products).
+ */
+struct TALER_MERCHANT_InventoryEntry
+{
+  /**
+   * Product identifier.
+   */
+  const char *product_id;
+
+};
+
+
+/**
+ * Function called with the result of the GET /products operation.
+ *
+ * @param cls closure
+ * @param hr HTTP response details
+ * @param products_length length of the @a products array
+ * @param products array of products the requested instance offers
+ */
+typedef void
+(*TALER_MERCHANT_ProductsGetCallback)(
+  void *cls,
+  struct TALER_MERCHANT_HttpResponse *hr,
+  unsigned int products_length,
+  const struct TALER_MERCHANT_InventoryEntry products[]);
+
+
+/**
+ * Make a GET /products request.
+ *
+ * @param ctx the context
+ * @param backend_url HTTP base URL for the backend
+ * @param instance_id instance to query about its products,
+ *                    NULL to query the default instance
+ * @param cb function to call with the backend's inventory information
+ * @param cb_cls closure for @a cb
+ * @return the request handle; NULL upon error
+ */
+struct TALER_MERCHANT_ProductsGetHandle *
+TALER_MERCHANT_products_get (
+  struct GNUNET_CURL_Context *ctx,
+  const char *backend_url,
+  const char *instance_id,
+  TALER_MERCHANT_ProductsGetCallback cb,
+  void *cb_cls);
+
+
+/**
+ * Cancel GET /products operation.
+ *
+ * @param pgh operation to cancel
+ */
+void
+TALER_MERCHANT_products_get_cancel (
+  struct TALER_MERCHANT_ProductsGetHandle *pgh);
+
+
+/**
+ * Handle for a GET /product/$ID operation. Gets details
+ * about a single product. Do not confused with a
+ * `struct TALER_MERCHANT_ProductsGetHandle`, which
+ * obtains a list of all products.
+ */
+struct TALER_MERCHANT_ProductGetHandle;
+
+
+/**
+ * Function called with the result of the GET /products operation.
+ *
+ * @param cls closure
+ * @param hr HTTP response details
+ * @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),
+ *                does NOT indicate remaining stocks, to get remaining stocks,
+ *                subtract @a total_sold and @a total_lost. Note that this 
still
+ *                does not then say how many of the remaining inventory are 
locked.
+ * @param total_sold in @a units, total number of @a unit of product sold
+ * @param total_lost in @a units, total number of @a unit of product lost from 
inventory
+ * @param location 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'.
+ */
+typedef void
+(*TALER_MERCHANT_ProductGetCallback)(
+  void *cls,
+  struct TALER_MERCHANT_HttpResponse *hr,
+  const char *description,
+  const json_t *description_i18n,
+  const char *unit,
+  const struct TALER_Amount *price,
+  const json_t *image,
+  const json_t *taxes,
+  int64_t total_stocked,
+  uint64_t total_sold,
+  uint64_t total_lost,
+  const json_t *location,
+  struct GNUNET_TIME_Absolute next_restock);
+
+
+/**
+ * Make a GET /product/$ID request to get details about an
+ * individual product.
+ *
+ * @param ctx the context
+ * @param backend_url HTTP base URL for the backend
+ * @param instance_id instance to query about its products,
+ *                    NULL to query the default instance
+ * @param product_id identifier of the product to inquire about
+ * @param cb function to call with the backend's product information
+ * @param cb_cls closure for @a cb
+ * @return the request handle; NULL upon error
+ */
+struct TALER_MERCHANT_ProductGetHandle *
+TALER_MERCHANT_product_get (
+  struct GNUNET_CURL_Context *ctx,
+  const char *backend_url,
+  const char *instance_id,
+  const char *product_id,
+  TALER_MERCHANT_ProductGetCallback cb,
+  void *cb_cls);
+
+
+/**
+ * Cancel GET /products/$ID operation.
+ *
+ * @param pgh operation to cancel
+ */
+void
+TALER_MERCHANT_product_get_cancel (
+  struct TALER_MERCHANT_ProductGetHandle *pgh);
+
+
+/**
+ * Handle for a POST /products operation.
+ */
+struct TALER_MERCHANT_ProductsPostHandle;
+
+
+/**
+ * Function called with the result of the POST /products operation.
+ *
+ * @param cls closure
+ * @param hr HTTP response details
+ */
+typedef void
+(*TALER_MERCHANT_ProductsPostCallback)(
+  void *cls,
+  struct TALER_MERCHANT_HttpResponse *hr);
+
+
+/**
+ * Make a POST /products request to add a product to the
+ * inventory.
+ *
+ * @param ctx the context
+ * @param backend_url HTTP base URL for the backend
+ * @param instance_id instance to add a product to,
+ *                    NULL to query the default instance
+ * @param product_id identifier to use for the product
+ * @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 location 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 cb function to call with the backend's result
+ * @param cb_cls closure for @a cb
+ * @return the request handle; NULL upon error
+ */
+struct TALER_MERCHANT_ProductsPostHandle *
+TALER_MERCHANT_products_post (
+  struct GNUNET_CURL_Context *ctx,
+  const char *backend_url,
+  const char *instance_id,
+  const char *product_id,
+  const char *description,
+  const json_t *description_i18n,
+  const char *unit,
+  const struct TALER_Amount *price,
+  const json_t *image,
+  const json_t *taxes,
+  int64_t total_stocked,
+  const json_t *location,
+  struct GNUNET_TIME_Absolute next_restock,
+  TALER_MERCHANT_ProductsPostCallback cb,
+  void *cb_cls);
+
+
+/**
+ * Cancel POST /products operation.
+ *
+ * @param pph operation to cancel
+ */
+void
+TALER_MERCHANT_products_post_cancel (
+  struct TALER_MERCHANT_ProductsPostHandle *pph);
+
+
+/**
+ * Handle for a PATCH /products operation.
+ */
+struct TALER_MERCHANT_ProductPatchHandle;
+
+
+/**
+ * Function called with the result of the PATCH /products operation.
+ *
+ * @param cls closure
+ * @param hr HTTP response details
+ */
+typedef void
+(*TALER_MERCHANT_ProductPatchCallback)(
+  void *cls,
+  struct TALER_MERCHANT_HttpResponse *hr);
+
+
+/**
+ * Make a PATCH /products request to update product details in the
+ * inventory.
+ *
+ * @param ctx the context
+ * @param backend_url HTTP base URL for the backend
+ * @param instance_id instance to add a product to,
+ *                    NULL to query the default instance
+ * @param product_id identifier to use for the product; the product must exist,
+ *                    or the transaction will fail with a #MHD_HTTP_NOT_FOUND
+ *                    HTTP status code
+ * @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),
+ *               must be larger than previous values
+ * @param total_lost in @a units, must be larger than previous values, and may
+ *               not exceed total_stocked minus total_sold; if it does, the 
transaction
+ *               will fail with a #MHD_HTTP_CONFLICT HTTP status code
+ * @param location where the product is in stock
+ * @param next_restock when the next restocking is expected to happen
+ * @param cb function to call with the backend's result
+ * @param cb_cls closure for @a cb
+ * @return the request handle; NULL upon error
+ */
+struct TALER_MERCHANT_ProductPatchHandle *
+TALER_MERCHANT_product_patch (
+  struct GNUNET_CURL_Context *ctx,
+  const char *backend_url,
+  const char *instance_id,
+  const char *product_id,
+  const char *description,
+  const json_t *description_i18n,
+  const char *unit,
+  const struct TALER_Amount *price,
+  const json_t *image,
+  const json_t *taxes,
+  int64_t total_stocked,
+  uint64_t total_lost,
+  const json_t *location,
+  struct GNUNET_TIME_Absolute next_restock,
+  TALER_MERCHANT_ProductPatchCallback cb,
+  void *cb_cls);
+
+
+/**
+ * Cancel PATCH /products operation.
+ *
+ * @param pph operation to cancel
+ */
+void
+TALER_MERCHANT_product_patch_cancel (
+  struct TALER_MERCHANT_ProductPatchHandle *pph);
+
+
+/**
+ * Handle for a POST /products/$ID/lock operation.
+ */
+struct TALER_MERCHANT_ProductLockHandle;
+
+
+/**
+ * Function called with the result of the POST /product/$ID/lock operation.
+ *
+ * @param cls closure
+ * @param hr HTTP response details
+ */
+typedef void
+(*TALER_MERCHANT_ProductLockCallback)(
+  void *cls,
+  struct TALER_MERCHANT_HttpResponse *hr);
+
+
+/**
+ * Make a POST /products/$ID/lock request to reserve a certain
+ * amount of product in inventory to a reservation UUID.
+ *
+ * @param ctx the context
+ * @param backend_url HTTP base URL for the backend
+ * @param instance_id instance to query about its products,
+ *                    NULL to query the default instance
+ * @param product_id identifier of the product
+ * @param uuid UUID that identifies the client holding the lock
+ * @param duration how long should the lock be held
+ * @param quantity how much product should be locked
+ * @param cb function to call with the backend's lock status
+ * @param cb_cls closure for @a cb
+ * @return the request handle; NULL upon error
+ */
+struct TALER_MERCHANT_ProductLockHandle *
+TALER_MERCHANT_product_lock (
+  struct GNUNET_CURL_Context *ctx,
+  const char *backend_url,
+  const char *instance_id,
+  const char *product_id,
+  struct GNUNET_TIME_Relative duration,
+  uint32_t quantity,
+  TALER_MERCHANT_ProductLockCallback cb,
+  void *cb_cls);
+
+
+/**
+ * Cancel POST /products/$ID/lock operation. Note that the
+ * lock may or may not be acquired despite the cancellation.
+ *
+ * @param pdh operation to cancel
+ */
+void
+TALER_MERCHANT_product_lock_cancel (
+  struct TALER_MERCHANT_ProductLockHandle *plh);
+
+
+/**
+ * Handle for a DELETE /products/$ID operation.
+ */
+struct TALER_MERCHANT_ProductDeleteHandle;
+
+
+/**
+ * Function called with the result of the DELETE /product/$ID operation.
+ *
+ * @param cls closure
+ * @param hr HTTP response details
+ */
+typedef void
+(*TALER_MERCHANT_ProductDeleteCallback)(
+  void *cls,
+  struct TALER_MERCHANT_HttpResponse *hr);
+
+
+/**
+ * Make a DELETE /products/$ID request to delete a product from our
+ * inventory.
+ *
+ * @param ctx the context
+ * @param backend_url HTTP base URL for the backend
+ * @param instance_id instance to query about its products,
+ *                    NULL to query the default instance
+ * @param product_id identifier of the product
+ * @param cb function to call with the backend's deletion status
+ * @param cb_cls closure for @a cb
+ * @return the request handle; NULL upon error
+ */
+struct TALER_MERCHANT_ProductDeleteHandle *
+TALER_MERCHANT_product_delete (
+  struct GNUNET_CURL_Context *ctx,
+  const char *backend_url,
+  const char *instance_id,
+  TALER_MERCHANT_ProductDeleteCallback cb,
+  void *cb_cls);
+
+
+/**
+ * Cancel DELETE /products/$ID operation.
+ *
+ * @param pdh operation to cancel
+ */
+void
+TALER_MERCHANT_product_delete_cancel (
+  struct TALER_MERCHANT_ProductDeleteHandle *pdh);
+
+
+/* *********************   OLD ************************** */
 
 
 /* ********************* /refund ************************** */
diff --git a/src/include/taler_merchantdb_plugin.h 
b/src/include/taler_merchantdb_plugin.h
index 09bb137..2a452fb 100644
--- a/src/include/taler_merchantdb_plugin.h
+++ b/src/include/taler_merchantdb_plugin.h
@@ -145,14 +145,10 @@ typedef void
  *
  * @param cls a `json_t *` JSON array to build
  * @param product_id ID of the product
- * @param in_stock how many are currently in stock (possibly locked), -1 for 
infinite
- * @param unit in which unit is the stock measured in
  */
 typedef void
 (*TALER_MERCHANTDB_ProductsCallback)(void *cls,
-                                     const char *product_id,
-                                     long long in_stock,
-                                     const char *unit);
+                                     const char *product_id);
 
 
 /**
@@ -238,6 +234,7 @@ typedef void
                                          uint64_t row_id,
                                          const json_t *contract_terms);
 
+
 /**
  * Function called with information about a transaction.
  *
@@ -578,8 +575,12 @@ struct TALER_MERCHANTDB_Plugin
    * @param cls closure
    * @param instance_id instance to lookup products for
    * @param product_id product to lookup
-   * @param[out] pd set to the product details on success, can be NULL
-   *             (in that case we only want to check if the product exists)
+   * @param pd set to the product details on success, can be NULL
+   *             (in that case we only want to check if the product exists);
+   *             total_sold in @a pd is ignored, total_lost must not
+   *             exceed total_stock minus the existing total_sold;
+   *             total_sold and total_stock must be larger or equal to
+   *             the existing value;
    * @return database result code, #GNUNET_DB_SUCCESS_NO_RESULTS if the
    *         non-decreasing constraints are not met *or* if the product
    *         does not yet exist.
@@ -588,7 +589,7 @@ struct TALER_MERCHANTDB_Plugin
   (*update_product)(void *cls,
                     const char *instance_id,
                     const char *product_id,
-                    struct TALER_MERCHANTDB_ProductDetails *pd);
+                    const struct TALER_MERCHANTDB_ProductDetails *pd);
 
   /**
    * Lock stocks of a particular product. Note that the transaction must
diff --git a/src/lib/merchant_api_delete_instances_ID.c 
b/src/lib/merchant_api_delete_instances_ID.c
index 46405bb..0eeb50b 100644
--- a/src/lib/merchant_api_delete_instances_ID.c
+++ b/src/lib/merchant_api_delete_instances_ID.c
@@ -33,7 +33,7 @@
 /**
  * Handle for a DELETE /instances/$ID operation.
  */
-struct TALER_MERCHANT_InstancesDeleteHandle
+struct TALER_MERCHANT_InstanceDeleteHandle
 {
   /**
    * The url for this request.
@@ -48,7 +48,7 @@ struct TALER_MERCHANT_InstancesDeleteHandle
   /**
    * Function to call with the result.
    */
-  TALER_MERCHANT_InstancesDeleteCallback cb;
+  TALER_MERCHANT_InstanceDeleteCallback cb;
 
   /**
    * Closure for @a cb.
@@ -72,11 +72,11 @@ struct TALER_MERCHANT_InstancesDeleteHandle
  * @param json response body, NULL if not in JSON
  */
 static void
-handle_instances_delete_finished (void *cls,
-                                  long response_code,
-                                  const void *response)
+handle_instance_delete_finished (void *cls,
+                                 long response_code,
+                                 const void *response)
 {
-  struct TALER_MERCHANT_InstancesDeleteHandle *idh = cls;
+  struct TALER_MERCHANT_InstanceDeleteHandle *idh = cls;
   const json_t *json = response;
   struct TALER_MERCHANT_HttpResponse hr = {
     .http_status = (unsigned int) response_code,
@@ -107,7 +107,7 @@ handle_instances_delete_finished (void *cls,
   }
   idh->cb (idh->cb_cls,
            &hr);
-  TALER_MERCHANT_instances_delete_cancel (idh);
+  TALER_MERCHANT_instance_delete_cancel (idh);
 }
 
 
@@ -123,19 +123,19 @@ handle_instances_delete_finished (void *cls,
  * @param instances_cb_cls closure for @a config_cb
  * @return the instances handle; NULL upon error
  */
-static struct TALER_MERCHANT_InstancesDeleteHandle *
-instances_delete (
+static struct TALER_MERCHANT_InstanceDeleteHandle *
+instance_delete (
   struct GNUNET_CURL_Context *ctx,
   const char *backend_url,
   const char *instance_id,
   bool purge,
-  TALER_MERCHANT_InstancesDeleteCallback instances_cb,
+  TALER_MERCHANT_InstanceDeleteCallback instances_cb,
   void *instances_cb_cls)
 {
-  struct TALER_MERCHANT_InstancesDeleteHandle *idh;
+  struct TALER_MERCHANT_InstanceDeleteHandle *idh;
   CURL *eh;
 
-  idh = GNUNET_new (struct TALER_MERCHANT_InstancesDeleteHandle);
+  idh = GNUNET_new (struct TALER_MERCHANT_InstanceDeleteHandle);
   idh->ctx = ctx;
   idh->cb = instances_cb;
   idh->cb_cls = instances_cb_cls;
@@ -179,7 +179,7 @@ instances_delete (
   idh->job = GNUNET_CURL_job_add (ctx,
                                   eh,
                                   GNUNET_YES,
-                                  &handle_instances_delete_finished,
+                                  &handle_instance_delete_finished,
                                   idh);
   return idh;
 }
@@ -197,20 +197,20 @@ instances_delete (
  * @param instances_cb_cls closure for @a config_cb
  * @return the instances handle; NULL upon error
  */
-struct TALER_MERCHANT_InstancesDeleteHandle *
-TALER_MERCHANT_instances_delete_instance (
+struct TALER_MERCHANT_InstanceDeleteHandle *
+TALER_MERCHANT_instance_delete (
   struct GNUNET_CURL_Context *ctx,
   const char *backend_url,
   const char *instance_id,
-  TALER_MERCHANT_InstancesDeleteCallback instances_cb,
+  TALER_MERCHANT_InstanceDeleteCallback instances_cb,
   void *instances_cb_cls)
 {
-  return instances_delete (ctx,
-                           backend_url,
-                           instance_id,
-                           false,
-                           instances_cb,
-                           instances_cb_cls);
+  return instance_delete (ctx,
+                          backend_url,
+                          instance_id,
+                          false,
+                          instances_cb,
+                          instances_cb_cls);
 }
 
 
@@ -226,20 +226,20 @@ TALER_MERCHANT_instances_delete_instance (
  * @param instances_cb_cls closure for @a config_cb
  * @return the instances handle; NULL upon error
  */
-struct TALER_MERCHANT_InstancesDeleteHandle *
-TALER_MERCHANT_instances_purge_instance (
+struct TALER_MERCHANT_InstanceDeleteHandle *
+TALER_MERCHANT_instance_purge (
   struct GNUNET_CURL_Context *ctx,
   const char *backend_url,
   const char *instance_id,
-  TALER_MERCHANT_InstancesDeleteCallback instances_cb,
+  TALER_MERCHANT_InstanceDeleteCallback instances_cb,
   void *instances_cb_cls)
 {
-  return instances_delete (ctx,
-                           backend_url,
-                           instance_id,
-                           true,
-                           instances_cb,
-                           instances_cb_cls);
+  return instance_delete (ctx,
+                          backend_url,
+                          instance_id,
+                          true,
+                          instances_cb,
+                          instances_cb_cls);
 }
 
 
@@ -250,8 +250,8 @@ TALER_MERCHANT_instances_purge_instance (
  * @param idh request to cancel.
  */
 void
-TALER_MERCHANT_instances_delete_cancel (
-  struct TALER_MERCHANT_InstancesDeleteHandle *idh)
+TALER_MERCHANT_instance_delete_cancel (
+  struct TALER_MERCHANT_InstanceDeleteHandle *idh)
 {
   if (NULL != idh->job)
     GNUNET_CURL_job_cancel (idh->job);

-- 
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]