diff options
Diffstat (limited to 'src/backend/taler-merchant-httpd_private-get-orders.c')
-rw-r--r-- | src/backend/taler-merchant-httpd_private-get-orders.c | 46 |
1 files changed, 36 insertions, 10 deletions
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 @@ -225,6 +225,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; } |