aboutsummaryrefslogtreecommitdiff
path: root/src/backend/taler-merchant-httpd_private-post-orders.c
diff options
context:
space:
mode:
authorChristian Blättler <blatc2@bfh.ch>2024-06-13 11:34:46 +0200
committerChristian Blättler <blatc2@bfh.ch>2024-06-13 11:34:46 +0200
commit599db2c13cc7b4eddab22f1e8ef55dde23086f68 (patch)
tree53f1060f6507cffdaf3a139428d7ab4614b13efa /src/backend/taler-merchant-httpd_private-post-orders.c
parentb9315cf4675bfb2ae94b71cf8931963b27873a5b (diff)
parent2e8cfbe844d4fbcf5fa6f086be0b184821e1bdc2 (diff)
Merge branch 'master' into tokens-payment
# Conflicts: # src/backend/taler-merchant-httpd_private-post-orders.c # src/backenddb/Makefile.am # src/backenddb/merchant-0006.sql # src/backenddb/pg_insert_token_family_key.c
Diffstat (limited to 'src/backend/taler-merchant-httpd_private-post-orders.c')
-rw-r--r--src/backend/taler-merchant-httpd_private-post-orders.c72
1 files changed, 44 insertions, 28 deletions
diff --git a/src/backend/taler-merchant-httpd_private-post-orders.c b/src/backend/taler-merchant-httpd_private-post-orders.c
index e8332c70..a2e3b493 100644
--- a/src/backend/taler-merchant-httpd_private-post-orders.c
+++ b/src/backend/taler-merchant-httpd_private-post-orders.c
@@ -960,6 +960,8 @@ execute_order (struct OrderContext *oc)
struct TALER_MERCHANTDB_ProductDetails pd;
MHD_RESULT ret;
const struct InventoryProduct *ip;
+ size_t num_categories = 0;
+ uint64_t *categories = NULL;
ip = &oc->parse_request.inventory_products[
oc->execute_order.out_of_stock_index];
@@ -970,10 +972,13 @@ execute_order (struct OrderContext *oc)
TMH_db->cls,
oc->hc->instance->settings.id,
ip->product_id,
- &pd);
+ &pd,
+ &num_categories,
+ &categories);
switch (qs)
{
case GNUNET_DB_STATUS_SUCCESS_ONE_RESULT:
+ GNUNET_free (categories);
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"Order creation failed: product out of stock\n");
ret = TALER_MHD_REPLY_JSON_PACK (
@@ -1337,6 +1342,7 @@ get_exchange_keys (void *cls,
rx);
}
+
/**
* Get rounded time interval. @a start is calculated by rounding
* @a ts down to the nearest multiple of @a precision. @a end is
@@ -1449,9 +1455,7 @@ set_token_family (struct OrderContext *oc,
struct TALER_MERCHANTDB_TokenFamilyKeyDetails key_details;
struct TALER_MerchantContractTokenFamily *family = NULL;
enum GNUNET_DB_QueryStatus qs;
- // TODO: make this configurable. This is the granularity of token
- // expiration dates. This should be stored in the
- // database along the token family.
+ /* TODO: Implement rounding duration of token family and use this here. */
struct GNUNET_TIME_Relative precision = GNUNET_TIME_UNIT_MONTHS;
struct GNUNET_TIME_Timestamp min_valid_after;
struct GNUNET_TIME_Timestamp max_valid_after;
@@ -1694,6 +1698,7 @@ set_token_family (struct OrderContext *oc,
return GNUNET_OK;
}
+
/**
* Serialize order into @a oc->serialize_order.contract,
* ready to be stored in the database. Upon success, continue
@@ -1712,16 +1717,16 @@ serialize_order (struct OrderContext *oc)
merchant = GNUNET_JSON_PACK (
GNUNET_JSON_pack_string ("name",
- settings->name),
+ settings->name),
GNUNET_JSON_pack_allow_null (
GNUNET_JSON_pack_string ("website",
- settings->website)),
+ settings->website)),
GNUNET_JSON_pack_allow_null (
GNUNET_JSON_pack_string ("email",
- settings->email)),
+ settings->email)),
GNUNET_JSON_pack_allow_null (
GNUNET_JSON_pack_string ("logo",
- settings->logo)));
+ settings->logo)));
GNUNET_assert (NULL != merchant);
{
json_t *loca;
@@ -1733,7 +1738,7 @@ serialize_order (struct OrderContext *oc)
loca = json_deep_copy (loca);
GNUNET_assert (NULL != loca);
GNUNET_assert (0 ==
- json_object_set_new (merchant,
+ json_object_set_new (merchant,
"address",
loca));
}
@@ -1748,7 +1753,7 @@ serialize_order (struct OrderContext *oc)
juri = json_deep_copy (juri);
GNUNET_assert (NULL != juri);
GNUNET_assert (0 ==
- json_object_set_new (merchant,
+ json_object_set_new (merchant,
"jurisdiction",
juri));
}
@@ -1855,10 +1860,10 @@ serialize_order (struct OrderContext *oc)
json_t *jchoice = GNUNET_JSON_PACK (
GNUNET_JSON_pack_array_incref ("inputs",
- inputs),
+ inputs),
GNUNET_JSON_pack_array_incref ("outputs",
- outputs)
- );
+ outputs)
+ );
GNUNET_assert (0 == json_array_append (choices, jchoice));
}
@@ -1879,7 +1884,8 @@ serialize_order (struct OrderContext *oc)
oc->parse_order.fulfillment_message)),
GNUNET_JSON_pack_allow_null (
GNUNET_JSON_pack_object_incref ("fulfillment_message_i18n",
- oc->parse_order.fulfillment_message_i18n)),
+ oc->parse_order.fulfillment_message_i18n))
+ ,
GNUNET_JSON_pack_allow_null (
GNUNET_JSON_pack_string ("fulfillment_url",
oc->parse_order.fulfillment_url)),
@@ -1961,6 +1967,7 @@ serialize_order (struct OrderContext *oc)
oc->phase++;
}
+
/**
* Set max_fee in @a oc based on STEFAN value if
* not yet present. Upon success, continue
@@ -1996,6 +2003,7 @@ set_max_fee (struct OrderContext *oc)
oc->phase++;
}
+
/**
* Set list of acceptable exchanges in @a oc. Upon success, continue
* processing with set_max_fee().
@@ -2119,7 +2127,7 @@ parse_order (struct OrderContext *oc)
NULL),
GNUNET_JSON_spec_mark_optional (
GNUNET_JSON_spec_array_const ("choices",
- &oc->parse_order.choices),
+ &oc->parse_order.choices),
NULL),
GNUNET_JSON_spec_mark_optional (
TALER_JSON_spec_web_url ("merchant_base_url",
@@ -2185,7 +2193,7 @@ parse_order (struct OrderContext *oc)
ret);
return;
}
- if (NULL == version || 0 == strcmp("0", version))
+ if (NULL == version || 0 == strcmp ("0", version))
{
oc->parse_order.version = TALER_MCV_V0;
@@ -2200,11 +2208,11 @@ parse_order (struct OrderContext *oc)
return;
}
}
- else if (0 == strcmp("1", version))
+ else if (0 == strcmp ("1", version))
{
oc->parse_order.version = TALER_MCV_V1;
- if (! json_is_array(oc->parse_order.choices))
+ if (! json_is_array (oc->parse_order.choices))
{
GNUNET_break_op (0);
GNUNET_JSON_parse_free (spec);
@@ -2237,9 +2245,9 @@ parse_order (struct OrderContext *oc)
return;
}
if ( (! no_fee) &&
- (GNUNET_OK !=
- TALER_amount_cmp_currency (&oc->parse_order.brutto,
- &oc->parse_order.max_fee)) )
+ (GNUNET_OK !=
+ TALER_amount_cmp_currency (&oc->parse_order.brutto,
+ &oc->parse_order.max_fee)) )
{
GNUNET_break_op (0);
GNUNET_JSON_parse_free (spec);
@@ -2516,6 +2524,7 @@ parse_order (struct OrderContext *oc)
oc->phase++;
}
+
/**
* Parse contract choices. Upon success, continue
* processing with merge_inventory().
@@ -2606,7 +2615,7 @@ parse_choices (struct OrderContext *oc)
GNUNET_JSON_spec_uint32 ("count",
&input.details.token.count),
NULL),
- GNUNET_JSON_spec_end()
+ GNUNET_JSON_spec_end ()
};
if (GNUNET_OK !=
@@ -2665,7 +2674,8 @@ parse_choices (struct OrderContext *oc)
size_t idx;
json_array_foreach ((json_t *) joutputs, idx, joutput)
{
- struct TALER_MerchantContractOutput output = { .details.token.count = 1 };
+ struct TALER_MerchantContractOutput output = { .details.token.count = 1}
+ ;
const char *kind;
const char *ierror_name;
unsigned int ierror_line;
@@ -2682,14 +2692,14 @@ parse_choices (struct OrderContext *oc)
GNUNET_JSON_spec_uint32 ("count",
&output.details.token.count),
NULL),
- GNUNET_JSON_spec_end()
+ GNUNET_JSON_spec_end ()
};
if (GNUNET_OK !=
GNUNET_JSON_parse (joutput,
- ispec,
- &ierror_name,
- &ierror_line))
+ ispec,
+ &ierror_name,
+ &ierror_line))
{
GNUNET_JSON_parse_free (spec);
GNUNET_JSON_parse_free (ispec);
@@ -2744,6 +2754,7 @@ parse_choices (struct OrderContext *oc)
oc->phase++;
}
+
/**
* Process the @a payment_target and add the details of how the
* order could be paid to @a order. On success, continue
@@ -2809,11 +2820,15 @@ merge_inventory (struct OrderContext *oc)
= &oc->parse_request.inventory_products[i];
struct TALER_MERCHANTDB_ProductDetails pd;
enum GNUNET_DB_QueryStatus qs;
+ size_t num_categories = 0;
+ uint64_t *categories = NULL;
qs = TMH_db->lookup_product (TMH_db->cls,
oc->hc->instance->settings.id,
ip->product_id,
- &pd);
+ &pd,
+ &num_categories,
+ &categories);
if (qs <= 0)
{
enum TALER_ErrorCode ec = TALER_EC_GENERIC_INTERNAL_INVARIANT_FAILURE;
@@ -2848,6 +2863,7 @@ merge_inventory (struct OrderContext *oc)
ip->product_id);
return;
}
+ GNUNET_free (categories);
oc->parse_order.minimum_age
= GNUNET_MAX (oc->parse_order.minimum_age,
pd.minimum_age);