From 6fa958a3cec156bc0eb89ddfae8b150d7400d2be Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Fri, 24 Nov 2023 09:51:53 +0100 Subject: address misc. FIXMEs --- .../taler-merchant-httpd_private-get-orders.c | 46 +++++++++++++++++----- .../taler-merchant-httpd_private-post-instances.c | 46 ++++++++++++++++------ 2 files changed, 69 insertions(+), 23 deletions(-) (limited to 'src/backend') diff --git a/src/backend/taler-merchant-httpd_private-get-orders.c b/src/backend/taler-merchant-httpd_private-get-orders.c index 0e0511cc..b55a5552 100644 --- a/src/backend/taler-merchant-httpd_private-get-orders.c +++ b/src/backend/taler-merchant-httpd_private-get-orders.c @@ -224,6 +224,23 @@ cleanup (void *ctx) } +/** + * Closure for #process_refunds_cb(). + */ +struct ProcessRefundsClosure +{ + /** + * Place where we accumulate the refunds. + */ + struct TALER_Amount total_refund_amount; + + /** + * Set to an error code if something goes wrong. + */ + enum TALER_ErrorCode ec; +}; + + /** * Function called with information about a refund. * It is responsible for summing up the refund amount. @@ -249,21 +266,20 @@ process_refunds_cb (void *cls, const struct TALER_Amount *refund_amount, bool pending) { - struct TALER_Amount *total_refund_amount = cls; + struct ProcessRefundsClosure *prc = cls; if (GNUNET_OK != - TALER_amount_cmp_currency (total_refund_amount, + TALER_amount_cmp_currency (&prc->total_refund_amount, refund_amount)) { /* Database error, refunds in mixed currency in DB. Not OK! */ - /* FIXME: we may want to return DB error to the client instead of just - ignoring the refund. */ + prc->ec = TALER_EC_GENERIC_DB_INVARIANT_FAILURE; GNUNET_break (0); return; } GNUNET_assert (0 <= - TALER_amount_add (total_refund_amount, - total_refund_amount, + TALER_amount_add (&prc->total_refund_amount, + &prc->total_refund_amount, refund_amount)); } @@ -395,16 +411,18 @@ add_order (void *cls, if (GNUNET_TIME_absolute_is_future (rd.abs_time) && paid) { - struct TALER_Amount refund_amount; + struct ProcessRefundsClosure prc = { + .ec = TALER_EC_NONE + }; GNUNET_assert (GNUNET_OK == TALER_amount_set_zero (order_amount.currency, - &refund_amount)); + &prc.total_refund_amount)); qs = TMH_db->lookup_refunds_detailed (TMH_db->cls, po->instance_id, &h_contract_terms, &process_refunds_cb, - &refund_amount); + &prc); if (0 > qs) { GNUNET_break (0); @@ -413,7 +431,15 @@ add_order (void *cls, GNUNET_free (order_id); return; } - if (0 > TALER_amount_cmp (&refund_amount, + if (TALER_EC_NONE != prc.ec) + { + GNUNET_break (0); + po->result = prc.ec; + json_decref (contract_terms); + GNUNET_free (order_id); + return; + } + if (0 > TALER_amount_cmp (&prc.total_refund_amount, &order_amount)) refundable = true; } diff --git a/src/backend/taler-merchant-httpd_private-post-instances.c b/src/backend/taler-merchant-httpd_private-post-instances.c index bc87ab41..396008c8 100644 --- a/src/backend/taler-merchant-httpd_private-post-instances.c +++ b/src/backend/taler-merchant-httpd_private-post-instances.c @@ -304,21 +304,41 @@ TMH_private_post_instances (const struct TMH_RequestHandler *rh, &mi->merchant_priv, &mi->settings, &mi->auth); - if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT != qs) + switch (qs) { - MHD_RESULT ret; + case GNUNET_DB_STATUS_HARD_ERROR: + { + MHD_RESULT ret; - TMH_db->rollback (TMH_db->cls); - if (GNUNET_DB_STATUS_SOFT_ERROR == qs) - goto retry; - GNUNET_break (0); // FIXME: distinguish better by qs - ret = TALER_MHD_reply_with_error (connection, - MHD_HTTP_CONFLICT, - TALER_EC_MERCHANT_PRIVATE_POST_INSTANCES_ALREADY_EXISTS, - is.id); - mi->rc = 1; - TMH_instance_decref (mi); - return ret; + TMH_db->rollback (TMH_db->cls); + GNUNET_break (0); + ret = TALER_MHD_reply_with_error (connection, + MHD_HTTP_INTERNAL_SERVER_ERROR, + TALER_EC_GENERIC_DB_STORE_FAILED, + is.id); + mi->rc = 1; + TMH_instance_decref (mi); + return ret; + } + case GNUNET_DB_STATUS_SOFT_ERROR: + goto retry; + case GNUNET_DB_STATUS_SUCCESS_NO_RESULTS: + { + MHD_RESULT ret; + + TMH_db->rollback (TMH_db->cls); + GNUNET_break (0); + ret = TALER_MHD_reply_with_error (connection, + MHD_HTTP_CONFLICT, + TALER_EC_MERCHANT_PRIVATE_POST_INSTANCES_ALREADY_EXISTS, + is.id); + mi->rc = 1; + TMH_instance_decref (mi); + return ret; + } + case GNUNET_DB_STATUS_SUCCESS_ONE_RESULT: + /* handled below */ + break; } qs = TMH_db->commit (TMH_db->cls); if (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS == qs) -- cgit v1.2.3