gnunet-svn
[Top][All Lists]
Advanced

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

[taler-merchant] branch master updated: update using templates


From: gnunet
Subject: [taler-merchant] branch master updated: update using templates
Date: Wed, 21 Dec 2022 17:27:06 +0100

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

priscilla-huang pushed a commit to branch master
in repository merchant.

The following commit(s) were added to refs/heads/master by this push:
     new a36a978d update using templates
a36a978d is described below

commit a36a978df4d0a4bc065ebd1e4ad08cdb9e19d7ea
Author: priscilla <priscilla.huang@efrei.net>
AuthorDate: Wed Dec 21 11:26:50 2022 -0500

    update using templates
---
 src/include/taler_merchant_service.h               |   2 +-
 src/lib/merchant_api_post_using_templates.c        |  13 +-
 src/testing/testing_api_cmd_post_using_templates.c | 190 +++++++++++++++++++++
 3 files changed, 197 insertions(+), 8 deletions(-)

diff --git a/src/include/taler_merchant_service.h 
b/src/include/taler_merchant_service.h
index c5bef549..c9224684 100644
--- a/src/include/taler_merchant_service.h
+++ b/src/include/taler_merchant_service.h
@@ -4397,7 +4397,7 @@ TALER_MERCHANT_using_templates_post (
   struct GNUNET_CURL_Context *ctx,
   const char *backend_url,
   const char *summary,
-  struct TALER_Amount amount,
+  const struct TALER_Amount *amount,
   TALER_MERCHANT_UsingTemplatesPostCallback cb,
   void *cb_cls);
 
diff --git a/src/lib/merchant_api_post_using_templates.c 
b/src/lib/merchant_api_post_using_templates.c
index 278fcac8..9a4aa93d 100644
--- a/src/lib/merchant_api_post_using_templates.c
+++ b/src/lib/merchant_api_post_using_templates.c
@@ -101,6 +101,10 @@ handle_post_using_templates_finished (void *cls,
     break;
   case MHD_HTTP_NO_CONTENT:
     break;
+  case MHD_HTTP_NOT_ACCEPTABLE:
+    hr.ec = TALER_JSON_get_error_code (json);
+    hr.hint = TALER_JSON_get_error_hint (json);
+    break;
   case MHD_HTTP_BAD_REQUEST:
     hr.ec = TALER_JSON_get_error_code (json);
     hr.hint = TALER_JSON_get_error_hint (json);
@@ -108,11 +112,6 @@ handle_post_using_templates_finished (void *cls,
      * or the merchant is buggy (or API version conflict);
      * just pass JSON reply to the application */
     break;
-  case MHD_HTTP_UNAUTHORIZED:
-    hr.ec = TALER_JSON_get_error_code (json);
-    hr.hint = TALER_JSON_get_error_hint (json);
-    /* Nothing really to verify, merchant says we need to authenticate. */
-    break;
   case MHD_HTTP_FORBIDDEN:
     hr.ec = TALER_JSON_get_error_code (json);
     hr.hint = TALER_JSON_get_error_hint (json);
@@ -160,7 +159,7 @@ TALER_MERCHANT_using_templates_post (
   struct GNUNET_CURL_Context *ctx,
   const char *backend_url,
   const char *summary,
-  struct TALER_Amount amount,
+  const struct TALER_Amount *amount,
   TALER_MERCHANT_UsingTemplatesPostCallback cb,
   void *cb_cls)
 {
@@ -173,7 +172,7 @@ TALER_MERCHANT_using_templates_post (
                                summary)),
     GNUNET_JSON_pack_allow_null (
       TALER_JSON_pack_amount ("amount",
-                              &amount)));
+                              amount)));
   utph = GNUNET_new (struct TALER_MERCHANT_UsingTemplatesPostHandle);
   utph->ctx = ctx;
   utph->cb = cb;
