merchant

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

commit 61f5a1fb6baf24ba1c84e00f52e67a266ac3150b
parent 050de4d39ca58446b02887bf5770864589e788cb
Author: Florian Dold <florian.dold@gmail.com>
Date:   Tue, 11 Aug 2020 20:05:57 +0530

implement refund gone response when claim token is present on paid order

Diffstat:
Msrc/backend/taler-merchant-httpd_get-orders-ID.c | 78+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-----
1 file changed, 73 insertions(+), 5 deletions(-)

diff --git a/src/backend/taler-merchant-httpd_get-orders-ID.c b/src/backend/taler-merchant-httpd_get-orders-ID.c @@ -875,6 +875,54 @@ god_cleanup (void *cls) GNUNET_free (god); } +/** + * Function to call to handle the request by sending + * back a redirect to the fulfillment URL. + * + * @param connection the MHD connection to handle + * @param url fulfillment URL + * @return MHD result code + */ +static MHD_RESULT +reply_fulfillment_redirect (struct MHD_Connection *connection, + const char *url) +{ + const char *text = "Redirecting to fulfillment URL ..."; + struct MHD_Response *response; + + response = MHD_create_response_from_buffer (strlen (text), + (void *) text, + MHD_RESPMEM_PERSISTENT); + if (NULL == response) + { + GNUNET_break (0); + return MHD_NO; + } + TALER_MHD_add_global_headers (response); + GNUNET_break (MHD_YES == + MHD_add_response_header (response, + MHD_HTTP_HEADER_CONTENT_TYPE, + "text/plain")); + if (MHD_NO == + MHD_add_response_header (response, + MHD_HTTP_HEADER_LOCATION, + url)) + { + GNUNET_break (0); + MHD_destroy_response (response); + return MHD_NO; + } + + { + MHD_RESULT ret; + + ret = MHD_queue_response (connection, + MHD_HTTP_FOUND, + response); + MHD_destroy_response (response); + return ret; + } +} /** * Handle a GET "/orders/$ID" request. @@ -892,6 +940,8 @@ TMH_get_orders_ID (const struct TMH_RequestHandler *rh, struct GetOrderData *god = hc->ctx; const char *order_id = hc->infix; enum GNUNET_DB_QueryStatus qs; + /* Will we reply with HTTP 410 Gone and just the fulfillment URL? */ + bool reply_gone = false; if (NULL == god) { @@ -1049,11 +1099,16 @@ TMH_get_orders_ID (const struct TMH_RequestHandler *rh, GNUNET_memcmp (&h, &god->h_contract_terms)) { - GNUNET_break_op (0); - return TALER_MHD_reply_with_error (connection, - MHD_HTTP_FORBIDDEN, - TALER_EC_GET_ORDER_WRONG_CONTRACT, - "Contract hash does not match order"); + if (0 == GNUNET_is_zero (&god->claim_token)) + { + /* The client did not provide any claim token, just a wrong h_contract */ + GNUNET_break_op (0); + return TALER_MHD_reply_with_error (connection, + MHD_HTTP_FORBIDDEN, + TALER_EC_GET_ORDER_WRONG_CONTRACT, + "Contract hash does not match order"); + } + reply_gone = true; } } @@ -1131,6 +1186,19 @@ TMH_get_orders_ID (const struct TMH_RequestHandler *rh, NULL); } + if (reply_gone) + { + GNUNET_assert (NULL != god->fulfillment_url); + if (god->generate_html) + return reply_fulfillment_redirect (connection, + god->fulfillment_url); + else + return TALER_MHD_reply_json_pack (connection, + MHD_HTTP_GONE, + "fulfillment_url", + god->fulfillment_url); + } + if ( (NULL != god->session_id) && (NULL != god->fulfillment_url) ) {