aboutsummaryrefslogtreecommitdiff
path: root/src/backend
diff options
context:
space:
mode:
Diffstat (limited to 'src/backend')
-rw-r--r--src/backend/taler-merchant-httpd_get-orders-ID.c89
-rw-r--r--src/backend/taler-merchant-httpd_get-orders-ID.h16
-rw-r--r--src/backend/taler-merchant-httpd_get-tips-ID.c90
-rw-r--r--src/backend/taler-merchant-httpd_get-tips-ID.h27
-rw-r--r--src/backend/taler-merchant-httpd_private-get-orders-ID.c33
-rw-r--r--src/backend/taler-merchant-httpd_private-post-reserves-ID-authorize-tip.c47
-rw-r--r--src/backend/taler-merchant-httpd_qr.c10
7 files changed, 262 insertions, 50 deletions
diff --git a/src/backend/taler-merchant-httpd_get-orders-ID.c b/src/backend/taler-merchant-httpd_get-orders-ID.c
index 08756e2b..afe452a0 100644
--- a/src/backend/taler-merchant-httpd_get-orders-ID.c
+++ b/src/backend/taler-merchant-httpd_get-orders-ID.c
@@ -371,6 +371,87 @@ make_taler_refund_uri (struct MHD_Connection *con,
/**
+ * Create a http(s) URL for the given @a con and @a order_id
+ * and @a instance_id to display the /orders/{order_id} page.
+ *
+ * @param con HTTP connection
+ * @param order_id the order id
+ * @param instance_id instance, may be "default"
+ * @param claim_token claim token for the order, may be NULL
+ * @return corresponding http(s):// URL, or NULL on missing "host"
+ */
+char *
+TMH_make_order_status_url (struct MHD_Connection *con,
+ const char *order_id,
+ const char *instance_id,
+ struct TALER_ClaimTokenP *claim_token)
+{
+ 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);
+
+ if (GNUNET_NO == TALER_mhd_is_https (con))
+ GNUNET_buffer_write_str (&buf,
+ "http://");
+ else
+ GNUNET_buffer_write_str (&buf,
+ "https://");
+
+ 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,
+ "/orders");
+ GNUNET_buffer_write_path (&buf,
+ order_id);
+ if ((NULL != claim_token) &&
+ (0 != GNUNET_is_zero (claim_token)))
+ {
+ GNUNET_buffer_write_str (&buf,
+ "?token=");
+ GNUNET_buffer_write_data_encoded (&buf,
+ (char *) claim_token,
+ sizeof (struct TALER_ClaimTokenP));
+ }
+
+ 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.
*
@@ -468,6 +549,7 @@ send_pay_request (struct GetOrderData *god,
{
MHD_RESULT ret;
char *taler_pay_uri;
+ char *order_status_url;
struct GNUNET_TIME_Relative remaining;
remaining = GNUNET_TIME_absolute_get_remaining (god->sc.long_poll_timeout);
@@ -488,6 +570,10 @@ send_pay_request (struct GetOrderData *god,
god->session_id,
god->hc->instance->settings.id,
&god->claim_token);
+ order_status_url = TMH_make_order_status_url (god->sc.con,
+ god->order_id,
+ god->hc->instance->settings.id,
+ &god->claim_token);
if (god->generate_html)
{
char *qr;
@@ -502,6 +588,8 @@ send_pay_request (struct GetOrderData *god,
struct KVC kvc[] = {
{ "taler_pay_uri",
taler_pay_uri },
+ { "order_status_url",
+ order_status_url },
{ "taler_pay_qrcode_svg",
qr },
{ "order_summary",
@@ -538,6 +626,7 @@ send_pay_request (struct GetOrderData *god,
already_paid_order_id);
}
GNUNET_free (taler_pay_uri);
+ GNUNET_free (order_status_url);
return ret;
}
diff --git a/src/backend/taler-merchant-httpd_get-orders-ID.h b/src/backend/taler-merchant-httpd_get-orders-ID.h
index 1eb9a18a..d5d33fac 100644
--- a/src/backend/taler-merchant-httpd_get-orders-ID.h
+++ b/src/backend/taler-merchant-httpd_get-orders-ID.h
@@ -42,6 +42,22 @@ TMH_make_taler_pay_uri (struct MHD_Connection *con,
const char *instance_id,
struct TALER_ClaimTokenP *claim_token);
+/**
+ * Create a http(s) URL for the given @a con and @a order_id
+ * and @a instance_id to display the /orders/{order_id} page.
+ *
+ * @param con HTTP connection
+ * @param order_id the order id
+ * @param instance_id instance, may be "default"
+ * @param claim_token claim token for the order, may be NULL
+ * @return corresponding http(s):// URL, or NULL on missing "host"
+ */
+char *
+TMH_make_order_status_url (struct MHD_Connection *con,
+ const char *order_id,
+ const char *instance_id,
+ struct TALER_ClaimTokenP *claim_token);
+
/**
* Handle a GET "/orders/$ID" request.
diff --git a/src/backend/taler-merchant-httpd_get-tips-ID.c b/src/backend/taler-merchant-httpd_get-tips-ID.c
index 487e88f4..237c1a4a 100644
--- a/src/backend/taler-merchant-httpd_get-tips-ID.c
+++ b/src/backend/taler-merchant-httpd_get-tips-ID.c
@@ -38,10 +38,10 @@
* @param instance_id instance, may be "default"
* @return corresponding taler://tip/ URI, or NULL on missing "host"
*/
-static char *
-make_taler_tip_uri (struct MHD_Connection *con,
- const struct GNUNET_HashCode *tip_id,
- const char *instance_id)
+char *
+TMH_make_taler_tip_uri (struct MHD_Connection *con,
+ const struct GNUNET_HashCode *tip_id,
+ const char *instance_id)
{
const char *host;
const char *forwarded_host;
@@ -100,6 +100,75 @@ make_taler_tip_uri (struct MHD_Connection *con,
/**
+ * Create a http(s):// URL for the given @a con and @a tip_id
+ * and @a instance_id.
+ *
+ * @param con HTTP connection
+ * @param tip_id the tip id
+ * @param instance_id instance, may be "default"
+ * @return corresponding taler://tip/ URI, or NULL on missing "host"
+ */
+char *
+TMH_make_tip_status_url (struct MHD_Connection *con,
+ const struct GNUNET_HashCode *tip_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 != tip_id);
+
+ if (GNUNET_NO == TALER_mhd_is_https (con))
+ GNUNET_buffer_write_str (&buf,
+ "http");
+ else
+ GNUNET_buffer_write_str (&buf,
+ "http");
+ 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,
+ "tips/");
+ GNUNET_buffer_write_data_encoded (&buf,
+ tip_id,
+ sizeof (*tip_id));
+ return GNUNET_buffer_reap_str (&buf);
+}
+
+
+/**
* Handle a GET "/tips/$ID" request.
*
* @param rh context of the handler
@@ -180,10 +249,14 @@ TMH_get_tips_ID (const struct TMH_RequestHandler *rh,
{
char *qr;
char *uri;
+ char *tip_status_url;
- uri = make_taler_tip_uri (connection,
- &tip_id,
- hc->instance->settings.id);
+ uri = TMH_make_taler_tip_uri (connection,
+ &tip_id,
+ hc->instance->settings.id);
+ tip_status_url = TMH_make_tip_status_url (connection,
+ &tip_id,
+ hc->instance->settings.id);
qr = TMH_create_qrcode (uri);
if (NULL == qr)
{
@@ -199,6 +272,8 @@ TMH_get_tips_ID (const struct TMH_RequestHandler *rh,
struct KVC kvc[] = {
{ "remaining_tip",
TALER_amount2s (&remaining) },
+ { "tip_status_url",
+ tip_status_url },
{ "taler_tip_uri",
uri },
{ "taler_tip_qrcode_svg",
@@ -218,6 +293,7 @@ TMH_get_tips_ID (const struct TMH_RequestHandler *rh,
uri,
kvc);
}
+ GNUNET_free (tip_status_url);
GNUNET_free (uri);
GNUNET_free (qr);
}
diff --git a/src/backend/taler-merchant-httpd_get-tips-ID.h b/src/backend/taler-merchant-httpd_get-tips-ID.h
index 6fa0253a..9ee73a6a 100644
--- a/src/backend/taler-merchant-httpd_get-tips-ID.h
+++ b/src/backend/taler-merchant-httpd_get-tips-ID.h
@@ -23,6 +23,33 @@
#include <microhttpd.h>
#include "taler-merchant-httpd.h"
+/**
+ * Create a taler://tip/ URI for the given @a con and @a tip_id
+ * and @a instance_id.
+ *
+ * @param con HTTP connection
+ * @param tip_id the tip id
+ * @param instance_id instance, may be "default"
+ * @return corresponding taler://tip/ URI, or NULL on missing "host"
+ */
+char *
+TMH_make_taler_tip_uri (struct MHD_Connection *con,
+ const struct GNUNET_HashCode *tip_id,
+ const char *instance_id);
+
+/**
+ * Create a http(s):// URL for the given @a con and @a tip_id
+ * and @a instance_id.
+ *
+ * @param con HTTP connection
+ * @param tip_id the tip id
+ * @param instance_id instance, may be "default"
+ * @return corresponding taler://tip/ URI, or NULL on missing "host"
+ */
+char *
+TMH_make_tip_status_url (struct MHD_Connection *con,
+ const struct GNUNET_HashCode *tip_id,
+ const char *instance_id);
/**
* Handle a GET "/tips/$ID" request.
diff --git a/src/backend/taler-merchant-httpd_private-get-orders-ID.c b/src/backend/taler-merchant-httpd_private-get-orders-ID.c
index 7823837f..230a240f 100644
--- a/src/backend/taler-merchant-httpd_private-get-orders-ID.c
+++ b/src/backend/taler-merchant-httpd_private-get-orders-ID.c
@@ -966,6 +966,7 @@ TMH_private_get_orders_ID (const struct TMH_RequestHandler *rh,
/* User did pay for this order, but under a different session; ask wallet
to switch order ID */
char *taler_pay_uri;
+ char *order_status_url;
MHD_RESULT ret;
taler_pay_uri = TMH_make_taler_pay_uri (connection,
@@ -973,11 +974,17 @@ TMH_private_get_orders_ID (const struct TMH_RequestHandler *rh,
gorc->session_id,
hc->instance->settings.id,
&claim_token);
+ order_status_url = TMH_make_order_status_url (connection,
+ hc->infix,
+ hc->instance->settings.id,
+ &claim_token);
ret = TALER_MHD_reply_json_pack (connection,
MHD_HTTP_OK,
- "{s:s, s:s, s:s}",
+ "{s:s, s:s, s:s, s:s}",
"taler_pay_uri",
taler_pay_uri,
+ "order_status_url",
+ order_status_url,
"order_status",
"unpaid",
"already_paid_order_id",
@@ -1034,6 +1041,7 @@ TMH_private_get_orders_ID (const struct TMH_RequestHandler *rh,
{
/* User never paid for this order */
char *taler_pay_uri;
+ char *order_status_url;
MHD_RESULT ret;
taler_pay_uri = TMH_make_taler_pay_uri (connection,
@@ -1041,16 +1049,23 @@ TMH_private_get_orders_ID (const struct TMH_RequestHandler *rh,
gorc->session_id,
hc->instance->settings.id,
&claim_token);
+ order_status_url = TMH_make_order_status_url (connection,
+ hc->infix,
+ hc->instance->settings.id,
+ &claim_token);
ret = TALER_MHD_reply_json_pack (connection,
MHD_HTTP_OK,
- "{s:s, s:O, s:s}",
+ "{s:s, s:s, s:O, s:s}",
"taler_pay_uri",
taler_pay_uri,
+ "order_status_url",
+ order_status_url,
"contract_terms",
gorc->contract_terms,
"order_status",
"unpaid");
GNUNET_free (taler_pay_uri);
+ GNUNET_free (order_status_url);
return ret;
}
@@ -1081,6 +1096,8 @@ TMH_private_get_orders_ID (const struct TMH_RequestHandler *rh,
{
MHD_RESULT ret;
+ char *order_status_url;
+
GNUNET_assert (GNUNET_OK ==
TALER_amount_get_zero (TMH_currency,
&gorc->deposits_total));
@@ -1166,10 +1183,15 @@ TMH_private_get_orders_ID (const struct TMH_RequestHandler *rh,
}
}
+ order_status_url = TMH_make_order_status_url (connection,
+ hc->infix,
+ hc->instance->settings.id,
+ &claim_token);
+
ret = TALER_MHD_reply_json_pack (connection,
MHD_HTTP_OK,
"{s:o, s:I, s:I, s:o, s:O,"
- " s:s, s:b, s:b, s:o, s:o, s:o}",
+ " s:s, s:b, s:b, s:o, s:o, s:o, s:s}",
"wire_reports",
gorc->wire_reports,
"exchange_ec",
@@ -1193,7 +1215,10 @@ TMH_private_get_orders_ID (const struct TMH_RequestHandler *rh,
"wire_details",
gorc->wire_details,
"refund_details",
- gorc->refund_details);
+ gorc->refund_details,
+ "order_status_url",
+ order_status_url);
+ GNUNET_free (order_status_url);
gorc->wire_details = NULL;
gorc->wire_reports = NULL;
gorc->refund_details = NULL;
diff --git a/src/backend/taler-merchant-httpd_private-post-reserves-ID-authorize-tip.c b/src/backend/taler-merchant-httpd_private-post-reserves-ID-authorize-tip.c
index 1c28173b..2181f1eb 100644
--- a/src/backend/taler-merchant-httpd_private-post-reserves-ID-authorize-tip.c
+++ b/src/backend/taler-merchant-httpd_private-post-reserves-ID-authorize-tip.c
@@ -24,6 +24,7 @@
#include <taler/taler_json_lib.h>
#include "taler-merchant-httpd.h"
#include "taler-merchant-httpd_mhd.h"
+#include "taler-merchant-httpd_get-tips-ID.h"
#include "taler-merchant-httpd_private-post-reserves-ID-authorize-tip.h"
@@ -116,54 +117,32 @@ authorize_tip (const struct TMH_RequestHandler *rh,
/* generate success response */
{
char *taler_tip_uri;
- const char *host;
- const char *forwarded_host;
- const char *uri_path;
+ char *tip_status_url;
struct GNUNET_CRYPTO_HashAsciiEncoded hash_enc;
MHD_RESULT res;
- host = MHD_lookup_connection_value (connection,
- MHD_HEADER_KIND,
- "Host");
- forwarded_host = MHD_lookup_connection_value (connection,
- MHD_HEADER_KIND,
- "X-Forwarded-Host");
-
- uri_path = MHD_lookup_connection_value (connection,
- MHD_HEADER_KIND,
- "X-Forwarded-Prefix");
- if (NULL != forwarded_host)
- host = forwarded_host;
- if (NULL == host)
- {
- /* Should never happen, at last the host header should be defined */
- GNUNET_break (0);
- return TALER_MHD_reply_with_error (connection,
- MHD_HTTP_INTERNAL_SERVER_ERROR,
- TALER_EC_INTERNAL_INVARIANT_FAILURE,
- "unable to identify backend host");
- }
-
GNUNET_CRYPTO_hash_to_enc (&tip_id,
&hash_enc);
- GNUNET_assert (0 < GNUNET_asprintf (&taler_tip_uri,
- "taler://tip/%s/%s%sinstances/%s/%s",
- host,
- (NULL == uri_path) ? "" : uri_path,
- (NULL == uri_path) ? "" : "/",
- hc->instance->settings.id,
- hash_enc.encoding));
+ taler_tip_uri = TMH_make_taler_tip_uri (connection,
+ &tip_id,
+ hc->instance->settings.id);
+ tip_status_url = TMH_make_tip_status_url (connection,
+ &tip_id,
+ hc->instance->settings.id);
GNUNET_TIME_round_abs (&expiration);
res = TALER_MHD_reply_json_pack (connection,
MHD_HTTP_OK,
- "{s:s, s:s, s:o}",
+ "{s:s, s:s, s:s, s:o}",
"tip_id",
hash_enc.encoding,
- "tip_redirect_url",
+ "taler_tip_uri",
taler_tip_uri,
+ "tip_status_url",
+ tip_status_url,
"tip_expiration",
GNUNET_JSON_from_time_abs (expiration));
GNUNET_free (taler_tip_uri);
+ GNUNET_free (tip_status_url);
return res;
}
}
diff --git a/src/backend/taler-merchant-httpd_qr.c b/src/backend/taler-merchant-httpd_qr.c
index ddb73167..1774f75b 100644
--- a/src/backend/taler-merchant-httpd_qr.c
+++ b/src/backend/taler-merchant-httpd_qr.c
@@ -73,11 +73,11 @@ TMH_create_qrcode (const char *uri)
}
QRinput_free (qri);
GNUNET_buffer_write_fstr (&buf,
- "<svg width='100mm' height='100mm' viewBox='0 0 %u %u' "
- "version='1.1' xmlns='http://www.w3.org/2000/svg' "
- "style='shape-rendering: crispedges;'>\n",
- qrc->width,
- qrc->width);
+ "<svg width='100mm' height='100mm' viewBox='0 0 %u %u' "
+ "version='1.1' xmlns='http://www.w3.org/2000/svg' "
+ "style='shape-rendering: crispedges;'>\n",
+ qrc->width,
+ qrc->width);
for (unsigned int y = 0; y<qrc->width; y++)
{
for (unsigned int x = 0; x<qrc->width; x++)