diff --git a/src/testing/testing_api_cmd_post_using_templates.c 
b/src/testing/testing_api_cmd_post_using_templates.c
new file mode 100644
index 00000000..d286364c
--- /dev/null
+++ b/src/testing/testing_api_cmd_post_using_templates.c
@@ -0,0 +1,190 @@
+/*
+  This file is part of TALER
+  Copyright (C) 2020 Taler Systems SA
+
+  TALER is free software; you can redistribute it and/or modify
+  it under the terms of the GNU General Public License as
+  published by the Free Software Foundation; either version 3, or
+  (at your option) any later version.
+
+  TALER is distributed in the hope that it will be useful, but
+  WITHOUT ANY WARRANTY; without even the implied warranty of
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+  GNU General Public License for more details.
+
+  You should have received a copy of the GNU General Public
+  License along with TALER; see the file COPYING.  If not, see
+  <http://www.gnu.org/licenses/>
+*/
+/**
+ * @file testing_api_cmd_post_using_templates.c
+ * @brief command to test POST /using-templates
+ * @author Priscilla HUANG
+ */
+#include "platform.h"
+#include <taler/taler_exchange_service.h>
+#include <taler/taler_testing_lib.h>
+#include "taler_merchant_service.h"
+#include "taler_merchant_testing_lib.h"
+
+/**
+ * State of a "POST /templates" CMD.
+ */
+struct PostUsingTemplatesState
+{
+
+  /**
+   * Handle for a "GET using-template" request.
+   */
+  struct TALER_MERCHANT_UsingTemplatesPostHandle *iph;
+
+  /**
+   * The interpreter state.
+   */
+  struct TALER_TESTING_Interpreter *is;
+
+  /**
+   * Base URL of the merchant serving the request.
+   */
+  const char *merchant_url;
+
+  /**
+   * Summary given by the customer.
+   */
+  const char *summary;
+
+  /**
+   * Amount given by the customer.
+   */
+  struct TALER_Amount amount;
+
+  /**
+   * Expected HTTP response code.
+   */
+  unsigned int http_status;
+
+};
+
+
+/**
+ * Callback for a POST /using-templates operation.
+ *
+ * @param cls closure for this function
+ * @param hr response being processed
+ */
+static void
+post_using_templates_cb (void *cls,
+                         const struct TALER_MERCHANT_HttpResponse *hr)
+{
+  struct PostUsingTemplatesState *tis = cls;
+
+  tis->iph = NULL;
+  if (tis->http_status != hr->http_status)
+  {
+    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                "Unexpected response code %u (%d) to command %s\n",
+                hr->http_status,
+                (int) hr->ec,
+                TALER_TESTING_interpreter_get_current_label (tis->is));
+    TALER_TESTING_interpreter_fail (tis->is);
+    return;
+  }
+  switch (hr->http_status)
+  {
+  case MHD_HTTP_NO_CONTENT:
+    break;
+  case MHD_HTTP_NOT_ACCEPTABLE:
+    break;
+  case MHD_HTTP_CONFLICT:
+    break;
+  case MHD_HTTP_FORBIDDEN:
+    break;
+  case MHD_HTTP_NOT_FOUND:
+    break;
+  default:
+    GNUNET_break (0);
+    GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+                "Unhandled HTTP status %u for POST /templates/$ID.\n",
+                hr->http_status);
+  }
+  TALER_TESTING_interpreter_next (tis->is);
+}
+
+/**
+ * Run the "POST /using-templates" CMD.
+ *
+ *
+ * @param cls closure.
+ * @param cmd command being run now.
+ * @param is interpreter state.
+ */
+static void
+post_using_templates_run (void *cls,
+                          const struct TALER_TESTING_Command *cmd,
+                          struct TALER_TESTING_Interpreter *is)
+{
+  struct PostUsingTemplatesState *tis = cls;
+
+  tis->is = is;
+  tis->iph = TALER_MERCHANT_templates_post (is->ctx,
+                                           tis->merchant_url,
+                                           tis->summary,
+                                           tis->amount,
+                                           &post_using_templates_cb,
+                                           tis);
+  GNUNET_assert (NULL != tis->iph);
+}
+
+/**
+ * Offers information from the POST /using-templates CMD state to other
+ * commands.
+ *
+ * @param cls closure
+ * @param[out] ret result (could be anything)
+ * @param trait name of the trait
+ * @param index index number of the object to extract.
+ * @return #GNUNET_OK on success
+ */
+static int
+post_using_templates_traits (void *cls,
+                             const void **ret,
+                             const char *trait,
+                             unsigned int index)
+{
+  struct PostUsingTemplatesState *pts = cls;
+  struct TALER_TESTING_Trait traits[] = {
+    TALER_TESTING_make_trait_sumamry (&pts->summary),
+    TALER_TESTING_make_trait_amount (&pts->amount),
+    TALER_TESTING_trait_end (),
+  };
+
+  return TALER_TESTING_get_trait (traits,
+                                  ret,
+                                  trait,
+                                  index);
+}
+
+
+/**
+ * Free the state of a "POST using-template" CMD, and possibly
+ * cancel a pending operation thereof.
+ *
+ * @param cls closure.
+ * @param cmd command being run.
+ */
+static void
+post_using_templates_cleanup (void *cls,
+                              const struct TALER_TESTING_Command *cmd)
+{
+  struct PostTemplatesState *tis = cls;
+
+  if (NULL != tis->iph)
+  {
+    GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+                "POST /templates operation did not complete\n");
+    TALER_MERCHANT_templates_post_cancel (tis->iph);
+  }
+  GNUNET_free (tis->image);
+  json_decref (tis->template_contract);
+  GNUNET_free (tis);
+}

-- 
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]