merchant

Merchant backend to process payments, run by merchants
Log | Files | Refs | Submodules | README | LICENSE

commit 19bc7db44155ed9ed930586bde5f2319a8a6e673
parent e53ad1e718cd6b5acab5672a8dbb2998477e4f86
Author: Christian Grothoff <christian@grothoff.org>
Date:   Sun, 16 Aug 2020 16:15:18 +0200

use 202 if JSON was requested

Diffstat:
Mcontrib/request_payment.en.must | 13++++++++++++-
Msrc/backend/taler-merchant-httpd_get-orders-ID.c | 57+++++++++++++++++++++++++++++++++++----------------------
2 files changed, 47 insertions(+), 23 deletions(-)

diff --git a/contrib/request_payment.en.must b/contrib/request_payment.en.must @@ -90,8 +90,8 @@ body { <body> <script> + let delayMs = 60000; let checkUrl = "{{order_status_url}}"; - let delayMs = 500; function check() { let req = new XMLHttpRequest(); req.onreadystatechange = function () { @@ -106,12 +106,23 @@ body { console.error("could not parse response:", e); } } + if (req.status === 302) { + try { + document.location.reload(true); + } catch (e) { + console.error("could not parse response:", e); + } + } setTimeout(check, delayMs); } }; req.onerror = function () { setTimeout(check, delayMs); } + req.ontimeout = function () { + setTimeout(check, delayMs); + } + req.timeout = delayMs; req.open("GET", checkUrl); req.send(); } diff --git a/src/backend/taler-merchant-httpd_get-orders-ID.c b/src/backend/taler-merchant-httpd_get-orders-ID.c @@ -1157,30 +1157,43 @@ TMH_get_orders_ID (const struct TMH_RequestHandler *rh, if ( (! token_match) && (! contract_match) ) { - /* Contract was claimed (maybe by another device), so this client - cannot get the status information. Redirect to fulfillment page, - where the client may be able to pickup a fresh order -- or might - be able authenticate via session ID */ - struct MHD_Response *reply; - MHD_RESULT ret; - - reply = MHD_create_response_from_buffer (0, - NULL, - MHD_RESPMEM_PERSISTENT); - if (NULL == reply) + if (god->generate_html) { - GNUNET_break (0); - return MHD_NO; + /* Contract was claimed (maybe by another device), so this client + cannot get the status information. Redirect to fulfillment page, + where the client may be able to pickup a fresh order -- or might + be able authenticate via session ID */ + struct MHD_Response *reply; + MHD_RESULT ret; + + reply = MHD_create_response_from_buffer (0, + NULL, + MHD_RESPMEM_PERSISTENT); + if (NULL == reply) + { + GNUNET_break (0); + return MHD_NO; + } + GNUNET_break (MHD_YES == + MHD_add_response_header (reply, + MHD_HTTP_HEADER_LOCATION, + god->fulfillment_url)); + ret = MHD_queue_response (connection, + MHD_HTTP_FOUND, + reply); + MHD_destroy_response (reply); + return ret; + } + else + { + /* Need to generate JSON reply */ + return TALER_MHD_reply_json_pack ( + connection, + MHD_HTTP_ACCEPTED, + "{s:s}", + "fulfillment_url", + god->fulfillment_url); } - GNUNET_break (MHD_YES == - MHD_add_response_header (reply, - MHD_HTTP_HEADER_LOCATION, - god->fulfillment_url)); - ret = MHD_queue_response (connection, - MHD_HTTP_FOUND, - reply); - MHD_destroy_response (reply); - return ret; } } /* end of first-time initialization / sanity checks */