diff options
author | Christian Grothoff <christian@grothoff.org> | 2019-11-07 22:01:22 +0100 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2019-11-07 22:01:22 +0100 |
commit | edfc078b18effea43865a093df69e5fcb1c3475d (patch) | |
tree | 337364b4716d51ddf4b0acbd2758aaf805ba66a4 | |
parent | add872255341a80476cac82a43a41dfba8b05d10 (diff) | |
download | merchant-edfc078b18effea43865a093df69e5fcb1c3475d.tar.gz merchant-edfc078b18effea43865a093df69e5fcb1c3475d.tar.bz2 merchant-edfc078b18effea43865a093df69e5fcb1c3475d.zip |
fix /public/poll-payment implementation and tests
-rw-r--r-- | src/backend/taler-merchant-httpd.c | 6 | ||||
-rw-r--r-- | src/backend/taler-merchant-httpd_poll-payment.c | 10 | ||||
-rw-r--r-- | src/lib/merchant_api_poll_payment.c | 22 | ||||
-rw-r--r-- | src/lib/test_merchant_api.c | 20 | ||||
-rw-r--r-- | src/lib/testing_api_cmd_poll_payment.c | 16 |
5 files changed, 60 insertions, 14 deletions
diff --git a/src/backend/taler-merchant-httpd.c b/src/backend/taler-merchant-httpd.c index 8abb4449..5daea7b6 100644 --- a/src/backend/taler-merchant-httpd.c +++ b/src/backend/taler-merchant-httpd.c @@ -1274,9 +1274,6 @@ url_handler (void *cls, { "/check-payment", MHD_HTTP_METHOD_GET, "text/plain", NULL, 0, &MH_handler_check_payment, MHD_HTTP_OK}, - { "/public/poll-payment", MHD_HTTP_METHOD_GET, "text/plain", - NULL, 0, - &MH_handler_poll_payment, MHD_HTTP_OK}, { "/config", MHD_HTTP_METHOD_GET, "text/plain", NULL, 0, &MH_handler_config, MHD_HTTP_OK}, @@ -1298,6 +1295,9 @@ url_handler (void *cls, { "/tip-pickup", MHD_HTTP_METHOD_GET, "text/plain", NULL, 0, &MH_handler_tip_pickup_get, MHD_HTTP_OK }, + { "/poll-payment", MHD_HTTP_METHOD_GET, "text/plain", + NULL, 0, + &MH_handler_poll_payment, MHD_HTTP_OK}, {NULL, NULL, NULL, NULL, 0, 0 } }; static struct TMH_RequestHandler h404 = { diff --git a/src/backend/taler-merchant-httpd_poll-payment.c b/src/backend/taler-merchant-httpd_poll-payment.c index 945a356f..3050267f 100644 --- a/src/backend/taler-merchant-httpd_poll-payment.c +++ b/src/backend/taler-merchant-httpd_poll-payment.c @@ -218,10 +218,10 @@ send_pay_request (struct PollPaymentRequestContext *pprc) int ret; char *already_paid_order_id = NULL; char *taler_pay_uri; + struct GNUNET_TIME_Relative remaining; - if (0 != - GNUNET_TIME_absolute_get_remaining ( - pprc->sc.long_poll_timeout).rel_value_us) + remaining = GNUNET_TIME_absolute_get_remaining (pprc->sc.long_poll_timeout); + if (0 != remaining.rel_value_us) { struct TMH_SuspendedConnection *sc; @@ -427,8 +427,6 @@ MH_handler_poll_payment (struct TMH_RequestHandler *rh, } if (0 == qs) { - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Contract unknown\n"); return TMH_RESPONSE_reply_not_found (connection, TALER_EC_POLL_PAYMENT_CONTRACT_NOT_FOUND, "Given order_id doesn't map to any proposal"); @@ -511,8 +509,6 @@ MH_handler_poll_payment (struct TMH_RequestHandler *rh, } if (0 == qs) { - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "not paid yet\n"); return send_pay_request (pprc); } GNUNET_break (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT == qs); diff --git a/src/lib/merchant_api_poll_payment.c b/src/lib/merchant_api_poll_payment.c index e89948e1..024595db 100644 --- a/src/lib/merchant_api_poll_payment.c +++ b/src/lib/merchant_api_poll_payment.c @@ -90,8 +90,22 @@ handle_poll_payment_finished (void *cls, cpo->job = NULL; - if (MHD_HTTP_OK != response_code) + switch (response_code) { + case MHD_HTTP_NOT_FOUND: + cpo->cb (cpo->cb_cls, + response_code, + json, + GNUNET_NO, + GNUNET_NO, + NULL, + NULL); + TALER_MERCHANT_poll_payment_cancel (cpo); + return; + case MHD_HTTP_OK: + /* see below */ + break; + default: GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Polling payment failed with HTTP status code %u\n", (unsigned int) response_code); @@ -107,6 +121,7 @@ handle_poll_payment_finished (void *cls, return; } + /* HTTP OK */ if (! json_boolean_value (json_object_get (json, "paid"))) { const char *taler_pay_uri = json_string_value (json_object_get (json, @@ -233,6 +248,11 @@ TALER_MERCHANT_poll_payment (struct GNUNET_CURL_Context *ctx, (0 != ts) ? "timeout" : NULL, timeout_s, NULL); + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + "Long poll timeout is %s/%llu, url is %s\n", + timeout_s, + (unsigned long long) timeout.rel_value_us, + cpo->url); GNUNET_free (h_contract_s); GNUNET_free (timeout_s); eh = curl_easy_init (); diff --git a/src/lib/test_merchant_api.c b/src/lib/test_merchant_api.c index 4517f48b..165a9d71 100644 --- a/src/lib/test_merchant_api.c +++ b/src/lib/test_merchant_api.c @@ -283,6 +283,18 @@ run (void *cls, MHD_HTTP_OK, "create-proposal-1", GNUNET_NO), + TALER_TESTING_cmd_poll_payment_start ("poll-payment-1", + merchant_url, + "create-proposal-1", + GNUNET_TIME_UNIT_MILLISECONDS), + TALER_TESTING_cmd_poll_payment_conclude ("poll-payment-conclude-1", + MHD_HTTP_OK, + "poll-payment-1", + GNUNET_NO), + TALER_TESTING_cmd_poll_payment_start ("poll-payment-2", + merchant_url, + "create-proposal-1", + GNUNET_TIME_UNIT_MINUTES), TALER_TESTING_cmd_pay ("deposit-simple", merchant_url, MHD_HTTP_OK, @@ -291,6 +303,10 @@ run (void *cls, "EUR:5", "EUR:4.99", "EUR:0.01"), + TALER_TESTING_cmd_poll_payment_conclude ("poll-payment-conclude-2", + MHD_HTTP_OK, + "poll-payment-2", + GNUNET_YES), TALER_TESTING_cmd_check_payment ("check-payment-2", merchant_url, MHD_HTTP_OK, @@ -1048,7 +1064,7 @@ main (int argc, unsetenv ("XDG_DATA_HOME"); unsetenv ("XDG_CONFIG_HOME"); - GNUNET_log_setup ("test-merchant-api-new", + GNUNET_log_setup ("test-merchant-api", "DEBUG", NULL); if (NULL == @@ -1098,4 +1114,4 @@ main (int argc, } -/* end of test_merchant_api_new.c */ +/* end of test_merchant_api.c */ diff --git a/src/lib/testing_api_cmd_poll_payment.c b/src/lib/testing_api_cmd_poll_payment.c index 14d71961..9cef2211 100644 --- a/src/lib/testing_api_cmd_poll_payment.c +++ b/src/lib/testing_api_cmd_poll_payment.c @@ -191,7 +191,9 @@ conclude_task (void *cls) } now = GNUNET_TIME_absolute_get (); if ( (GNUNET_NO == cps->paid) && - (cps->deadline.abs_value_us < now.abs_value_us) ) + (GNUNET_TIME_absolute_add (cps->deadline, + GNUNET_TIME_UNIT_SECONDS).abs_value_us < + now.abs_value_us) ) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Expected answer to be delayed until %llu, but got response at %llu\n", @@ -236,6 +238,17 @@ poll_payment_cb (void *cls, { struct PollPaymentStartState *cps = cls; + if (MHD_HTTP_OK != http_status) + { + char *log = json_dumps (obj, + JSON_COMPACT); + + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + "Poll payment returned %u: %s\n", + http_status, + log); + free (log); + } cps->cpo = NULL; cps->paid = paid; cps->http_status = http_status; @@ -380,6 +393,7 @@ poll_payment_conclude_run (void *cls, const struct TALER_TESTING_Command *poll_cmd; struct PollPaymentStartState *cps; + ppc->is = is; poll_cmd = TALER_TESTING_interpreter_lookup_command (is, ppc->start_reference); |