gnunet-svn
[Top][All Lists]
Advanced

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

[taler-merchant] branch master updated: parse/test refund uri


From: gnunet
Subject: [taler-merchant] branch master updated: parse/test refund uri
Date: Thu, 20 Aug 2020 07:01:16 +0200

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

jonathan-buchanan pushed a commit to branch master
in repository merchant.

The following commit(s) were added to refs/heads/master by this push:
     new 8d17285  parse/test refund uri
     new 9fce403  Merge branch 'master' of ssh://git.taler.net/merchant
8d17285 is described below

commit 8d172853c1c7b1ca8d9dc31194c4e73e79499a80
Author: Jonathan Buchanan <jonathan.russ.buchanan@gmail.com>
AuthorDate: Thu Aug 20 00:49:02 2020 -0400

    parse/test refund uri
---
 src/backend/taler-merchant-httpd_get-orders-ID.c   |  2 ++
 ...-merchant-httpd_private-post-orders-ID-refund.c |  2 ++
 src/include/taler_merchant_service.h               |  4 ++-
 src/lib/merchant_api_post_order_refund.c           | 37 ++++++++++++++++---
 src/testing/testing_api_cmd_refund_order.c         | 41 +++++++++++++++++++++-
 5 files changed, 79 insertions(+), 7 deletions(-)

diff --git a/src/backend/taler-merchant-httpd_get-orders-ID.c 
b/src/backend/taler-merchant-httpd_get-orders-ID.c
index 142ba99..027f9f4 100644
--- a/src/backend/taler-merchant-httpd_get-orders-ID.c
+++ b/src/backend/taler-merchant-httpd_get-orders-ID.c
@@ -265,6 +265,8 @@ make_taler_refund_uri (struct MHD_Connection *con,
   }
   GNUNET_buffer_write_path (&buf,
                             order_id);
+  GNUNET_buffer_write_path (&buf,
+                            ""); // Trailing slash
   return GNUNET_buffer_reap_str (&buf);
 }
 
diff --git a/src/backend/taler-merchant-httpd_private-post-orders-ID-refund.c 
b/src/backend/taler-merchant-httpd_private-post-orders-ID-refund.c
index 16f21d1..7d947d2 100644
--- a/src/backend/taler-merchant-httpd_private-post-orders-ID-refund.c
+++ b/src/backend/taler-merchant-httpd_private-post-orders-ID-refund.c
@@ -85,6 +85,8 @@ make_taler_refund_uri (struct MHD_Connection *connection,
     GNUNET_buffer_write_path (&buf, instance_id);
   }
   GNUNET_buffer_write_path (&buf, order_id);
+  GNUNET_buffer_write_path (&buf,
+                            ""); // Trailing slash
 
   return GNUNET_buffer_reap_str (&buf);
 }
diff --git a/src/include/taler_merchant_service.h 
b/src/include/taler_merchant_service.h
index 771cfbe..b0be501 100644
--- a/src/include/taler_merchant_service.h
+++ b/src/include/taler_merchant_service.h
@@ -2352,11 +2352,13 @@ struct TALER_MERCHANT_OrderRefundHandle;
  * @param cls closure
  * @param http_status HTTP status code for this request
  * @param ec taler-specific error code
