commit a5c27744fb269c108e3e4f8e9fa29e51403dd4c8
parent 7a38e2dcaaabfc0a17ca9362a40958539c629785
Author: Christian Grothoff <grothoff@gnunet.org>
Date: Sat, 17 Jan 2026 12:22:08 +0100
fix some ECs, WiP on templates
Diffstat:
2 files changed, 56 insertions(+), 39 deletions(-)
diff --git a/src/backend/taler-merchant-httpd_get-templates-ID.c b/src/backend/taler-merchant-httpd_get-templates-ID.c
@@ -121,6 +121,10 @@ add_inventory_product (
for (size_t i = 0; i < num_categories; i++)
{
/* Adding per product category */
+ // FIXME: include how much of the product is
+ // still in stock (if we manage stock)
+ // => wallets can restrict user to
+ // only select an amount that is still in stock
TMH_category_set_add (&ipc->category_set,
categories[i]);
GNUNET_assert (0 ==
diff --git a/src/backend/taler-merchant-httpd_post-using-templates.c b/src/backend/taler-merchant-httpd_post-using-templates.c
@@ -471,39 +471,16 @@ parse_using_templates_inventory_request (
return GNUNET_SYSERR;
}
- if ( (! uc->parse_request.no_amount) ||
- (! uc->parse_request.no_tip) )
- {
- if (! TMH_test_exchange_configured_for_currency (
- (! uc->parse_request.no_amount)
- ? uc->parse_request.amount.currency
- : uc->parse_request.tip.currency))
- {
- GNUNET_break_op (0);
- use_reply_with_error (uc,
- MHD_HTTP_CONFLICT,
- TALER_EC_MERCHANT_GENERIC_CURRENCY_MISMATCH,
- "Currency is not supported by backend");
- return GNUNET_SYSERR;
- }
- }
-
- if (! uc->parse_request.no_tip)
+ if ( (! uc->parse_request.no_amount) &&
+ (! TMH_test_exchange_configured_for_currency (
+ uc->parse_request.amount.currency)) )
{
- if (! uc->parse_request.no_amount &&
- (GNUNET_YES !=
- TALER_amount_cmp_currency (
- &uc->parse_request.amount,
- &uc->parse_request.tip)))
- {
- GNUNET_break_op (0);
- use_reply_with_error (
- uc,
- MHD_HTTP_BAD_REQUEST,
- TALER_EC_GENERIC_CURRENCY_MISMATCH,
- "Mismatch of currencies between the total amount and tip");
- return GNUNET_SYSERR;
- }
+ GNUNET_break_op (0);
+ use_reply_with_error (uc,
+ MHD_HTTP_CONFLICT,
+ TALER_EC_MERCHANT_GENERIC_CURRENCY_MISMATCH,
+ "Currency is not supported by backend");
+ return GNUNET_SYSERR;
}
for (size_t i = 0; i < json_array_size (inventory_selection); i++)
@@ -1006,7 +983,7 @@ verify_using_templates_inventory (struct UseContext *uc)
use_reply_with_error (
uc,
MHD_HTTP_CONFLICT,
- TALER_EC_GENERIC_PARAMETER_MALFORMED, /* FIXME: bad EC! */
+ TALER_EC_MERCHANT_POST_USING_TEMPLATES_WRONG_PRODUCT,
item->product_id);
return GNUNET_SYSERR;
}
@@ -1382,12 +1359,27 @@ handle_phase_compute_price (struct UseContext *uc)
switch (uc->template_type)
{
case TALER_MERCHANT_TEMPLATE_TYPE_FIXED_ORDER:
- uc->phase++;
- return;
case TALER_MERCHANT_TEMPLATE_TYPE_PAIVANA:
+ uc->compute_price.totals
+ = GNUNET_new (struct TALER_Amount);
+ uc->compute_price.totals_len
+ = 1;
+ if (uc->parse_request.no_amount)
+ {
+ GNUNET_assert (! uc->parse_template.no_tamount);
+ *uc->compute_price.totals
+ = uc->parse_template.tamount;
+ }
+ else
+ {
+ GNUNET_assert (uc->parse_template.no_tamount);
+ *uc->compute_price.totals
+ = uc->parse_request.amount;
+ }
uc->phase++;
return;
case TALER_MERCHANT_TEMPLATE_TYPE_INVENTORY_CART:
+ /* handled below */
break;
case TALER_MERCHANT_TEMPLATE_TYPE_INVALID:
GNUNET_assert (0);
@@ -1416,7 +1408,7 @@ handle_phase_compute_price (struct UseContext *uc)
{
use_reply_with_error (uc,
MHD_HTTP_INTERNAL_SERVER_ERROR,
- TALER_EC_GENERIC_INTERNAL_INVARIANT_FAILURE, // FIXME: bad EC, use arithmetic error
+ TALER_EC_GENERIC_FAILED_COMPUTE_AMOUNT,
"calculation of currency totals failed");
return;
}
@@ -1424,8 +1416,8 @@ handle_phase_compute_price (struct UseContext *uc)
{
use_reply_with_error (uc,
MHD_HTTP_CONFLICT,
- TALER_EC_GENERIC_INTERNAL_INVARIANT_FAILURE, // FIXME: bad EC!
- "failed to find prices in any acceptable currency for all selected products");
+ TALER_EC_MERCHANT_POST_USING_TEMPLATES_NO_CURRENCY,
+ NULL);
return;
}
@@ -1451,7 +1443,28 @@ handle_phase_check_tip (struct UseContext *uc)
uc->phase++;
return;
}
- // FIXME: not quite right if we do not have compute_price total!
+ if (0 == uc->compute_price.totals_len)
+ {
+ if (! TMH_test_exchange_configured_for_currency (
+ uc->parse_request.tip.currency))
+ {
+ GNUNET_break_op (0);
+ use_reply_with_error (uc,
+ MHD_HTTP_CONFLICT,
+ TALER_EC_MERCHANT_GENERIC_CURRENCY_MISMATCH,
+ "Tip currency is not supported by backend");
+ return;
+ }
+ uc->compute_price.totals
+ = GNUNET_new (struct TALER_Amount);
+ uc->compute_price.totals_len
+ = 1;
+ *uc->compute_price.totals
+ = uc->parse_request.tip;
+ uc->phase++;
+ return;
+ }
+ GNUNET_assert (1 == uc->compute_price.totals_len);
total_amount = &uc->compute_price.totals[0];
if (GNUNET_YES !=
TALER_amount_cmp_currency (&uc->parse_request.tip,