gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] [taler-merchant] branch master updated: generate taler_pay_


From: gnunet
Subject: [GNUnet-SVN] [taler-merchant] branch master updated: generate taler_pay_uri in favor of the trigger-pay mechanism
Date: Mon, 26 Aug 2019 20:26:47 +0200

This is an automated email from the git hooks/post-receive script.

dold pushed a commit to branch master
in repository merchant.

The following commit(s) were added to refs/heads/master by this push:
     new 8da3379  generate taler_pay_uri in favor of the trigger-pay mechanism
8da3379 is described below

commit 8da3379c0a4ec94aa0a6d665307ef0191dee16ec
Author: Florian Dold <address@hidden>
AuthorDate: Mon Aug 26 20:26:41 2019 +0200

    generate taler_pay_uri in favor of the trigger-pay mechanism
---
 src/backend/taler-merchant-httpd.c               |  4 -
 src/backend/taler-merchant-httpd_check-payment.c | 97 +++++++++++++++++++++---
 src/include/taler_merchant_service.h             |  6 +-
 src/lib/merchant_api_check_payment.c             |  8 +-
 src/lib/test_merchant_api_twisted.c              |  2 +-
 src/lib/testing_api_cmd_pay.c                    |  8 +-
 6 files changed, 97 insertions(+), 28 deletions(-)

diff --git a/src/backend/taler-merchant-httpd.c 
b/src/backend/taler-merchant-httpd.c
index 9cc198e..c19eb9a 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 b4526b1..98c9493 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 46e6ec9..9cca90a 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 4605f47..87a74ea 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 9646fd1..43f3ef6 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 a9947a5..aafcf25 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);

-- 
To stop receiving notification emails like this one, please contact
address@hidden.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]