+ * @param taler_refund_uri the refund uri offered to the wallet
  */
 typedef void
 (*TALER_MERCHANT_RefundCallback) (
   void *cls,
-  const struct TALER_MERCHANT_HttpResponse *hr);
+  const struct TALER_MERCHANT_HttpResponse *hr,
+  const char *taler_refund_uri);
 
 
 /**
diff --git a/src/lib/merchant_api_post_order_refund.c 
b/src/lib/merchant_api_post_order_refund.c
index fb93864..834aea5 100644
--- a/src/lib/merchant_api_post_order_refund.c
+++ b/src/lib/merchant_api_post_order_refund.c
@@ -94,18 +94,44 @@ handle_refund_finished (void *cls,
   case 0:
     hr.ec = TALER_EC_INVALID_RESPONSE;
     orh->cb (orh->cb_cls,
-             &hr);
+             &hr,
+             NULL);
     break;
   case MHD_HTTP_OK:
-    orh->cb (orh->cb_cls,
-             &hr);
+    {
+      const char *taler_refund_uri;
+      struct GNUNET_JSON_Specification spec[] = {
+        GNUNET_JSON_spec_string ("taler_refund_uri",
+                                 &taler_refund_uri),
+        GNUNET_JSON_spec_end ()
+      };
+
+      if (GNUNET_OK !=
+          GNUNET_JSON_parse (json,
+                             spec,
+                             NULL, NULL))
+      {
+        GNUNET_break_op (0);
+        hr.http_status = 0;
+        hr.ec = TALER_EC_INVALID_RESPONSE;
+        orh->cb (orh->cb_cls,
+                 &hr,
+                 NULL);
+        break;
+      }
+      orh->cb (orh->cb_cls,
+               &hr,
+               taler_refund_uri);
+      GNUNET_JSON_parse_free (spec);
+    }
     break;
   case MHD_HTTP_CONFLICT:
   case MHD_HTTP_NOT_FOUND:
     hr.ec = TALER_JSON_get_error_code (json);
     hr.hint = TALER_JSON_get_error_hint (json);
     orh->cb (orh->cb_cls,
-             &hr);
+             &hr,
+             NULL);
     break;
   default:
     GNUNET_break_op (0); /* unexpected status code */
@@ -113,7 +139,8 @@ handle_refund_finished (void *cls,
                                          response_code,
                                          &hr);
     orh->cb (orh->cb_cls,
-             &hr);
+             &hr,
+             NULL);
     break;
   }
   TALER_MERCHANT_post_order_refund_cancel (orh);
diff --git a/src/testing/testing_api_cmd_refund_order.c 
b/src/testing/testing_api_cmd_refund_order.c
index ab6f78a..bf8474d 100644
--- a/src/testing/testing_api_cmd_refund_order.c
+++ b/src/testing/testing_api_cmd_refund_order.c
@@ -77,10 +77,12 @@ struct RefundState
  *
  * @param cls closure
  * @param hr HTTP response
+ * @param taler_refund_uri the refund uri offered to the wallet
  */
 static void
 refund_cb (void *cls,
-           const struct TALER_MERCHANT_HttpResponse *hr)
+           const struct TALER_MERCHANT_HttpResponse *hr,
+           const char *taler_refund_uri)
 {
   struct RefundState *ris = cls;
 
@@ -94,6 +96,43 @@ refund_cb (void *cls,
                 (int) hr->ec);
     TALER_TESTING_FAIL (ris->is);
   }
+  switch (hr->http_status)
+  {
+  case MHD_HTTP_OK:
+    {
+      struct TALER_MERCHANT_RefundUriData rud;
+
+      if (GNUNET_OK !=
+          TALER_MERCHANT_parse_refund_uri (taler_refund_uri,
+                                           &rud))
+      {
+        GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                    "Taler refund uri is malformed\n");
+        TALER_TESTING_interpreter_fail (ris->is);
+        return;
+      }
+
+      if ((0 != strcmp ("localhost:8080",
+                        rud.merchant_host)) ||
+          (NULL != rud.merchant_prefix_path) ||
+          (0 != strcmp (ris->order_id,
+                        rud.order_id)) ||
+          (NULL != rud.ssid))
+      {
+        GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                    "Taler refund uri does not match\n");
+        TALER_TESTING_interpreter_fail (ris->is);
+        TALER_MERCHANT_parse_refund_uri_free (&rud);
+        return;
+      }
+
+      TALER_MERCHANT_parse_refund_uri_free (&rud);
+    }
+    break;
+  default:
+    GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+                "Unhandled HTTP status.\n");
+  }
   TALER_TESTING_interpreter_next (ris->is);
 }
 

-- 
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.



reply via email to

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