summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFlorian Dold <florian.dold@gmail.com>2019-08-26 20:26:41 +0200
committerFlorian Dold <florian.dold@gmail.com>2019-08-26 20:26:41 +0200
commit8da3379c0a4ec94aa0a6d665307ef0191dee16ec (patch)
tree2569e9089131f864b8b98f3a2bea381aeca06209
parent15518f077f9955d04de58c8041370372a7d0475b (diff)
downloadmerchant-8da3379c0a4ec94aa0a6d665307ef0191dee16ec.tar.gz
merchant-8da3379c0a4ec94aa0a6d665307ef0191dee16ec.tar.bz2
merchant-8da3379c0a4ec94aa0a6d665307ef0191dee16ec.zip
generate taler_pay_uri in favor of the trigger-pay mechanism
-rw-r--r--src/backend/taler-merchant-httpd.c4
-rw-r--r--src/backend/taler-merchant-httpd_check-payment.c97
-rw-r--r--src/include/taler_merchant_service.h6
-rw-r--r--src/lib/merchant_api_check_payment.c8
-rw-r--r--src/lib/test_merchant_api_twisted.c2
-rw-r--r--src/lib/testing_api_cmd_pay.c8
6 files changed, 97 insertions, 28 deletions
diff --git a/src/backend/taler-merchant-httpd.c b/src/backend/taler-merchant-httpd.c
index 9cc198e5..c19eb9ab 100644
--- a/src/backend/taler-merchant-httpd.c
+++ b/src/backend/taler-merchant-httpd.c
@@ -47,7 +47,6 @@
#include "taler-merchant-httpd_history.h"
#include "taler-merchant-httpd_refund.h"
#include "taler-merchant-httpd_check-payment.h"
-#include "taler-merchant-httpd_trigger-pay.h"
#include "taler-merchant-httpd_config.h"
/**
@@ -289,9 +288,6 @@ url_handler (void *cls,
{ "/check-payment", MHD_HTTP_METHOD_GET, "text/plain",
NULL, 0,
&MH_handler_check_payment, MHD_HTTP_OK},
- { "/public/trigger-pay", MHD_HTTP_METHOD_GET, "text/plain",
- NULL, 0,
- &MH_handler_trigger_pay, MHD_HTTP_OK},
{ "/config", MHD_HTTP_METHOD_GET, "text/plain",
NULL, 0,
&MH_handler_config, MHD_HTTP_OK},
diff --git a/src/backend/taler-merchant-httpd_check-payment.c b/src/backend/taler-merchant-httpd_check-payment.c
index b4526b14..98c94932 100644
--- a/src/backend/taler-merchant-httpd_check-payment.c
+++ b/src/backend/taler-merchant-httpd_check-payment.c
@@ -37,6 +37,80 @@
#define MAX_RETRIES 5
+
+/**
+ * Make a taler://pay URI
+ *
+ * @param MHD connection to take host and path from
+ * @param merchant's instance
+ * @param order_id order ID to request a payment for
+ * @param session_id session ID for the payment or NULL
+ * if not a session-bound payment
+ * @returns the URI, must be freed with #GNUNET_free
+ */
+char *
+make_taler_pay_uri (struct MHD_Connection *connection,
+ const char *instance,
+ const char *order_id,
+ const char *session_id)
+{
+ const char *host;
+ const char *forwarded_host;
+ const char *uri_path;
+ const char *uri_instance;
+ char *result;
+
+
+ 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 == uri_path)
+ uri_path = "-";
+
+ if (NULL != forwarded_host)
+ host = forwarded_host;
+
+ if (0 == strcmp (instance, "default"))
+ uri_instance = "-";
+ else
+ uri_instance = instance;
+
+ if (NULL == host)
+ {
+ /* Should never happen, at last the host header should be defined */
+ GNUNET_break (0);
+ return NULL;
+ }
+
+ GNUNET_assert (NULL != order_id);
+
+ if (NULL == session_id)
+ {
+ GNUNET_assert (0 < GNUNET_asprintf (&result,
+ "taler://pay/%s/%s/%s/%s",
+ host,
+ uri_path,
+ uri_instance,
+ order_id));
+ }
+ else
+ {
+ GNUNET_assert (0 < GNUNET_asprintf (&result,
+ "taler://pay/%s/%s/%s/%s/%s",
+ host,
+ uri_path,
+ uri_instance,
+ order_id,
+ session_id));
+ }
+ return result;
+}
+
+
+
/**
* Function called with information about a refund.
* It is responsible for summing up the refund amount.
@@ -69,6 +143,7 @@ process_refunds_cb (void *cls,
* The client did not yet pay, send it the payment request.
*
* @param connection connection to send on
+ * @param order_id order ID for the payment
* @param final_contract_url where to get the contract
* @param session_id session of the client
* @param resource_url where the resource will be (?), can be NULL!
@@ -78,6 +153,7 @@ process_refunds_cb (void *cls,
*/
static int
send_pay_request (struct MHD_Connection *connection,
+ const char *order_id,
const char *final_contract_url,
const char *session_id,
const char *resource_url,
@@ -86,8 +162,8 @@ send_pay_request (struct MHD_Connection *connection,
{
int ret;
int qs;
- char *url;
char *already_paid_order_id = NULL;
+ char *taler_pay_uri;
/* Check if resource_id has been paid for in the same session
* with another order_id.
@@ -112,19 +188,13 @@ send_pay_request (struct MHD_Connection *connection,
}
}
- url = TALER_url_absolute_mhd (connection,
- "public/trigger-pay",
- "contract_url", final_contract_url,
- "session_id", session_id,
- "resource_url", resource_url,
- "h_contract_terms", h_contract_terms_str,
- NULL);
- GNUNET_assert (NULL != url);
+ taler_pay_uri = make_taler_pay_uri (connection, mi->name, order_id, session_id);
+
ret = TMH_RESPONSE_reply_json_pack (connection,
MHD_HTTP_OK,
"{s:s, s:s, s:b, s:s?}",
- "fallback_request_payment_url",
- url,
+ "taler_pay_uri",
+ taler_pay_uri,
"contract_url",
final_contract_url,
"paid",
@@ -133,7 +203,7 @@ send_pay_request (struct MHD_Connection *connection,
already_paid_order_id
);
GNUNET_free_non_null (already_paid_order_id);
- GNUNET_free (url);
+ GNUNET_free (taler_pay_uri);
return ret;
}
@@ -199,6 +269,7 @@ check_order_and_request_payment (struct MHD_Connection *connection,
h_contract_terms_str = GNUNET_STRINGS_data_to_string_alloc (&h_contract_terms,
sizeof (struct GNUNET_HashCode));
ret = send_pay_request (connection,
+ order_id,
final_contract_url,
session_id,
resource_url,
@@ -383,6 +454,7 @@ MH_handler_check_payment (struct TMH_RequestHandler *rh,
{
ret = send_pay_request (connection,
+ order_id,
final_contract_url,
session_id,
resource_url,
@@ -419,6 +491,7 @@ MH_handler_check_payment (struct TMH_RequestHandler *rh,
{
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "not paid yet\n");
ret = send_pay_request (connection,
+ order_id,
final_contract_url,
session_id,
resource_url,
diff --git a/src/include/taler_merchant_service.h b/src/include/taler_merchant_service.h
index 46e6ec9f..9cca90a3 100644
--- a/src/include/taler_merchant_service.h
+++ b/src/include/taler_merchant_service.h
@@ -963,8 +963,8 @@ struct TALER_MERCHANT_CheckPaymentOperation;
* #GNUNET_NO if refunded, #GNUNET_SYSERR or error
* @param refunded_amount amount that was refunded, NULL if there
* was no refund
- * @param fallback_request_payment_url URL to redirect the browser to in order to
- * execute or re-play the payment (NULL if not applicable)
+ * @param taler_pay_uri the URI that instructs the wallets to process
+ * the payment
*/
typedef void
(*TALER_MERCHANT_CheckPaymentCallback) (void *cls,
@@ -973,7 +973,7 @@ typedef void
int paid,
int refunded,
struct TALER_Amount *refund_amount,
- const char *fallback_request_payment_url);
+ const char *taler_pay_uri);
/**
diff --git a/src/lib/merchant_api_check_payment.c b/src/lib/merchant_api_check_payment.c
index 4605f476..87a74ea6 100644
--- a/src/lib/merchant_api_check_payment.c
+++ b/src/lib/merchant_api_check_payment.c
@@ -111,11 +111,11 @@ handle_check_payment_finished (void *cls,
if (! json_boolean_value (json_object_get (json, "paid")))
{
- const char *fallback_request_payment_url = json_string_value (json_object_get (json, "fallback_request_payment_url"));
- if (NULL == fallback_request_payment_url)
+ const char *taler_pay_uri = json_string_value (json_object_get (json, "taler_pay_uri"));
+ if (NULL == taler_pay_uri)
{
GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- "no fallback_request_payment_url in unpaid check-payment response\n");
+ "no taler_pay_uri in unpaid check-payment response\n");
GNUNET_break_op (0);
cpo->cb (cpo->cb_cls,
0,
@@ -131,7 +131,7 @@ handle_check_payment_finished (void *cls,
GNUNET_NO,
GNUNET_NO,
&refund_amount,
- fallback_request_payment_url);
+ taler_pay_uri);
}
TALER_MERCHANT_check_payment_cancel (cpo);
return;
diff --git a/src/lib/test_merchant_api_twisted.c b/src/lib/test_merchant_api_twisted.c
index 9646fd16..43f3ef6f 100644
--- a/src/lib/test_merchant_api_twisted.c
+++ b/src/lib/test_merchant_api_twisted.c
@@ -303,7 +303,7 @@ run (void *cls,
TALER_TESTING_cmd_delete_object ("hack-check-payment-0",
PROXY_MERCHANT_CONFIG_FILE,
- "fallback_request_payment_url"),
+ "taler_pay_uri"),
TALER_TESTING_cmd_check_payment
("check-payment-fail-invalid",
twister_merchant_url,
diff --git a/src/lib/testing_api_cmd_pay.c b/src/lib/testing_api_cmd_pay.c
index a9947a50..aafcf253 100644
--- a/src/lib/testing_api_cmd_pay.c
+++ b/src/lib/testing_api_cmd_pay.c
@@ -316,8 +316,8 @@ check_payment_cleanup (void *cls,
* refunded (not refunded).
* @param refund_amount the amount that was refunded to this
* contract.
- * @param fallback_request_payment_url URL where the payment has to be
- * addressed.
+ * @param taler_pay_uri the URI that instructs the wallets to process
+ * the payment
*/
static void
check_payment_cb (void *cls,
@@ -326,7 +326,7 @@ check_payment_cb (void *cls,
int paid,
int refunded,
struct TALER_Amount *refund_amount,
- const char *fallback_request_payment_url)
+ const char *taler_pay_uri)
{
struct CheckPaymentState *cps = cls;
@@ -341,7 +341,7 @@ check_payment_cb (void *cls,
paid);
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"check payment: url: %s\n",
- fallback_request_payment_url);
+ taler_pay_uri);
if (paid != cps->expect_paid)
TALER_TESTING_FAIL (cps->is);