[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[taler-merchant] 194/277: finish FIXMEs in private-get-orders-ID:
From: |
gnunet |
Subject: |
[taler-merchant] 194/277: finish FIXMEs in private-get-orders-ID: |
Date: |
Sun, 05 Jul 2020 20:51:47 +0200 |
This is an automated email from the git hooks/post-receive script.
grothoff pushed a commit to branch master
in repository merchant.
commit e006e76011b134b3b8479f68ec64c5b3e19d0f9d
Author: Christian Grothoff <christian@grothoff.org>
AuthorDate: Fri Jun 12 09:18:03 2020 +0200
finish FIXMEs in private-get-orders-ID:
---
.../taler-merchant-httpd_private-get-orders-ID.c | 76 ++++++++++++++++++++--
1 file 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 d43c650..5635d63 100644
--- a/src/backend/taler-merchant-httpd_private-get-orders-ID.c
+++ b/src/backend/taler-merchant-httpd_private-get-orders-ID.c
@@ -76,6 +76,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.
*/
@@ -175,6 +185,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);
--
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.
- [taler-merchant] 177/277: wrote method for delete reserve, (continued)
- [taler-merchant] 177/277: wrote method for delete reserve, gnunet, 2020/07/05
- [taler-merchant] 184/277: work on implementing GET /private/orders/ID, gnunet, 2020/07/05
- [taler-merchant] 183/277: work on getting TransactionWireTransfer reply built, gnunet, 2020/07/05
- [taler-merchant] 180/277: more work on private-get-orders-ID, gnunet, 2020/07/05
- [taler-merchant] 186/277: start to build get-orders-ID, gnunet, 2020/07/05
- [taler-merchant] 181/277: more test cleanup and some lookup_orders filter tests, gnunet, 2020/07/05
- [taler-merchant] 192/277: need #include, gnunet, 2020/07/05
- [taler-merchant] 197/277: remove from waiting list when resuming, gnunet, 2020/07/05
- [taler-merchant] 196/277: do not forget to kick MHD, gnunet, 2020/07/05
- [taler-merchant] 189/277: created lookup_tips method for backenddb, gnunet, 2020/07/05
- [taler-merchant] 194/277: finish FIXMEs in private-get-orders-ID:,
gnunet <=
- [taler-merchant] 195/277: remark, gnunet, 2020/07/05
- [taler-merchant] 182/277: More complete tests for deposits, transfers, refund, lookup orders, gnunet, 2020/07/05
- [taler-merchant] 187/277: Merge branch 'protocolV1' of git+ssh://git.taler.net/merchant into protocolV1, gnunet, 2020/07/05
- [taler-merchant] 190/277: implementation of GET /private/tips, gnunet, 2020/07/05
- [taler-merchant] 191/277: test/fix for POST /private/reserves, gnunet, 2020/07/05
- [taler-merchant] 193/277: Merge branch 'protocolV1' of git+ssh://git.taler.net/merchant into protocolV1, gnunet, 2020/07/05
- [taler-merchant] 198/277: enable handler, gnunet, 2020/07/05
- [taler-merchant] 200/277: test with MHD error, gnunet, 2020/07/05
- [taler-merchant] 201/277: fix crash, gnunet, 2020/07/05
- [taler-merchant] 205/277: fixed authorize tip and tests for GET /private/tips, gnunet, 2020/07/05