aboutsummaryrefslogtreecommitdiff
path: root/src/backend/taler-merchant-httpd_private-get-orders-ID.c
diff options
context:
space:
mode:
authorChristian Grothoff <grothoff@gnunet.org>2023-10-13 20:51:04 +0200
committerChristian Grothoff <grothoff@gnunet.org>2023-10-13 21:16:50 +0200
commit0f3490dc022620c7e42b86426e14198a04c2e17f (patch)
tree0b16661ae6aa9273bf81652fe6a8806060b31fb0 /src/backend/taler-merchant-httpd_private-get-orders-ID.c
parenta5f50083e65a3e9a0945b150701349afa81a0e9e (diff)
more work on multicurrency support: use checks everywhere...
Diffstat (limited to 'src/backend/taler-merchant-httpd_private-get-orders-ID.c')
-rw-r--r--src/backend/taler-merchant-httpd_private-get-orders-ID.c96
1 files changed, 87 insertions, 9 deletions
diff --git a/src/backend/taler-merchant-httpd_private-get-orders-ID.c b/src/backend/taler-merchant-httpd_private-get-orders-ID.c
index 14e71762..98bf2ab8 100644
--- a/src/backend/taler-merchant-httpd_private-get-orders-ID.c
+++ b/src/backend/taler-merchant-httpd_private-get-orders-ID.c
@@ -1,6 +1,6 @@
/*
This file is part of TALER
- (C) 2017-2022 Taler Systems SA
+ (C) 2017-2023 Taler Systems SA
TALER is free software; you can redistribute it and/or modify it under the
terms of the GNU General Public License as published by the Free Software
@@ -285,6 +285,19 @@ struct GetOrderRequestContext
*/
bool transfer_status_requested;
+ /**
+ * Set to true if our database (incorrectly) has refunds
+ * in a different currency than the currency of the
+ * original payment for the order.
+ */
+ bool refund_currency_mismatch;
+
+ /**
+ * Set to true if our database (incorrectly) has deposits
+ * in a different currency than the currency of the
+ * original payment for the order.
+ */
+ bool deposit_currency_mismatch;
};
@@ -484,6 +497,29 @@ deposit_get_cb (void *cls,
return;
}
/* Compute total amount *wired* */
+ if ( (GNUNET_OK !=
+ TALER_amount_cmp_currency (
+ &gorc->deposits_total,
+ &dr->details.ok.coin_contribution)) ||
+ (GNUNET_OK !=
+ TALER_amount_cmp_currency (
+ &gorc->deposit_fees_total,
+ &tq->deposit_fee)) )
+ {
+ /* something very wrong in our database ... */
+ GNUNET_break (0);
+ gorc_report (gorc,
+ TALER_EC_GENERIC_DB_FETCH_FAILED,
+ &tq->coin_pub,
+ NULL);
+ GNUNET_free (tq->exchange_url);
+ GNUNET_free (tq);
+ if (NULL == gorc->tq_head)
+ gorc_resume (gorc,
+ 0,
+ TALER_EC_NONE);
+ return;
+ }
if (0 >
TALER_amount_add (&gorc->deposits_total,
&gorc->deposits_total,
@@ -775,12 +811,29 @@ process_refunds_cb (void *cls,
GNUNET_memcmp (&tq->coin_pub,
coin_pub))
{
+ if (GNUNET_OK !=
+ TALER_amount_cmp_currency (
+ &gorc->deposit_fees_total,
+ &tq->deposit_fee))
+ {
+ gorc->refund_currency_mismatch = true;
+ return;
+ }
+
GNUNET_assert (0 <=
TALER_amount_subtract (&gorc->deposit_fees_total,
&gorc->deposit_fees_total,
&tq->deposit_fee));
}
}
+ if (GNUNET_OK !=
+ TALER_amount_cmp_currency (
+ &gorc->refund_amount,
+ refund_amount))
+ {
+ gorc->refund_currency_mismatch = true;
+ return;
+ }
GNUNET_assert (0 <=
TALER_amount_add (&gorc->refund_amount,
&gorc->refund_amount,
@@ -817,6 +870,18 @@ process_transfer_details (
json_t *wire_details = gorc->wire_details;
struct TALER_Amount wired;
+ if ( (GNUNET_OK !=
+ TALER_amount_cmp_currency (&gorc->deposits_total,
+ deposit_value)) ||
+ (GNUNET_OK !=
+ TALER_amount_cmp_currency (&gorc->deposit_fees_total,
+ deposit_fee)) )
+ {
+ GNUNET_break (0);
+ gorc->deposit_currency_mismatch = true;
+ return;
+ }
+
/* Compute total amount *wired* */
GNUNET_assert (0 <
TALER_amount_add (&gorc->deposits_total,
@@ -1233,12 +1298,11 @@ TMH_private_get_orders_ID (const struct TMH_RequestHandler *rh,
{
/* suspend connection, wait for exchange to check wire transfer status there */
gorc->transfer_status_requested = false; /* only try ONCE */
- /* FIXME: #7951 */
GNUNET_assert (GNUNET_OK ==
- TALER_amount_set_zero (TMH_currency,
+ TALER_amount_set_zero (gorc->contract_amount.currency,
&gorc->deposits_total));
GNUNET_assert (GNUNET_OK ==
- TALER_amount_set_zero (TMH_currency,
+ TALER_amount_set_zero (gorc->contract_amount.currency,
&gorc->deposit_fees_total));
TMH_db->lookup_deposits_by_order (TMH_db->cls,
gorc->order_serial,
@@ -1316,9 +1380,8 @@ TMH_private_get_orders_ID (const struct TMH_RequestHandler *rh,
GNUNET_assert (paid);
/* Accumulate refunds, if any. */
{
- /* FIXME: #7951 */
GNUNET_assert (GNUNET_OK ==
- TALER_amount_set_zero (TMH_currency,
+ TALER_amount_set_zero (gorc->contract_amount.currency,
&gorc->refund_amount));
qs = TMH_db->lookup_refunds_detailed (TMH_db->cls,
hc->instance->settings.id,
@@ -1334,18 +1397,25 @@ TMH_private_get_orders_ID (const struct TMH_RequestHandler *rh,
TALER_EC_GENERIC_DB_FETCH_FAILED,
"detailed refunds");
}
+ if (gorc->refund_currency_mismatch)
+ {
+ GNUNET_break (0);
+ return TALER_MHD_reply_with_error (connection,
+ MHD_HTTP_INTERNAL_SERVER_ERROR,
+ TALER_EC_GENERIC_DB_FETCH_FAILED,
+ "refunds in different currency than original order price");
+ }
/* Generate final reply, including wire details if we have them */
{
MHD_RESULT ret;
char *order_status_url;
- /* FIXME: #7951 */
GNUNET_assert (GNUNET_OK ==
- TALER_amount_set_zero (TMH_currency,
+ TALER_amount_set_zero (gorc->contract_amount.currency,
&gorc->deposits_total));
GNUNET_assert (GNUNET_OK ==
- TALER_amount_set_zero (TMH_currency,
+ TALER_amount_set_zero (gorc->contract_amount.currency,
&gorc->deposit_fees_total));
qs = TMH_db->lookup_transfer_details_by_order (TMH_db->cls,
gorc->order_serial,
@@ -1359,6 +1429,14 @@ TMH_private_get_orders_ID (const struct TMH_RequestHandler *rh,
TALER_EC_GENERIC_DB_FETCH_FAILED,
"transfer details");
}
+ if (gorc->deposit_currency_mismatch)
+ {
+ GNUNET_break (0);
+ return TALER_MHD_reply_with_error (connection,
+ MHD_HTTP_INTERNAL_SERVER_ERROR,
+ TALER_EC_GENERIC_DB_FETCH_FAILED,
+ "deposits in different currency than original order price");
+ }
if (! wired)
{