summaryrefslogtreecommitdiff
path: root/src/backend/taler-merchant-httpd_private-get-orders-ID.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2020-06-12 09:18:03 +0200
committerChristian Grothoff <christian@grothoff.org>2020-06-12 09:18:03 +0200
commite006e76011b134b3b8479f68ec64c5b3e19d0f9d (patch)
tree94f055172f1c5a0a9d0f9e75d3ec4be2b9a191ad /src/backend/taler-merchant-httpd_private-get-orders-ID.c
parent4836173de5fce860b18bf6fb23c0f8e0f76cee81 (diff)
downloadmerchant-e006e76011b134b3b8479f68ec64c5b3e19d0f9d.tar.gz
merchant-e006e76011b134b3b8479f68ec64c5b3e19d0f9d.tar.bz2
merchant-e006e76011b134b3b8479f68ec64c5b3e19d0f9d.zip
finish FIXMEs in private-get-orders-ID:
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.c76
1 files changed, 72 insertions, 4 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 d43c6500..5635d634 100644
--- a/src/backend/taler-merchant-httpd_private-get-orders-ID.c
+++ b/src/backend/taler-merchant-httpd_private-get-orders-ID.c
@@ -77,6 +77,16 @@ struct TransferQuery
struct GNUNET_HashCode h_wire;
/**
+ * Value deposited (including deposit fee).
+ */
+ struct TALER_Amount amount_with_fee;
+
+ /**
+ * Deposit fee paid for this coin.
+ */
+ struct TALER_Amount deposit_fee;
+
+ /**
* Public key of the coin this is about.
*/
struct TALER_CoinSpendPublicKeyP coin_pub;
@@ -176,6 +186,11 @@ struct GetOrderRequestContext
struct TALER_Amount deposits_total;
/**
+ * Total amount in deposit fees we paid for all coins.
+ */
+ struct TALER_Amount deposit_fees_total;
+
+ /**
* Total value of the coins that the exchange deposited into our bank
* account (confirmed or unconfirmed), including deposit fees.
*/
@@ -356,6 +371,17 @@ deposit_get_cb (void *cls,
GNUNET_free (tq);
return;
}
+ if (0 >
+ TALER_amount_add (&gorc->deposit_fees_total,
+ &gorc->deposit_fees_total,
+ &tq->deposit_fee))
+ {
+ gorc_resume (gorc,
+ TALER_EC_GET_ORDERS_AMOUNT_ARITHMETIC_FAILURE,
+ NULL);
+ GNUNET_free (tq);
+ return;
+ }
}
else
{
@@ -462,7 +488,8 @@ deposit_cb (void *cls,
tq);
tq->coin_pub = *coin_pub;
tq->h_wire = *h_wire;
- // FIXME: keep at least deposit_fee in 'tq'! needed later!
+ tq->amount_with_fee = *amount_with_fee;
+ tq->deposit_fee = *deposit_fee;
tq->fo = TMH_EXCHANGES_find_exchange (exchange_url,
NULL,
GNUNET_NO,
@@ -547,6 +574,23 @@ process_refunds_cb (void *cls,
refund_amount));
return;
}
+
+ /* For refunded coins, we are not charged deposit fees, so subtract those
+ again */
+ for (struct TransferQuery *tq = gorc->tq_head;
+ NULL != tq;
+ tq = tq->next)
+ {
+ if (0 ==
+ GNUNET_memcmp (&tq->coin_pub,
+ coin_pub))
+ {
+ GNUNET_assert (0 <=
+ TALER_amount_subtract (&gorc->deposit_fees_total,
+ &gorc->deposit_fees_total,
+ &tq->deposit_fee));
+ }
+ }
gorc->refund_amount = *refund_amount;
gorc->refunded = true;
}
@@ -731,7 +775,17 @@ TMH_private_get_orders_ID (const struct TMH_RequestHandler *rh,
TALER_EC_GET_ORDERS_DB_FETCH_CONTRACT_TERMS_ERROR,
"Merchant database error (contract terms corrupted)");
}
- // FIXME: sanity check on gorc->contract_amount.currency!
+ if (0 !=
+ strcasecmp (TMH_currency,
+ gorc->contract_amount.currency))
+ {
+ GNUNET_break (0);
+ return TALER_MHD_reply_with_error (
+ connection,
+ MHD_HTTP_INTERNAL_SERVER_ERROR,
+ TALER_EC_GET_ORDERS_DB_FETCH_CONTRACT_TERMS_ERROR,
+ "Merchant database error (contract terms in wrong currency)");
+ }
}
if (GNUNET_OK !=
TALER_JSON_hash (gorc->contract_terms,
@@ -896,6 +950,9 @@ TMH_private_get_orders_ID (const struct TMH_RequestHandler *rh,
GNUNET_assert (GNUNET_OK ==
TALER_amount_get_zero (TMH_currency,
&gorc->deposits_total));
+ GNUNET_assert (GNUNET_OK ==
+ TALER_amount_get_zero (TMH_currency,
+ &gorc->deposit_fees_total));
qs = TMH_db->lookup_transfer_details_by_order (TMH_db->cls,
gorc->order_serial,
&process_transfer_details,
@@ -926,11 +983,22 @@ TMH_private_get_orders_ID (const struct TMH_RequestHandler *rh,
TALER_EC_GET_ORDERS_CONTRACT_CONTENT_INVALID,
"Inconsistent contract terms in DB");
}
- // FIXME: what about fees?
- if (0 >= // FIXME: right cmp?
+ if (0 >
+ TALER_amount_subtract (&expect_total,
+ &expect_total,
+ &gorc->deposit_fees_total))
+ {
+ GNUNET_break (0);
+ return TALER_MHD_reply_with_error (connection,
+ MHD_HTTP_INTERNAL_SERVER_ERROR,
+ TALER_EC_GET_ORDERS_CONTRACT_CONTENT_INVALID,
+ "Inconsistent contract terms in DB");
+ }
+ if (0 >=
TALER_amount_cmp (&expect_total,
&gorc->deposits_total))
{
+ /* expect_total <= gorc->deposits_total: good: we got paid */
wired = true;
qs = TMH_db->mark_order_wired (TMH_db->cls,
gorc->order_serial);