From 9776c13c24d52521ef46eac35fb4ad73b3d86260 Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Mon, 3 Aug 2020 12:27:24 +0200 Subject: fix name extraction --- src/backend/taler-merchant-httpd_get-orders-ID.c | 83 ++++++++++++++++++++++-- 1 file changed, 79 insertions(+), 4 deletions(-) (limited to 'src/backend/taler-merchant-httpd_get-orders-ID.c') diff --git a/src/backend/taler-merchant-httpd_get-orders-ID.c b/src/backend/taler-merchant-httpd_get-orders-ID.c index f51b1962..d587745c 100644 --- a/src/backend/taler-merchant-httpd_get-orders-ID.c +++ b/src/backend/taler-merchant-httpd_get-orders-ID.c @@ -297,6 +297,73 @@ suspend_god (struct GetOrderData *god) } +/** + * Create a taler://refund/ URI for the given @a con and @a order_id + * and @a instance_id. + * + * @param con HTTP connection + * @param order_id the order id + * @param instance_id instance, may be "default" + * @return corresponding taler://refund/ URI, or NULL on missing "host" + */ +static char * +make_taler_refund_uri (struct MHD_Connection *con, + const char *order_id, + const char *instance_id) +{ + const char *host; + const char *forwarded_host; + const char *uri_path; + struct GNUNET_Buffer buf = { 0 }; + + host = MHD_lookup_connection_value (con, + MHD_HEADER_KIND, + "Host"); + forwarded_host = MHD_lookup_connection_value (con, + MHD_HEADER_KIND, + "X-Forwarded-Host"); + + uri_path = MHD_lookup_connection_value (con, + MHD_HEADER_KIND, + "X-Forwarded-Prefix"); + if (NULL != forwarded_host) + host = forwarded_host; + + if (NULL == host) + { + GNUNET_break (0); + return NULL; + } + + GNUNET_assert (NULL != instance_id); + GNUNET_assert (NULL != order_id); + + GNUNET_buffer_write_str (&buf, + "taler"); + if (GNUNET_NO == TALER_mhd_is_https (con)) + GNUNET_buffer_write_str (&buf, + "+http"); + GNUNET_buffer_write_str (&buf, + "://refund/"); + GNUNET_buffer_write_str (&buf, + host); + if (NULL != uri_path) + GNUNET_buffer_write_path (&buf, + uri_path); + if (0 != strcmp ("default", + instance_id)) + { + GNUNET_buffer_write_path (&buf, + "instances"); + GNUNET_buffer_write_path (&buf, + instance_id); + } + GNUNET_buffer_write_path (&buf, + order_id); + return GNUNET_buffer_reap_str (&buf); +} + + /** * Create a taler://pay/ URI for the given @a con and @a order_id * and @a session_id and @a instance_id. @@ -320,7 +387,6 @@ TMH_make_taler_pay_uri (struct MHD_Connection *con, const char *uri_path; struct GNUNET_Buffer buf = { 0 }; - host = MHD_lookup_connection_value (con, MHD_HEADER_KIND, "Host"); @@ -433,7 +499,10 @@ send_pay_request (struct GetOrderData *god, { "taler_pay_qrcode_svg", qr }, { "order_summary", - "FIXME" }, + // FIXME: implement logic to extract summary based on + // language preferences from summary_i18n if present. + json_string_value (json_object_get (god->contract_terms, + "summary")) }, { NULL, NULL } }; enum GNUNET_GenericReturnValue res; @@ -1241,11 +1310,16 @@ TMH_get_orders_ID (const struct TMH_RequestHandler *rh, if (god->refunded) // FIXME: don't check for refunded, but for PENDING refund! { char *qr; + char *uri; - qr = TMH_create_qrcode ("taler://refund/FIXME"); + uri = make_taler_refund_uri (god->sc.con, + order_id, + hc->instance->settings.id); + qr = TMH_create_qrcode (uri); if (NULL == qr) { GNUNET_break (0); + GNUNET_free (uri); return MHD_NO; // FIXME: add nicer error reply... } { @@ -1260,9 +1334,10 @@ TMH_get_orders_ID (const struct TMH_RequestHandler *rh, res = TMH_return_from_template (god->sc.con, MHD_HTTP_OK, "offer_refund", - "FIXME: refund-URI here", + uri, kvc); } + GNUNET_free (uri); GNUNET_free (qr); } else -- cgit v1.2.3