summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorꦌꦫꦶꦏ꧀ꦦꦿꦧꦮꦑꦩꦭ꧀ <erik@darapsa.co.id>2023-03-09 12:04:11 +0800
committerꦌꦫꦶꦏ꧀ꦦꦿꦧꦮꦑꦩꦭ꧀ <erik@darapsa.co.id>2023-03-09 12:04:11 +0800
commit1be551eb39df7240b661b2c7e661d31dd242476e (patch)
tree52380f3c2245bfd60ba452154fd822a4e0be3f81
parentc4244b7286dc0b0ac5ba8e0d5ad425a250c68892 (diff)
Handler parameter to order
-rw-r--r--interchange/ord.h8
-rw-r--r--ord.c8
2 files changed, 11 insertions, 5 deletions
diff --git a/interchange/ord.h b/interchange/ord.h
index f57b66a..ce6bb65 100644
--- a/interchange/ord.h
+++ b/interchange/ord.h
@@ -32,9 +32,13 @@ extern "C" {
* \param sku The SKU of the item to order.
* \param catalog The catalog from which the item is.
* \param order The address of an order instance.
+ * \param handler A pointer to the function when a custom handler is needed to
+ * arrange the data into the order.
*/
-void interchange_ord_order(const char *sku, const struct interchange_catalog *catalog,
- struct interchange_ord_order **order);
+void interchange_ord_order(const char *sku,
+ const struct interchange_catalog *catalog,
+ struct interchange_ord_order **order,
+ void (*handler)(interchange_response *));
/*!
* \brief For checking out items in the cart.
diff --git a/ord.c b/ord.c
index 8d4e0ae..664d18c 100644
--- a/ord.c
+++ b/ord.c
@@ -17,8 +17,10 @@ static int itemcmp(const void *item1, const void *item2)
(*(struct interchange_ord_item * const *)item2)->product->sku);
}
-void interchange_ord_order(const char *sku, const struct interchange_catalog *catalog,
- struct interchange_ord_order **order)
+void interchange_ord_order(const char *sku,
+ const struct interchange_catalog *catalog,
+ struct interchange_ord_order **order,
+ void (*handler)(interchange_response *))
{
struct interchange_product **products = ((struct interchange_catalog *)catalog)->products;
qsort(products, catalog->length, sizeof(struct interchange_product *), prodcmp);
@@ -58,7 +60,7 @@ void interchange_ord_order(const char *sku, const struct interchange_catalog *ca
}
(*order)->subtotal += item->product->price;
(*order)->total_cost += item->product->price;
- request(NULL, NULL, NULL, "%s%s", "order?mv_arg=", sku);
+ request(handler, NULL, NULL, "%s%s", "order?mv_arg=", sku);
}
void interchange_ord_checkout(const struct interchange_ord_order *order,