summaryrefslogtreecommitdiff
path: root/src
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
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')
-rw-r--r--src/backend/taler-merchant-httpd_private-get-orders.c45
-rw-r--r--src/include/taler_merchant_service.h5
-rw-r--r--src/lib/merchant_api_get_orders.c2
-rw-r--r--src/testing/test_merchant_api_twisted.c2
4 files changed, 45 insertions, 9 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");
}
}
diff --git a/src/include/taler_merchant_service.h b/src/include/taler_merchant_service.h
index 73901031..ca391e10 100644
--- a/src/include/taler_merchant_service.h
+++ b/src/include/taler_merchant_service.h
@@ -1253,6 +1253,11 @@ struct TALER_MERCHANT_OrderEntry
*/
bool refundable;
+ /**
+ * Whether the order has been paid.
+ */
+ bool paid;
+
};
diff --git a/src/lib/merchant_api_get_orders.c b/src/lib/merchant_api_get_orders.c
index c9585799..10989b69 100644
--- a/src/lib/merchant_api_get_orders.c
+++ b/src/lib/merchant_api_get_orders.c
@@ -96,6 +96,8 @@ parse_orders (const json_t *ia,
&ie->summary),
GNUNET_JSON_spec_bool ("refundable",
&ie->refundable),
+ GNUNET_JSON_spec_bool ("paid",
+ &ie->paid),
GNUNET_JSON_spec_end ()
};
diff --git a/src/testing/test_merchant_api_twisted.c b/src/testing/test_merchant_api_twisted.c
index 6b0ea36f..9adf9e27 100644
--- a/src/testing/test_merchant_api_twisted.c
+++ b/src/testing/test_merchant_api_twisted.c
@@ -369,7 +369,7 @@ run (void *cls,
TALER_TESTING_cmd_merchant_claim_order (
"claim-1-incorrect-claim-token",
twister_merchant_url,
- MHD_HTTP_CONFLICT,
+ MHD_HTTP_NOT_FOUND,
"create-proposal-1",
NULL),
TALER_TESTING_cmd_merchant_post_orders ("create-proposal-2",