summaryrefslogtreecommitdiff
path: root/src/backend
diff options
context:
space:
mode:
authorChristian Blättler <blatc2@bfh.ch>2023-12-18 09:11:41 +0100
committerChristian Grothoff <grothoff@gnunet.org>2023-12-23 00:09:56 +0800
commitebb6c68e941a96b19242f486aff06ca81952e908 (patch)
treebdfe36c9dfdecf416e69f1f0708bf0cbb477a892 /src/backend
parent5fa8678d9490957b5d23a34a06f001d4ec5de41b (diff)
downloadmerchant-ebb6c68e941a96b19242f486aff06ca81952e908.tar.gz
merchant-ebb6c68e941a96b19242f486aff06ca81952e908.tar.bz2
merchant-ebb6c68e941a96b19242f486aff06ca81952e908.zip
fix order serialization so test are passing
Diffstat (limited to 'src/backend')
-rw-r--r--src/backend/taler-merchant-httpd_private-post-orders.c84
1 files changed, 49 insertions, 35 deletions
diff --git a/src/backend/taler-merchant-httpd_private-post-orders.c b/src/backend/taler-merchant-httpd_private-post-orders.c
index 008c378d..9d00b0b9 100644
--- a/src/backend/taler-merchant-httpd_private-post-orders.c
+++ b/src/backend/taler-merchant-httpd_private-post-orders.c
@@ -24,7 +24,9 @@
* @author Marcello Stanisci
*/
#include "platform.h"
+#include <gnunet/gnunet_common.h>
#include <gnunet/gnunet_json_lib.h>
+#include <gnunet/gnunet_time_lib.h>
#include <jansson.h>
#include <string.h>
#include <taler/taler_signatures.h>
@@ -281,6 +283,11 @@ struct OrderContext
struct GNUNET_TIME_Timestamp delivery_date;
/**
+ * Delivery location.
+ */
+ json_t *delivery_location;
+
+ /**
* Payment deadline.
*/
struct GNUNET_TIME_Timestamp pay_deadline;
@@ -318,11 +325,6 @@ struct OrderContext
struct TALER_Amount max_fee;
/**
- * Delivery location.
- */
- const json_t *delivery_location;
-
- /**
* Specifies for how long the wallet should try to get an
* automatic refund for the purchase.
*/
@@ -1245,25 +1247,25 @@ get_exchange_keys (void *cls,
static void
serialize_order (struct OrderContext *oc)
{
- /* TODO: add public_reorder_url
- fulfillment_message
- fulfillment_message_i18n
- nonce
- extra (?)
- */
-
oc->serialize_order.contract = GNUNET_JSON_PACK (
GNUNET_JSON_pack_string ("summary",
oc->patch_order.summary),
- GNUNET_JSON_pack_object_steal ("summary_i18n",
- oc->patch_order.summary_i18n),
- GNUNET_JSON_pack_string ("public_reorder_url",
- oc->patch_order.public_reorder_url),
- GNUNET_JSON_pack_string ("fulfillment_message",
- oc->patch_order.fulfillment_message),
- GNUNET_JSON_pack_object_steal ("fulfillment_message_i18n",
- oc->patch_order.fulfillment_message_i18n),
- GNUNET_JSON_pack_object_steal ("products",
+ GNUNET_JSON_pack_allow_null (
+ GNUNET_JSON_pack_object_steal ("summary_i18n",
+ oc->patch_order.summary_i18n)),
+ GNUNET_JSON_pack_allow_null (
+ GNUNET_JSON_pack_string ("public_reorder_url",
+ oc->patch_order.public_reorder_url)),
+ GNUNET_JSON_pack_allow_null (
+ GNUNET_JSON_pack_string ("fulfillment_message",
+ oc->patch_order.fulfillment_message)),
+ GNUNET_JSON_pack_allow_null (
+ GNUNET_JSON_pack_object_steal ("fulfillment_message_i18n",
+ oc->patch_order.fulfillment_message_i18n)),
+ GNUNET_JSON_pack_allow_null (
+ GNUNET_JSON_pack_string ("fulfillment_url",
+ oc->patch_order.fulfillment_url)),
+ GNUNET_JSON_pack_array_steal ("products",
oc->merge_inventory.products),
GNUNET_JSON_pack_data_auto ("h_wire",
&oc->add_payment_details.wm->h_wire),
@@ -1271,22 +1273,18 @@ serialize_order (struct OrderContext *oc)
oc->add_payment_details.wm->wire_method),
GNUNET_JSON_pack_string ("order_id",
oc->patch_order.order_id),
- GNUNET_JSON_pack_allow_null (
- GNUNET_JSON_pack_string ("fulfillment_url",
- oc->patch_order.fulfillment_url)),
GNUNET_JSON_pack_timestamp ("timestamp",
oc->patch_order.timestamp),
- GNUNET_JSON_pack_timestamp ("refund_deadline",
- oc->patch_order.refund_deadline),
GNUNET_JSON_pack_timestamp ("pay_deadline",
oc->patch_order.pay_deadline),
GNUNET_JSON_pack_timestamp ("wire_transfer_deadline",
oc->patch_order.wire_deadline),
- GNUNET_JSON_pack_time_rel ("auto_refund",
- oc->patch_order.auto_refund),
GNUNET_JSON_pack_allow_null (
GNUNET_JSON_pack_timestamp ("delivery_date",
oc->patch_order.delivery_date)),
+ GNUNET_JSON_pack_allow_null (
+ GNUNET_JSON_pack_object_steal ("delivery_location",
+ oc->patch_order.delivery_location)),
GNUNET_JSON_pack_string ("merchant_base_url",
oc->patch_order.merchant_base_url),
GNUNET_JSON_pack_object_steal ("merchant",
@@ -1299,11 +1297,26 @@ serialize_order (struct OrderContext *oc)
&oc->set_max_fee.max_fee),
TALER_JSON_pack_amount ("amount",
&oc->patch_order.brutto),
- GNUNET_JSON_pack_string ("nonce",
- oc->patch_order.nonce),
- GNUNET_JSON_pack_object_steal ("extra",
- oc->patch_order.extra)
+ GNUNET_JSON_pack_allow_null (
+ GNUNET_JSON_pack_object_steal ("extra",
+ oc->patch_order.extra))
);
+
+ /* Pack does not work here, because it doesn't set zero-values for timestamps */
+ GNUNET_assert (0 ==
+ json_object_set_new (oc->serialize_order.contract,
+ "refund_deadline",
+ GNUNET_JSON_from_timestamp (
+ oc->patch_order.refund_deadline)));
+
+ if (!GNUNET_TIME_relative_is_zero(oc->patch_order.auto_refund)) {
+ GNUNET_assert (0 ==
+ json_object_set_new (oc->serialize_order.contract,
+ "auto_refund",
+ GNUNET_JSON_from_time_rel (
+ oc->patch_order.auto_refund)));
+ }
+
oc->phase++;
}
@@ -1419,6 +1432,7 @@ patch_order (struct OrderContext *oc)
oc->patch_order.merchant_base_url = NULL;
oc->patch_order.timestamp = GNUNET_TIME_UNIT_ZERO_TS;
oc->patch_order.refund_deadline = GNUNET_TIME_UNIT_FOREVER_TS;
+ oc->patch_order.auto_refund = GNUNET_TIME_UNIT_ZERO;
oc->patch_order.pay_deadline = GNUNET_TIME_UNIT_ZERO_TS;
oc->patch_order.wire_deadline = GNUNET_TIME_UNIT_FOREVER_TS;
oc->patch_order.delivery_location = NULL;
@@ -1487,8 +1501,8 @@ patch_order (struct OrderContext *oc)
&oc->patch_order.max_fee),
&no_fee),
GNUNET_JSON_spec_mark_optional (
- GNUNET_JSON_spec_object_const ("delivery_location",
- &oc->patch_order.delivery_location),
+ GNUNET_JSON_spec_json ("delivery_location",
+ &oc->patch_order.delivery_location),
NULL),
GNUNET_JSON_spec_mark_optional (
GNUNET_JSON_spec_timestamp ("delivery_date",
@@ -1898,7 +1912,7 @@ merge_inventory (struct OrderContext *oc)
*/
{
oc->merge_inventory.products = json_object_get (oc->init.order,
- "products");
+ "products");
if (NULL == oc->merge_inventory.products)
{
oc->merge_inventory.products = json_array ();