commit 50959df54ff84280593f66453a998e83e81c75d8
parent d58649702ed3af027b441fbff9ad3f187bdabd68
Author: Marcello Stanisci <marcello.stanisci@inria.fr>
Date: Wed, 19 Oct 2016 22:51:00 +0200
fetch and test pay_deadline in /pay
Diffstat:
3 files changed, 20 insertions(+), 4 deletions(-)
diff --git a/src/backend/taler-merchant-httpd_contract.c b/src/backend/taler-merchant-httpd_contract.c
@@ -154,7 +154,7 @@ MH_handler_contract (struct TMH_RequestHandler *rh,
json_t *products;
struct GNUNET_TIME_Absolute timestamp;
struct GNUNET_TIME_Absolute refund_deadline;
- struct GNUNET_TIME_Absolute expiry;
+ struct GNUNET_TIME_Absolute pay_deadline;
struct GNUNET_JSON_Specification spec[] = {
TALER_JSON_spec_amount ("amount", &total),
TALER_JSON_spec_amount ("max_fee", &max_fee),
@@ -164,7 +164,7 @@ MH_handler_contract (struct TMH_RequestHandler *rh,
GNUNET_JSON_spec_json ("products", &products),
GNUNET_JSON_spec_absolute_time ("timestamp", ×tamp),
GNUNET_JSON_spec_absolute_time ("refund_deadline", &refund_deadline),
- GNUNET_JSON_spec_absolute_time ("expiry", &expiry),
+ GNUNET_JSON_spec_absolute_time ("pay_deadline", &pay_deadline),
GNUNET_JSON_spec_end()
};
diff --git a/src/backend/taler-merchant-httpd_pay.c b/src/backend/taler-merchant-httpd_pay.c
@@ -186,6 +186,11 @@ struct PayContext
struct GNUNET_TIME_Absolute refund_deadline;
/**
+ * Deadline for the customer to pay for this contract.
+ */
+ struct GNUNET_TIME_Absolute pay_deadline;
+
+ /**
* "H_contract" from @e root.
*/
struct GNUNET_HashCode h_contract;
@@ -854,6 +859,7 @@ MH_handler_pay (struct TMH_RequestHandler *rh,
struct PayContext *pc;
int res;
json_t *root;
+ struct GNUNET_TIME_Absolute now;
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"In handler for /pay.\n");
@@ -929,6 +935,7 @@ MH_handler_pay (struct TMH_RequestHandler *rh,
GNUNET_JSON_spec_fixed_auto ("merchant_sig", &merchant_sig),
GNUNET_JSON_spec_string ("exchange", &chosen_exchange),
GNUNET_JSON_spec_absolute_time ("refund_deadline", &pc->refund_deadline),
+ GNUNET_JSON_spec_absolute_time ("pay_deadline", &pc->pay_deadline),
GNUNET_JSON_spec_absolute_time ("timestamp", &pc->timestamp),
GNUNET_JSON_spec_uint64 ("transaction_id", &pc->transaction_id),
GNUNET_JSON_spec_end()
@@ -1134,6 +1141,15 @@ MH_handler_pay (struct TMH_RequestHandler *rh,
}
if (GNUNET_NO == pc->transaction_exits)
{
+ /* #4521 goes here: Check if the customer respects pay_deadline */
+ now = GNUNET_TIME_absolute_get ();
+ if (now.abs_value_us > pc->pay_deadline.abs_value_us)
+ {
+ /* Time expired, the customer cannot pay! */
+ return TMH_RESPONSE_reply_bad_request (connection,
+ "The time to pay for this contract has expired");
+ }
+
if (GNUNET_OK !=
db->store_transaction (db->cls,
pc->transaction_id,
diff --git a/src/lib/test_merchant_api.c b/src/lib/test_merchant_api.c
@@ -2176,7 +2176,7 @@ run (void *cls)
\"transaction_id\":1,\
\"timestamp\":\"\\/Date(42)\\/\",\
\"refund_deadline\":\"\\/Date(0)\\/\",\
- \"expiry\":\"\\/Date(999999999)\\/\",\
+ \"pay_deadline\":\"\\/Date(999999999)\\/\",\
\"amount\":{\"currency\":\"EUR\", \"value\":5, \"fraction\":0},\
\"summary\": \"merchant-lib testcase\",\
\"products\":\
@@ -2199,7 +2199,7 @@ run (void *cls)
\"transaction_id\":2,\
\"timestamp\":\"\\/Date(42)\\/\",\
\"refund_deadline\":\"\\/Date(0)\\/\",\
- \"expiry\":\"\\/Date(999999999)\\/\",\
+ \"pay_deadline\":\"\\/Date(999999999)\\/\",\
\"amount\":{\"currency\":\"EUR\", \"value\":5, \"fraction\":0},\
\"products\":\
[ {\"description\":\"ice cream\", \"value\":\"{EUR:5}\"} ] }" },