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-09 12:00:15 +0200
committerChristian Grothoff <christian@grothoff.org>2020-06-09 12:00:15 +0200
commitb5b3f8adc175519530ee17137e532393727682ca (patch)
treed9d5f3ed5f73a76bd8d312abbc8a69312ffde18a /src/backend/taler-merchant-httpd_private-get-orders-ID.c
parentfcf60499c3ab3e23c458cecdf8f51dd7cf5e16d3 (diff)
downloadmerchant-b5b3f8adc175519530ee17137e532393727682ca.tar.gz
merchant-b5b3f8adc175519530ee17137e532393727682ca.tar.bz2
merchant-b5b3f8adc175519530ee17137e532393727682ca.zip
start to build 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.c168
1 files changed, 76 insertions, 92 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 78fe4e19..d43c6500 100644
--- a/src/backend/taler-merchant-httpd_private-get-orders-ID.c
+++ b/src/backend/taler-merchant-httpd_private-get-orders-ID.c
@@ -21,8 +21,10 @@
*/
#include "platform.h"
#include "taler-merchant-httpd_private-get-orders-ID.h"
+#include "taler-merchant-httpd_get-orders-ID.h"
#include <taler/taler_json_lib.h>
#include "taler-merchant-httpd_mhd.h"
+#include "taler-merchant-httpd_exchanges.h"
/**
* How long do we wait on the exchange?
@@ -270,20 +272,16 @@ gorc_resume (struct GetOrderRequestContext *gorc,
tq->dgh = NULL;
}
}
- GNUNET_CONTAINER_DLL_remove (gorc_head,
- gorc_tail,
- gorc);
- MHD_resume_connection (gorc->sc.connection);
- GNUNET_CONTAINER_DLL_remove (gorc_head,
- gorc_tail,
- gorc);
gorc->wire_ec = ec;
if (NULL != exchange_hr)
{
gorc->exchange_hc = exchange_hr->http_status;
- gorc->exchange_ec = exchange_hr->error_code;
+ gorc->exchange_ec = exchange_hr->ec;
}
- MHD_resume_connection (gorc->sc.connection);
+ GNUNET_CONTAINER_DLL_remove (gorc_head,
+ gorc_tail,
+ gorc);
+ MHD_resume_connection (gorc->sc.con);
}
@@ -300,7 +298,7 @@ exchange_timeout_cb (void *cls)
gorc->tt = NULL;
gorc_resume (gorc,
- 42, // FIXME: EC
+ TALER_EC_GET_ORDERS_EXCHANGE_TIMEOUT,
NULL);
}
@@ -326,7 +324,7 @@ deposit_get_cb (void *cls,
if (NULL == dd)
{
gorc_resume (gorc,
- 42, // FIXME: EC
+ TALER_EC_GET_ORDERS_EXCHANGE_TRACKING_FAILURE,
hr);
GNUNET_free (tq);
return;
@@ -341,7 +339,7 @@ deposit_get_cb (void *cls,
if (qs < 0)
{
gorc_resume (gorc,
- 42, // FIXME: EC
+ TALER_EC_GET_ORDERS_DB_STORE_TRACKING_FAILURE,
NULL);
GNUNET_free (tq);
return;
@@ -353,20 +351,7 @@ deposit_get_cb (void *cls,
&dd->coin_contribution))
{
gorc_resume (gorc,
- 42, // FIXME: EC
- NULL);
- GNUNET_free (tq);
- return;
- }
- /* Compute total amount including deposit fees (so how much
- of the total deposit was properly paid by the exchange) */
- if (0 >
- TALER_amount_add (&gorc->value_total,
- &gorc->value_total,
- &tq->coin_value))
- {
- gorc_resume (gorc,
- 42, // FIXME: EC
+ TALER_EC_GET_ORDERS_AMOUNT_ARITHMETIC_FAILURE,
NULL);
GNUNET_free (tq);
return;
@@ -417,16 +402,16 @@ exchange_found_cb (void *cls,
tq);
GNUNET_free (tq);
gorc_resume (gorc,
- 42, // FIXME: EC!
+ TALER_EC_GET_ORDERS_EXCHANGE_LOOKUP_FAILURE,
hr);
return;
}
tq->dgh = TALER_EXCHANGE_deposits_get (eh,
- &gorc->hc->instance.merchant_priv,
+ &gorc->hc->instance->merchant_priv,
&tq->h_wire,
&gorc->h_contract_terms,
&tq->coin_pub,
- &deposit_get_callback,
+ &deposit_get_cb,
tq);
if (NULL == tq->dgh)
{
@@ -435,7 +420,7 @@ exchange_found_cb (void *cls,
tq);
GNUNET_free (tq);
gorc_resume (gorc,
- 42,
+ TALER_EC_GET_ORDERS_EXCHANGE_REQUEST_FAILURE,
NULL);
}
}
@@ -452,6 +437,8 @@ exchange_found_cb (void *cls,
* @param cls a `struct GetOrderRequestContext`
* @param deposit_serial identifies the deposit operation
* @param exchange_url URL of the exchange that issued @a coin_pub
+ * @param amount_with_fee amount the exchange will deposit for this coin
+ * @param deposit_fee fee the exchange will charge for this coin
* @param h_wire hash of the merchant's wire account into which the deposit was made
* @param coin_pub public key of the deposited coin
*/
@@ -460,6 +447,8 @@ deposit_cb (void *cls,
uint64_t deposit_serial,
const char *exchange_url,
const struct GNUNET_HashCode *h_wire,
+ const struct TALER_Amount *amount_with_fee,
+ const struct TALER_Amount *deposit_fee,
const struct TALER_CoinSpendPublicKeyP *coin_pub)
{
struct GetOrderRequestContext *gorc = cls;
@@ -473,15 +462,16 @@ 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->fo = TMH_EXCHANGES_find_exchange (exchange_url,
NULL,
GNUNET_NO,
&exchange_found_cb,
tq);
- if (NULL = tq->fo)
+ if (NULL == tq->fo)
{
gorc_resume (gorc,
- 42, // FIXME: EC
+ TALER_EC_GET_ORDERS_EXCHANGE_LOOKUP_FAILURE,
NULL);
}
}
@@ -504,7 +494,6 @@ gorc_cleanup (void *cls)
if (NULL != gorc->refund_details)
json_decref (gorc->refund_details);
GNUNET_assert (NULL == gorc->tt);
- GNUNET_assert (NULL == gorc->fo);
GNUNET_free (gorc);
}
@@ -537,19 +526,19 @@ process_refunds_cb (void *cls,
if (NULL == gorc->refund_details)
{
- gorc->refund_details = json_array_new ();
+ gorc->refund_details = json_array ();
GNUNET_assert (NULL != gorc->refund_details);
}
GNUNET_assert (0 ==
- json_array_append_new (json_pack ("{s:o, s:o, s:s}",
- "amount",
- TALER_JSON_from_amount (
- refund_amount),
- "timestamp",
- GNUNET_JSON_from_time_absolute (
- timestamp),
- "reason",
- reason)));
+ json_array_append_new (
+ gorc->refund_details,
+ json_pack ("{s:o, s:o, s:s}",
+ "amount",
+ TALER_JSON_from_amount (refund_amount),
+ "timestamp",
+ GNUNET_JSON_from_time_abs (timestamp),
+ "reason",
+ reason)));
if (gorc->refunded)
{
GNUNET_assert (0 <=
@@ -608,7 +597,7 @@ process_transfer_details (void *cls,
"amount",
TALER_JSON_from_amount (&wired),
"execution_time",
- GNUNET_JSON_from_time_absolute (execution_time),
+ GNUNET_JSON_from_time_abs (execution_time),
"confirmed",
transfer_confirmed)));
}
@@ -695,7 +684,7 @@ TMH_private_get_orders_ID (const struct TMH_RequestHandler *rh,
TMH_db->preflight (TMH_db->cls);
qs = TMH_db->lookup_contract_terms (TMH_db->cls,
- hc->instance.settings->id,
+ hc->instance->settings.id,
hc->infix,
&gorc->contract_terms,
&gorc->order_serial);
@@ -708,7 +697,7 @@ TMH_private_get_orders_ID (const struct TMH_RequestHandler *rh,
GNUNET_break (GNUNET_DB_STATUS_HARD_ERROR == qs);
return TALER_MHD_reply_with_error (connection,
MHD_HTTP_INTERNAL_SERVER_ERROR,
- TALER_EC_CHECK_PAYMENT_DB_FETCH_CONTRACT_TERMS_ERROR,
+ TALER_EC_GET_ORDERS_DB_FETCH_CONTRACT_TERMS_ERROR,
"db error fetching contract terms");
}
if (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS == qs)
@@ -716,7 +705,7 @@ TMH_private_get_orders_ID (const struct TMH_RequestHandler *rh,
GNUNET_break_op (0);
return TALER_MHD_reply_with_error (connection,
MHD_HTTP_NOT_FOUND,
- TALER_EC_ORDERS_GET_ORDER_NOT_FOUND,
+ TALER_EC_GET_ORDERS_ORDER_NOT_FOUND,
"Did not find order in DB");
}
@@ -739,7 +728,7 @@ TMH_private_get_orders_ID (const struct TMH_RequestHandler *rh,
return TALER_MHD_reply_with_error (
connection,
MHD_HTTP_INTERNAL_SERVER_ERROR,
- TALER_EC_CHECK_PAYMENT_DB_FETCH_CONTRACT_TERMS_ERROR,
+ TALER_EC_GET_ORDERS_DB_FETCH_CONTRACT_TERMS_ERROR,
"Merchant database error (contract terms corrupted)");
}
// FIXME: sanity check on gorc->contract_amount.currency!
@@ -752,7 +741,7 @@ TMH_private_get_orders_ID (const struct TMH_RequestHandler *rh,
return (MHD_YES ==
TALER_MHD_reply_with_error (connection,
MHD_HTTP_INTERNAL_SERVER_ERROR,
- TALER_EC_ORDERS_GET_FAILED_COMPUTE_PROPOSAL_HASH,
+ TALER_EC_GET_ORDERS_FAILED_COMPUTE_PROPOSAL_HASH,
"Failed to hash contract terms"))
? GNUNET_NO
: GNUNET_SYSERR;
@@ -774,7 +763,7 @@ TMH_private_get_orders_ID (const struct TMH_RequestHandler *rh,
GNUNET_break (GNUNET_DB_STATUS_HARD_ERROR == qs);
return TALER_MHD_reply_with_error (connection,
MHD_HTTP_INTERNAL_SERVER_ERROR,
- TALER_EC_CHECK_PAYMENT_DB_FETCH_PAYMENT_STATUS,
+ TALER_EC_GET_ORDERS_DB_FETCH_PAYMENT_STATUS,
"DB error fetching payment status");
}
if (! paid)
@@ -793,7 +782,7 @@ TMH_private_get_orders_ID (const struct TMH_RequestHandler *rh,
GNUNET_break (GNUNET_DB_STATUS_HARD_ERROR == qs);
return TALER_MHD_reply_with_error (connection,
MHD_HTTP_INTERNAL_SERVER_ERROR,
- TALER_EC_CHECK_PAYMENT_DB_FETCH_PAYMENT_STATUS,
+ TALER_EC_GET_ORDERS_DB_FETCH_PAYMENT_STATUS,
"DB error fetching payment status");
}
if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT == qs)
@@ -806,7 +795,7 @@ TMH_private_get_orders_ID (const struct TMH_RequestHandler *rh,
taler_pay_uri = TMH_make_taler_pay_uri (connection,
hc->infix,
gorc->session_id,
- hc->instance.settings->id);
+ hc->instance->settings.id);
ret = TALER_MHD_reply_json_pack (connection,
MHD_HTTP_OK,
"{s:s, s:b, s:s}",
@@ -828,11 +817,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 */
- TMH_db->lookup_deposits (TMH_db->cls,
- gorc->order_serial,
- &deposit_cb,
- gorc);
- if (NULL != gorc->tq)
+ TMH_db->lookup_deposits_by_order (TMH_db->cls,
+ gorc->order_serial,
+ &deposit_cb,
+ gorc);
+ if (NULL != gorc->tq_head)
{
GNUNET_CONTAINER_DLL_insert (gorc_head,
gorc_tail,
@@ -846,7 +835,7 @@ TMH_private_get_orders_ID (const struct TMH_RequestHandler *rh,
}
if ( (! paid) &&
- (0 != gorc.sc.long_poll_timeout.abs_value_us) )
+ (0 != gorc->sc.long_poll_timeout.abs_value_us) )
{
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"Suspending GET /private/orders/%s\n",
@@ -867,7 +856,7 @@ TMH_private_get_orders_ID (const struct TMH_RequestHandler *rh,
taler_pay_uri = TMH_make_taler_pay_uri (connection,
hc->infix,
gorc->session_id,
- hc->instance.settings->id);
+ hc->instance->settings.id);
ret = TALER_MHD_reply_json_pack (connection,
MHD_HTTP_OK,
"{s:s, s:b}",
@@ -884,8 +873,8 @@ TMH_private_get_orders_ID (const struct TMH_RequestHandler *rh,
/* Accumulate refunds, if any. */
{
qs = TMH_db->lookup_refunds_detailed (TMH_db->cls,
- hc->instance.settings->id,
- &h_contract_terms,
+ hc->instance->settings.id,
+ &gorc->h_contract_terms,
&process_refunds_cb,
gorc);
}
@@ -894,7 +883,7 @@ TMH_private_get_orders_ID (const struct TMH_RequestHandler *rh,
GNUNET_break (0);
return TALER_MHD_reply_with_error (connection,
MHD_HTTP_INTERNAL_SERVER_ERROR,
- TALER_EC_ORDERS_GET_DB_FETCH_TRANSACTION_ERROR,
+ TALER_EC_GET_ORDERS_DB_FETCH_TRANSACTION_ERROR,
"Merchant database error");
}
@@ -902,13 +891,11 @@ TMH_private_get_orders_ID (const struct TMH_RequestHandler *rh,
{
MHD_RESULT ret;
- gorc->wire_details = json_array_new ();
+ gorc->wire_details = json_array ();
GNUNET_assert (NULL != gorc->wire_details);
- // FIXME: assert on return codes:
- TALER_amount_get_zero (&gorc->value_total,
- TMH_currency);
- TALER_amount_get_zero (&gorc->deposits_total,
- TMH_currency);
+ GNUNET_assert (GNUNET_OK ==
+ TALER_amount_get_zero (TMH_currency,
+ &gorc->deposits_total));
qs = TMH_db->lookup_transfer_details_by_order (TMH_db->cls,
gorc->order_serial,
&process_transfer_details,
@@ -936,12 +923,13 @@ TMH_private_get_orders_ID (const struct TMH_RequestHandler *rh,
GNUNET_break (0);
return TALER_MHD_reply_with_error (connection,
MHD_HTTP_INTERNAL_SERVER_ERROR,
- 42, // FIXME: EC
+ TALER_EC_GET_ORDERS_CONTRACT_CONTENT_INVALID,
"Inconsistent contract terms in DB");
}
+ // FIXME: what about fees?
if (0 >= // FIXME: right cmp?
TALER_amount_cmp (&expect_total,
- &gorc->value_total))
+ &gorc->deposits_total))
{
wired = true;
qs = TMH_db->mark_order_wired (TMH_db->cls,
@@ -952,36 +940,32 @@ TMH_private_get_orders_ID (const struct TMH_RequestHandler *rh,
ret = TALER_MHD_reply_json_pack (connection,
MHD_HTTP_OK,
- "{s:I, s:I, s:I, s:o, s:o,"
- " s:O, s:b, s:b, s:o?, s:o?, s:o?}",
+ "{s:I, s:I, s:I, s:o, s:O,"
+ " s:b, s:b, s:o?, s:o?, s:o?}",
"wire_ec",
(json_int_t) gorc->wire_ec,
"exchange_ec",
(json_int_t) gorc->exchange_ec,
"exchange_hc",
(json_int_t) gorc->exchange_hc,
- "transfer_value_total",
- TALER_JSON_from_amount (
- &gorc->value_total)
"deposit_total",
TALER_JSON_from_amount (
- &gorc->deposits_total)
- : NULL,
- "contract_terms",
- gorc->contract_terms,
- "paid",
- true,
- "refunded",
- gorc->refunded,
- "refund_amount",
- (gorc->refunded)
- ? TALER_JSON_from_amount (
- &gorc->refund_amount)
- : NULL,
- "wire_details",
- gorc->wire_details,
- "refund_details",
- gorc->refund_details);
+ &gorc->deposits_total),
+ "contract_terms",
+ gorc->contract_terms,
+ "paid",
+ true,
+ "refunded",
+ gorc->refunded,
+ "refund_amount",
+ (gorc->refunded)
+ ? TALER_JSON_from_amount (
+ &gorc->refund_amount)
+ : NULL,
+ "wire_details",
+ gorc->wire_details,
+ "refund_details",
+ gorc->refund_details);
gorc->wire_details = NULL;
gorc->refund_details = NULL;
return ret;