summaryrefslogtreecommitdiff
path: root/src/backend/taler-merchant-httpd_private-get-orders.c
diff options
context:
space:
mode:
authorJonathan Buchanan <jonathan.russ.buchanan@gmail.com>2020-07-30 17:35:50 -0400
committerJonathan Buchanan <jonathan.russ.buchanan@gmail.com>2020-07-30 17:35:50 -0400
commit034765718ee18166f634ba7dc996a159f82e76a6 (patch)
treeeb36a9cf92403369fc765674ada94eb00020d487 /src/backend/taler-merchant-httpd_private-get-orders.c
parent4cc9a8d32bd76d00a382b33ee4fc922257a4751c (diff)
downloadmerchant-034765718ee18166f634ba7dc996a159f82e76a6.tar.gz
merchant-034765718ee18166f634ba7dc996a159f82e76a6.tar.bz2
merchant-034765718ee18166f634ba7dc996a159f82e76a6.zip
add 'paid' to GET /private/orders response entries
Diffstat (limited to 'src/backend/taler-merchant-httpd_private-get-orders.c')
-rw-r--r--src/backend/taler-merchant-httpd_private-get-orders.c45
1 files changed, 37 insertions, 8 deletions
diff --git a/src/backend/taler-merchant-httpd_private-get-orders.c b/src/backend/taler-merchant-httpd_private-get-orders.c
index c14569da..d890fa83 100644
--- a/src/backend/taler-merchant-httpd_private-get-orders.c
+++ b/src/backend/taler-merchant-httpd_private-get-orders.c
@@ -42,6 +42,11 @@ struct AddOrderState
* The result after adding the orders (0 for okay, anything else for an error).
*/
int result;
+
+ /**
+ * In the case of an error, what message to respond with.
+ */
+ const char *ec_msg;
};
@@ -253,6 +258,7 @@ add_order (void *cls,
{
struct AddOrderState *aos = cls;
json_t *contract_terms;
+ struct GNUNET_HashCode h_contract_terms;
enum GNUNET_DB_QueryStatus qs =
TMH_db->lookup_order (TMH_db->cls,
aos->instance_id,
@@ -260,19 +266,38 @@ add_order (void *cls,
NULL,
&contract_terms);
bool refundable = false;
+ bool paid;
if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT != qs)
{
aos->result = 1;
+ aos->ec_msg = "failed to lookup order in database";
json_decref (contract_terms);
return;
}
{
+ qs = TMH_db->lookup_order_status (TMH_db->cls,
+ aos->instance_id,
+ order_id,
+ &h_contract_terms,
+ &paid);
+ /* qs == 0: contract terms don't exist, so the order cannot be paid. */
+ if (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS == qs)
+ paid = false;
+ if (qs < 0)
+ {
+ aos->result = 1;
+ aos->ec_msg = "failed to lookup order status in database";
+ json_decref (contract_terms);
+ return;
+ }
+ }
+
+ {
struct TALER_Amount order_amount;
struct GNUNET_TIME_Absolute rd;
struct GNUNET_TIME_Absolute now = GNUNET_TIME_absolute_get ();
- struct GNUNET_HashCode h_contract_terms;
struct GNUNET_JSON_Specification spec[] = {
TALER_JSON_spec_amount ("amount",
@@ -288,18 +313,17 @@ add_order (void *cls,
NULL, NULL))
{
aos->result = 1;
+ aos->ec_msg = "failed to parse order contract terms";
json_decref (contract_terms);
return;
}
- if (now.abs_value_us <= rd.abs_value_us)
+ if ((now.abs_value_us <= rd.abs_value_us) &&
+ paid)
{
struct TALER_Amount refund_amount;
GNUNET_assert (GNUNET_OK ==
- TALER_JSON_contract_hash (contract_terms,
- &h_contract_terms));
- GNUNET_assert (GNUNET_OK ==
TALER_amount_get_zero (TMH_currency,
&refund_amount));
qs = TMH_db->lookup_refunds_detailed (TMH_db->cls,
@@ -310,6 +334,7 @@ add_order (void *cls,
if (0 > qs)
{
aos->result = 1;
+ aos->ec_msg = "failed to lookup order refunds in database";
json_decref (contract_terms);
return;
}
@@ -323,7 +348,7 @@ add_order (void *cls,
json_array_append_new (
aos->pa,
json_pack (
- "{s:s, s:I, s:o, s:O, s:O, s:b}",
+ "{s:s, s:I, s:o, s:O, s:O, s:b, s:b}",
"order_id",
order_id,
"row_id",
@@ -337,7 +362,9 @@ add_order (void *cls,
json_object_get (contract_terms,
"summary"),
"refundable",
- refundable)));
+ refundable,
+ "paid",
+ paid)));
json_decref (contract_terms);
}
@@ -438,7 +465,7 @@ TMH_private_get_orders (const struct TMH_RequestHandler *rh,
return TALER_MHD_reply_with_error (connection,
MHD_HTTP_INTERNAL_SERVER_ERROR,
TALER_EC_ORDERS_GET_DB_LOOKUP_ERROR,
- "failed to lookup orders in database");
+ aos->ec_msg);
}
return TALER_MHD_reply_json_pack (connection,
MHD_HTTP_OK,
@@ -598,6 +625,8 @@ TMH_private_get_orders (const struct TMH_RequestHandler *rh,
return TALER_MHD_reply_with_error (connection,
MHD_HTTP_INTERNAL_SERVER_ERROR,
TALER_EC_ORDERS_GET_DB_LOOKUP_ERROR,
+ 0 != aos->result ?
+ aos->ec_msg :
"failed to lookup orders in database");
}
}