diff options
author | Christian Grothoff <christian@grothoff.org> | 2016-10-20 15:09:18 +0200 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2016-10-20 15:09:18 +0200 |
commit | 8dbd57d61b5b6e02e9472a1d4c90597108b242fc (patch) | |
tree | e7ac41914a0c55cccb578a3fc5475cab14f6d96e | |
parent | f02036b3cb59135c5df2fda57627e42f344b5a96 (diff) | |
parent | 28542396565a8c3feb9b8a34be68410373022b6e (diff) |
Merge branch 'master' of git+ssh://taler.net/merchant
-rw-r--r-- | src/backend/taler-merchant-httpd_contract.c | 4 | ||||
-rw-r--r-- | src/backend/taler-merchant-httpd_pay.c | 23 | ||||
-rw-r--r-- | src/include/taler_merchant_service.h | 4 | ||||
-rw-r--r-- | src/lib/merchant_api_pay.c | 17 | ||||
-rw-r--r-- | src/lib/test_merchant_api.c | 8 |
5 files changed, 51 insertions, 5 deletions
diff --git a/src/backend/taler-merchant-httpd_contract.c b/src/backend/taler-merchant-httpd_contract.c index d2ded00b..0e8c9426 100644 --- a/src/backend/taler-merchant-httpd_contract.c +++ b/src/backend/taler-merchant-httpd_contract.c @@ -156,7 +156,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), @@ -166,7 +166,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 index 81f38a58..eeea4866 100644 --- 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; @@ -869,6 +874,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"); @@ -945,6 +951,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() @@ -1159,6 +1166,22 @@ 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, we don't accept this payment now! */ + const char *pd_str; + pd_str = GNUNET_STRINGS_absolute_time_to_string (pc->pay_deadline); + + GNUNET_log (GNUNET_ERROR_TYPE_WARNING, + "Attempt to get coins for expired contract. Deadline: '%s'\n", + pd_str); + + 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/include/taler_merchant_service.h b/src/include/taler_merchant_service.h index b61b9cb7..dac6c766 100644 --- a/src/include/taler_merchant_service.h +++ b/src/include/taler_merchant_service.h @@ -171,6 +171,7 @@ struct TALER_MERCHANT_PayCoin * @param merchant_sig signature from the merchant over the original contract * @param timestamp timestamp when the contract was finalized, must match approximately the current time of the merchant * @param refund_deadline date until which the merchant can issue a refund to the customer via the merchant (can be zero if refunds are not allowed) + * @param pay_deadline maximum time limit to pay for this contract * @param exchange_uri URI of the exchange that the coins belong to * @param num_coins number of coins used to pay * @param coins array of coins we use to pay @@ -191,6 +192,7 @@ TALER_MERCHANT_pay_wallet (struct GNUNET_CURL_Context *ctx, const struct TALER_MerchantSignatureP *merchant_sig, struct GNUNET_TIME_Absolute timestamp, struct GNUNET_TIME_Absolute refund_deadline, + struct GNUNET_TIME_Absolute pay_deadline, const struct GNUNET_HashCode *h_wire, const char *exchange_uri, unsigned int num_coins, @@ -258,6 +260,7 @@ struct TALER_MERCHANT_PaidCoin * @param transaction_id transaction id for the transaction between merchant and customer * @param merchant_sig the signature of the merchant over the original contract * @param refund_deadline date until which the merchant can issue a refund to the customer via the merchant (can be zero if refunds are not allowed) + * @param pay_deadline maximum time limit to pay for this contract * @param timestamp timestamp when the contract was finalized, must match approximately the current time of the merchant * @param wire_transfer_deadline date by which the merchant would like the exchange to execute the wire transfer (can be zero if there is no specific date desired by the frontend). If non-zero, must be larger than @a refund_deadline. * @param exchange_uri URI of the exchange that the coins belong to @@ -278,6 +281,7 @@ TALER_MERCHANT_pay_frontend (struct GNUNET_CURL_Context *ctx, uint64_t transaction_id, const struct TALER_MerchantSignatureP *merchant_sig, struct GNUNET_TIME_Absolute refund_deadline, + struct GNUNET_TIME_Absolute pay_deadline, struct GNUNET_TIME_Absolute timestamp, struct GNUNET_TIME_Absolute wire_transfer_deadline, const char *exchange_uri, diff --git a/src/lib/merchant_api_pay.c b/src/lib/merchant_api_pay.c index d65eb254..c2511169 100644 --- a/src/lib/merchant_api_pay.c +++ b/src/lib/merchant_api_pay.c @@ -263,6 +263,7 @@ handle_pay_finished (void *cls, * @param transaction_id transaction id for the transaction between merchant and customer * @param merchant_pub the public key of the merchant (used to identify the merchant for refund requests) * @param refund_deadline date until which the merchant can issue a refund to the customer via the merchant (can be zero if refunds are not allowed) + * @param pay_deadline maximum time limit to pay for this contract * @param exchange_uri URI of the exchange that the coins belong to * @param num_coins number of coins used to pay * @param coins array of coins we use to pay @@ -285,6 +286,7 @@ TALER_MERCHANT_pay_wallet (struct GNUNET_CURL_Context *ctx, const struct TALER_MerchantSignatureP *merchant_sig, struct GNUNET_TIME_Absolute timestamp, struct GNUNET_TIME_Absolute refund_deadline, + struct GNUNET_TIME_Absolute pay_deadline, const struct GNUNET_HashCode *h_wire, const char *exchange_uri, unsigned int num_coins, @@ -296,6 +298,10 @@ TALER_MERCHANT_pay_wallet (struct GNUNET_CURL_Context *ctx, struct TALER_DepositRequestPS dr; struct TALER_MERCHANT_PaidCoin pc[num_coins]; + (void) GNUNET_TIME_round_abs (×tamp); + (void) GNUNET_TIME_round_abs (&pay_deadline); + (void) GNUNET_TIME_round_abs (&refund_deadline); + dr.purpose.purpose = htonl (TALER_SIGNATURE_WALLET_COIN_DEPOSIT); dr.purpose.size = htonl (sizeof (struct TALER_DepositRequestPS)); dr.h_contract = *h_contract; @@ -346,6 +352,7 @@ TALER_MERCHANT_pay_wallet (struct GNUNET_CURL_Context *ctx, transaction_id, merchant_sig, refund_deadline, + pay_deadline, timestamp, GNUNET_TIME_UNIT_ZERO_ABS, exchange_uri, @@ -369,6 +376,7 @@ TALER_MERCHANT_pay_wallet (struct GNUNET_CURL_Context *ctx, * @param timestamp timestamp when the contract was finalized, must match approximately the current time of the merchant * @param transaction_id transaction id for the transaction between merchant and customer * @param refund_deadline date until which the merchant can issue a refund to the customer via the merchant (can be zero if refunds are not allowed) + * @param deadline to pay for this contract * @param wire_transfer_deadline date by which the merchant would like the exchange to execute the wire transfer (can be zero if there is no specific date desired by the frontend). If non-zero, must be larger than @a refund_deadline. * @param exchange_uri URI of the exchange that the coins belong to * @param num_coins number of coins used to pay @@ -390,6 +398,7 @@ TALER_MERCHANT_pay_frontend (struct GNUNET_CURL_Context *ctx, uint64_t transaction_id, const struct TALER_MerchantSignatureP *merchant_sig, struct GNUNET_TIME_Absolute refund_deadline, + struct GNUNET_TIME_Absolute pay_deadline, struct GNUNET_TIME_Absolute timestamp, struct GNUNET_TIME_Absolute wire_transfer_deadline, const char *exchange_uri, @@ -406,6 +415,10 @@ TALER_MERCHANT_pay_frontend (struct GNUNET_CURL_Context *ctx, struct TALER_Amount total_amount; unsigned int i; + (void) GNUNET_TIME_round_abs (×tamp); + (void) GNUNET_TIME_round_abs (&refund_deadline); + (void) GNUNET_TIME_round_abs (&wire_transfer_deadline); + if (GNUNET_YES != TALER_amount_cmp_currency (amount, max_fee)) @@ -550,13 +563,15 @@ TALER_MERCHANT_pay_frontend (struct GNUNET_CURL_Context *ctx, pay_obj = json_pack ("{s:o," /* H_contract */ " s:I, s:o," /* transaction id, timestamp */ - " s:o, s:s," /* refund_deadline, exchange */ + " s:o, s:o," /* refund_deadline, pay_deadline */ + " s:s," /* exchange */ " s:o, s:o," /* coins, max_fee */ " s:o, s:o}",/* amount, signature */ "H_contract", GNUNET_JSON_from_data_auto (h_contract), "transaction_id", (json_int_t) transaction_id, "timestamp", GNUNET_JSON_from_time_abs (timestamp), "refund_deadline", GNUNET_JSON_from_time_abs (refund_deadline), + "pay_deadline", GNUNET_JSON_from_time_abs (pay_deadline), "exchange", exchange_uri, "coins", j_coins, "max_fee", TALER_JSON_from_amount (max_fee), diff --git a/src/lib/test_merchant_api.c b/src/lib/test_merchant_api.c index 7cdbc7d3..60762062 100644 --- a/src/lib/test_merchant_api.c +++ b/src/lib/test_merchant_api.c @@ -1661,6 +1661,7 @@ interpreter_run (void *cls) struct TALER_MERCHANT_PayCoin pc; uint64_t transaction_id; struct GNUNET_TIME_Absolute refund_deadline; + struct GNUNET_TIME_Absolute pay_deadline; struct GNUNET_TIME_Absolute timestamp; struct GNUNET_HashCode h_wire; struct TALER_MerchantPublicKeyP merchant_pub; @@ -1682,6 +1683,7 @@ interpreter_run (void *cls) struct GNUNET_JSON_Specification spec[] = { GNUNET_JSON_spec_uint64 ("transaction_id", &transaction_id), GNUNET_JSON_spec_absolute_time ("refund_deadline", &refund_deadline), + GNUNET_JSON_spec_absolute_time ("pay_deadline", &pay_deadline), GNUNET_JSON_spec_absolute_time ("timestamp", ×tamp), GNUNET_JSON_spec_fixed_auto ("merchant_pub", &merchant_pub), GNUNET_JSON_spec_fixed_auto ("H_wire", &h_wire), @@ -1765,6 +1767,7 @@ interpreter_run (void *cls) &merchant_sig, timestamp, refund_deadline, + pay_deadline, &h_wire, EXCHANGE_URI, 1 /* num_coins */, @@ -2176,8 +2179,9 @@ run (void *cls) \"transaction_id\":1,\ \"timestamp\":\"\\/Date(42)\\/\",\ \"refund_deadline\":\"\\/Date(0)\\/\",\ - \"expiry\":\"\\/Date(999999999)\\/\",\ + \"pay_deadline\":\"\\/Date(9999999999)\\/\",\ \"amount\":{\"currency\":\"EUR\", \"value\":5, \"fraction\":0},\ + \"summary\": \"merchant-lib testcase\",\ \"products\":\ [ {\"description\":\"ice cream\", \"value\":\"{EUR:5}\"} ] }"}, { .oc = OC_PAY, @@ -2198,7 +2202,7 @@ run (void *cls) \"transaction_id\":2,\ \"timestamp\":\"\\/Date(42)\\/\",\ \"refund_deadline\":\"\\/Date(0)\\/\",\ - \"expiry\":\"\\/Date(999999999)\\/\",\ + \"pay_deadline\":\"\\/Date(9999999999)\\/\",\ \"amount\":{\"currency\":\"EUR\", \"value\":5, \"fraction\":0},\ \"products\":\ [ {\"description\":\"ice cream\", \"value\":\"{EUR:5}\"} ] }" }, |