gnunet-svn
[Top][All Lists]
Advanced

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

[taler-merchant] 77/277: POST /orders/ID/refund implementation


From: gnunet
Subject: [taler-merchant] 77/277: POST /orders/ID/refund implementation
Date: Sun, 05 Jul 2020 20:49:50 +0200

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

grothoff pushed a commit to branch master
in repository merchant.

commit dcc083c0959d395bcd4bcf9aee276eb96ea76dee
Author: Christian Grothoff <christian@grothoff.org>
AuthorDate: Sat May 2 17:11:55 2020 +0200

    POST /orders/ID/refund implementation
---
 src/backend/Makefile.am                            |   8 +-
 .../taler-merchant-httpd_post-orders-ID-abort.c    |   4 +-
 .../taler-merchant-httpd_post-orders-ID-claim.c    |  16 +-
 .../taler-merchant-httpd_post-orders-ID-pay.c      |   4 +-
 ...ler-merchant-httpd_private-patch-instances-ID.c |  16 +-
 ...aler-merchant-httpd_private-patch-products-ID.c |  36 +--
 .../taler-merchant-httpd_private-post-instances.c  |  16 +-
 ...-merchant-httpd_private-post-orders-ID-refund.c | 329 ++++++---------------
 ...-merchant-httpd_private-post-orders-ID-refund.h |  26 +-
 .../taler-merchant-httpd_private-post-orders.c     |  17 +-
 ...-merchant-httpd_private-post-products-ID-lock.c |  16 +-
 .../taler-merchant-httpd_private-post-products.c   |  36 +--
 ...-httpd_private-post-reserves-ID-authorize-tip.c |   4 +-
 src/include/taler_merchantdb_plugin.h              |  90 ++++--
 14 files changed, 207 insertions(+), 411 deletions(-)

diff --git a/src/backend/Makefile.am b/src/backend/Makefile.am
index f842257..049e0f4 100644
--- a/src/backend/Makefile.am
+++ b/src/backend/Makefile.am
@@ -49,14 +49,16 @@ taler_merchant_httpd_SOURCES = \
     taler-merchant-httpd_private-post-products.h \
   taler-merchant-httpd_private-post-products-ID-lock.c \
     taler-merchant-httpd_private-post-products-ID-lock.h \
+  taler-merchant-httpd_private-post-orders-ID-refund.c \
+    taler-merchant-httpd_private-post-orders-ID-refund.h \
   taler-merchant-httpd_private-post-orders.c \
     taler-merchant-httpd_private-post-orders.h \
+  taler-merchant-httpd_post-orders-ID-abort.c \
+    taler-merchant-httpd_post-orders-ID-abort.h \
   taler-merchant-httpd_post-orders-ID-claim.c \
     taler-merchant-httpd_post-orders-ID-claim.h \
   taler-merchant-httpd_post-orders-ID-pay.c \
-    taler-merchant-httpd_post-orders-ID-pay.h \
-  taler-merchant-httpd_post-orders-ID-abort.c \
-    taler-merchant-httpd_post-orders-ID-abort.h
+    taler-merchant-httpd_post-orders-ID-pay.h
 
 DEAD = \
   taler-merchant-httpd_check-payment.c taler-merchant-httpd_check-payment.h \
diff --git a/src/backend/taler-merchant-httpd_post-orders-ID-abort.c 
b/src/backend/taler-merchant-httpd_post-orders-ID-abort.c
index 7072a5a..08773a7 100644
--- a/src/backend/taler-merchant-httpd_post-orders-ID-abort.c
+++ b/src/backend/taler-merchant-httpd_post-orders-ID-abort.c
@@ -983,7 +983,9 @@ TMH_post_orders_ID_abort (const struct TMH_RequestHandler 
*rh,
                        hc,
                        ac);
     if (GNUNET_OK != ret)
-      return (GNUNET_NO == ret) ? MHD_YES : MHD_NO;
+      return (GNUNET_NO == ret)
+             ? MHD_YES
+             : MHD_NO;
   }
 
   /* Abort not finished, suspend while we interact with the exchange */
diff --git a/src/backend/taler-merchant-httpd_post-orders-ID-claim.c 
b/src/backend/taler-merchant-httpd_post-orders-ID-claim.c
index 6b3a922..17ef013 100644
--- a/src/backend/taler-merchant-httpd_post-orders-ID-claim.c
+++ b/src/backend/taler-merchant-httpd_post-orders-ID-claim.c
@@ -176,18 +176,10 @@ TMH_post_orders_ID_claim (const struct TMH_RequestHandler 
*rh,
     res = TALER_MHD_parse_json_data (connection,
                                      hc->request_body,
                                      spec);
-    /* json is malformed */
-    if (GNUNET_NO == res)
-    {
-      GNUNET_break_op (0);
-      return MHD_YES;
-    }
-    /* other internal errors might have occurred */
-    if (GNUNET_SYSERR == res)
-      return TALER_MHD_reply_with_error (connection,
-                                         MHD_HTTP_BAD_REQUEST,
-                                         TALER_EC_PARAMETER_MISSING,
-                                         "nonce");
+    if (GNUNET_OK != res)
+      return (GNUNET_NO == res)
+             ? MHD_YES
+             : MHD_NO;
   }
   contract_terms = NULL;
   for (unsigned int i = 0; i<MAX_RETRIES; i++)
diff --git a/src/backend/taler-merchant-httpd_post-orders-ID-pay.c 
b/src/backend/taler-merchant-httpd_post-orders-ID-pay.c
index 46bcaee..5962eb5 100644
--- a/src/backend/taler-merchant-httpd_post-orders-ID-pay.c
+++ b/src/backend/taler-merchant-httpd_post-orders-ID-pay.c
@@ -1822,7 +1822,9 @@ TMH_post_orders_ID_pay (const struct TMH_RequestHandler 
*rh,
                      hc,
                      pc);
     if (GNUNET_OK != ret)
-      return (GNUNET_NO == ret) ? MHD_YES : MHD_NO;
+      return (GNUNET_NO == ret)
+             ? MHD_YES
+             : MHD_NO;
   }
 
   /* Payment not finished, suspend while we interact with the exchange */
diff --git a/src/backend/taler-merchant-httpd_private-patch-instances-ID.c 
b/src/backend/taler-merchant-httpd_private-patch-instances-ID.c
index a4104b0..9255dca 100644
--- a/src/backend/taler-merchant-httpd_private-patch-instances-ID.c
+++ b/src/backend/taler-merchant-httpd_private-patch-instances-ID.c
@@ -96,18 +96,10 @@ TMH_private_patch_instances_ID (const struct 
TMH_RequestHandler *rh,
     res = TALER_MHD_parse_json_data (connection,
                                      hc->request_body,
                                      spec);
-    /* json is malformed */
-    if (GNUNET_NO == res)
-    {
-      GNUNET_break_op (0);
-      return MHD_YES;
-    }
-    /* other internal errors might have occurred */
-    if (GNUNET_SYSERR == res)
-      return TALER_MHD_reply_with_error (connection,
-                                         MHD_HTTP_INTERNAL_SERVER_ERROR,
-                                         TALER_EC_INTERNAL_INVARIANT_FAILURE,
-                                         "Impossible to parse the order");
+    if (GNUNET_OK != res)
+      return (GNUNET_NO == res)
+             ? MHD_YES
+             : MHD_NO;
   }
   if (! json_is_array (payto_uris))
     return TALER_MHD_reply_with_error (connection,
diff --git a/src/backend/taler-merchant-httpd_private-patch-products-ID.c 
b/src/backend/taler-merchant-httpd_private-patch-products-ID.c
index be7f52e..6bbaba2 100644
--- a/src/backend/taler-merchant-httpd_private-patch-products-ID.c
+++ b/src/backend/taler-merchant-httpd_private-patch-products-ID.c
@@ -161,18 +161,10 @@ TMH_private_patch_products_ID (const struct 
TMH_RequestHandler *rh,
     res = TALER_MHD_parse_json_data (connection,
                                      hc->request_body,
                                      spec);
-    /* json is malformed */
-    if (GNUNET_NO == res)
-    {
-      GNUNET_break_op (0);
-      return MHD_YES;
-    }
-    /* other internal errors might have occurred */
-    if (GNUNET_SYSERR == res)
-      return TALER_MHD_reply_with_error (connection,
-                                         MHD_HTTP_INTERNAL_SERVER_ERROR,
-                                         TALER_EC_INTERNAL_INVARIANT_FAILURE,
-                                         "Impossible to parse the product 
description");
+    if (GNUNET_OK != res)
+      return (GNUNET_NO == res)
+             ? MHD_YES
+             : MHD_NO;
   }
   if (-1 == total_stock)
     pd.total_stock = UINT64_MAX;
@@ -191,22 +183,10 @@ TMH_private_patch_products_ID (const struct 
TMH_RequestHandler *rh,
     res = TALER_MHD_parse_json_data (connection,
                                      hc->request_body,
                                      spec);
-    /* json is malformed */
-    if (GNUNET_NO == res)
-    {
-      GNUNET_break_op (0);
-      GNUNET_JSON_parse_free (spec);
-      return MHD_YES;
-    }
-    /* other internal errors might have occurred */
-    if (GNUNET_SYSERR == res)
-    {
-      GNUNET_JSON_parse_free (spec);
-      return TALER_MHD_reply_with_error (connection,
-                                         MHD_HTTP_INTERNAL_SERVER_ERROR,
-                                         TALER_EC_INTERNAL_INVARIANT_FAILURE,
-                                         "Impossible to parse the restock 
time");
-    }
+    if (GNUNET_OK != res)
+      return (GNUNET_NO == res)
+             ? MHD_YES
+             : MHD_NO;
   }
   else
   {
diff --git a/src/backend/taler-merchant-httpd_private-post-instances.c 
b/src/backend/taler-merchant-httpd_private-post-instances.c
index 2bfce6b..350a8ea 100644
--- a/src/backend/taler-merchant-httpd_private-post-instances.c
+++ b/src/backend/taler-merchant-httpd_private-post-instances.c
@@ -174,18 +174,10 @@ TMH_private_post_instances (const struct 
TMH_RequestHandler *rh,
     res = TALER_MHD_parse_json_data (connection,
                                      hc->request_body,
                                      spec);
-    /* json is malformed */
-    if (GNUNET_NO == res)
-    {
-      GNUNET_break_op (0);
-      return MHD_YES;
-    }
-    /* other internal errors might have occurred */
-    if (GNUNET_SYSERR == res)
-      return TALER_MHD_reply_with_error (connection,
-                                         MHD_HTTP_INTERNAL_SERVER_ERROR,
-                                         TALER_EC_INTERNAL_INVARIANT_FAILURE,
-                                         "Impossible to parse the order");
+    if (GNUNET_OK != res)
+      return (GNUNET_NO == res)
+             ? MHD_YES
+             : MHD_NO;
   }
 
   {
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 5324c61..44db612 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
@@ -14,16 +14,16 @@
   TALER; see the file COPYING.  If not, see <http://www.gnu.org/licenses/>
 */
 /**
- * @file backend/taler-merchant-httpd_refund_increase.c
+ * @file backend/taler-merchant-httpd_private-post-orders-ID-refund.c
  * @brief Handle request to increase the refund for an order
  * @author Marcello Stanisci
+ * @author Christian Grothoff
  */
 #include "platform.h"
 #include <jansson.h>
 #include <taler/taler_signatures.h>
 #include <taler/taler_json_lib.h>
-#include "taler-merchant-httpd.h"
-#include "taler-merchant-httpd_refund.h"
+#include "taler-merchant-httpd_private-post-orders-ID-refund.h"
 
 /**
  * How often do we retry the non-trivial refund INSERT database
@@ -32,26 +32,6 @@
 #define MAX_RETRIES 5
 
 
-/**
- * Information we keep for individual calls
- * to requests that parse JSON, but keep no other state.
- */
-struct TMH_JsonParseContext
-{
-
-  /**
-   * This field MUST be first for handle_mhd_completion_callback() to work
-   * when it treats this struct as a `struct TM_HandlerContext`.
-   */
-  struct TM_HandlerContext hc;
-
-  /**
-   * Placeholder for #TALER_MHD_parse_post_json() to keep its internal state.
-   */
-  void *json_parse_context;
-};
-
-
 /**
  * Make a taler://refund URI
  *
@@ -114,266 +94,129 @@ make_taler_refund_uri (struct MHD_Connection *connection,
 
 
 /**
- * Custom cleanup routine for a `struct TMH_JsonParseContext`.
- *
- * @param hc the `struct TMH_JsonParseContext` to clean up.
- */
-static void
-json_parse_cleanup (struct TM_HandlerContext *hc)
-{
-  struct TMH_JsonParseContext *jpc = (struct TMH_JsonParseContext *) hc;
-
-  TALER_MHD_parse_post_cleanup_callback (jpc->json_parse_context);
-  GNUNET_free (jpc);
-}
-
-
-/**
- * Process a refund request.
+ * Handle request for increasing the refund associated with
+ * a contract.
  *
- * @param connection HTTP client connection
- * @param mi merchant instance doing the processing
- * @param refund amount to be refunded
- * @param order_id for which order is the refund
- * @param reason reason for the refund
+ * @param rh context of the handler
+ * @param connection the MHD connection to handle
+ * @param[in,out] hc context with further information about the request
  * @return MHD result code
  */
-static MHD_RESULT
-process_refund (struct MHD_Connection *connection,
-                struct MerchantInstance *mi,
-                const struct TALER_Amount *refund,
-                const char *order_id,
-                const char *reason)
+MHD_RESULT
+MH_handler_refund_increase (const struct TMH_RequestHandler *rh,
+                            struct MHD_Connection *connection,
+                            struct TMH_HandlerContext *hc)
 {
-  json_t *contract_terms;
-  enum GNUNET_DB_QueryStatus qs;
-  enum GNUNET_DB_QueryStatus qsx;
-  struct GNUNET_HashCode h_contract_terms;
+  struct TALER_Amount refund;
+  const char *reason;
+  struct GNUNET_JSON_Specification spec[] = {
+    TALER_JSON_spec_amount ("refund", &refund),
+    GNUNET_JSON_spec_string ("reason", &reason),
+    GNUNET_JSON_spec_end ()
+  };
+  enum TALER_MERCHANTDB_RefundStatus rs;
 
-  db->preflight (db->cls);
-  /* Convert order id to h_contract_terms */
-  qs = db->find_contract_terms (db->cls,
-                                &contract_terms,
-                                order_id,
-                                &mi->pubkey);
-  if (0 > qs)
   {
-    /* single, read-only SQL statements should never cause
-       serialization problems */
-    GNUNET_break (GNUNET_DB_STATUS_SOFT_ERROR != qs);
-    /* Always report on hard error as well to enable diagnostics */
-    GNUNET_break (GNUNET_DB_STATUS_HARD_ERROR == qs);
-    return TALER_MHD_reply_with_error (connection,
-                                       MHD_HTTP_INTERNAL_SERVER_ERROR,
-                                       TALER_EC_REFUND_LOOKUP_DB_ERROR,
-                                       "An error occurred while retrieving 
payment data from db");
-  }
-  if (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS == qs)
-  {
-    GNUNET_log (GNUNET_ERROR_TYPE_INFO,
-                "Unknown order id given: `%s'\n",
-                order_id);
-    return TALER_MHD_reply_with_error (connection,
-                                       MHD_HTTP_NOT_FOUND,
-                                       TALER_EC_REFUND_ORDER_ID_UNKNOWN,
-                                       "order_id not found in database");
+    enum GNUNET_GenericReturnValue res;
+
+    res = TALER_MHD_parse_json_data (connection,
+                                     hc->request_body,
+                                     spec);
+    if (GNUNET_OK != res)
+      return (GNUNET_NO == res)
+             ? MHD_YES
+             : MHD_NO;
   }
 
-  if (GNUNET_OK !=
-      TALER_JSON_hash (contract_terms,
-                       &h_contract_terms))
-  {
-    GNUNET_break (0);
-    json_decref (contract_terms);
-    return TALER_MHD_reply_with_error (connection,
-                                       MHD_HTTP_INTERNAL_SERVER_ERROR,
-                                       TALER_EC_INTERNAL_LOGIC_ERROR,
-                                       "Could not hash contract terms");
-  }
-  json_decref (contract_terms);
+  TMH_db->preflight (TMH_db->cls);
   for (unsigned int i = 0; i<MAX_RETRIES; i++)
   {
     if (GNUNET_OK !=
-        db->start (db->cls,
-                   "increase refund"))
+        TMH_db->start (TMH_db->cls,
+                       "increase refund"))
     {
       GNUNET_break (0);
       return GNUNET_DB_STATUS_HARD_ERROR;
     }
-    qs = db->increase_refund_for_contract_NT (db->cls,
-                                              &h_contract_terms,
-                                              &mi->pubkey,
-                                              refund,
-                                              reason);
+    rs = TMH_db->increase_refund (TMH_db->cls,
+                                  hc->instance->settings.id,
+                                  hc->infix,
+                                  &refund,
+                                  reason);
     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
                 "increase refund returned %d\n",
-                qs);
-    if (GNUNET_DB_STATUS_HARD_ERROR == qs)
-    {
-      GNUNET_break (0);
-      db->rollback (db->cls);
-      break;
-    }
-    if (GNUNET_DB_STATUS_SOFT_ERROR == qs)
-    {
-      db->rollback (db->cls);
+                rs);
+    if (TALER_MERCHANTDB_RS_SUCCESS != rs)
+      TMH_db->rollback (TMH_db->cls);
+    if (TALER_MERCHANTDB_RS_SOFT_ERROR == rs)
       continue;
-    }
-    /* Got one or more deposits */
-    if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT != qs)
+    if (TALER_MERCHANTDB_RS_SUCCESS == rs)
     {
-      db->rollback (db->cls);
-      break;
+      enum GNUNET_DB_QueryStatus qs;
+
+      qs = TMH_db->commit (TMH_db->cls);
+      if (GNUNET_DB_STATUS_HARD_ERROR == qs)
+      {
+        GNUNET_break (0);
+        rs = TALER_MERCHANTDB_RS_HARD_ERROR;
+        break;
+      }
+      if (GNUNET_DB_STATUS_SOFT_ERROR == qs)
+        continue;
     }
-    qsx = db->commit (db->cls);
-    if (GNUNET_DB_STATUS_HARD_ERROR == qsx)
-    {
-      GNUNET_break (0);
-      qs = qsx;
-      break;
-    }
-    if (GNUNET_DB_STATUS_SOFT_ERROR != qsx)
-      break;
-  }
-  if (0 > qs)
-  {
-    /* Special report if retries insufficient */
-    GNUNET_break (GNUNET_DB_STATUS_SOFT_ERROR != qs);
-    /* Always report on hard error as well to enable diagnostics */
-    GNUNET_break (GNUNET_DB_STATUS_HARD_ERROR == qs);
-    return TALER_MHD_reply_with_error (connection,
-                                       MHD_HTTP_INTERNAL_SERVER_ERROR,
-                                       
TALER_EC_REFUND_MERCHANT_DB_COMMIT_ERROR,
-                                       "Internal database error or refund 
amount too big");
-  }
-  if (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS == qs)
+    break;
+  } /* retries loop */
+
+  switch (rs)
   {
+  case TALER_MERCHANTDB_RS_TOO_HIGH:
     GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
                 "Refusing refund amount %s that is larger than original 
payment\n",
-                TALER_amount2s (refund));
+                TALER_amount2s (&refund));
     return TALER_MHD_reply_with_error (connection,
                                        MHD_HTTP_CONFLICT,
                                        TALER_EC_REFUND_INCONSISTENT_AMOUNT,
                                        "Amount above payment");
+  case TALER_MERCHANTDB_RS_HARD_ERROR:
+  case TALER_MERCHANTDB_RS_SOFT_ERROR:
+    return TALER_MHD_reply_with_error (connection,
+                                       MHD_HTTP_INTERNAL_SERVER_ERROR,
+                                       
TALER_EC_REFUND_MERCHANT_DB_COMMIT_ERROR,
+                                       "Internal database error");
+  case TALER_MERCHANTDB_RS_NO_SUCH_ORDER:
+    return TALER_MHD_reply_with_error (connection,
+                                       MHD_HTTP_NOT_FOUND,
+                                       TALER_EC_REFUND_ORDER_ID_UNKNOWN,
+                                       "Order unknown (or never paid)");
+  case TALER_MERCHANTDB_RS_SUCCESS:
+    break;
   }
 
-  /* Resume /public/poll-payments clients that may wait for this refund */
+  /* Resume clients that may wait for this refund */
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
               "Awakeing clients on %s waiting for refund of less than %s\n",
-              order_id,
-              TALER_amount2s (refund));
-
-  TMH_long_poll_resume (order_id,
-                        &mi->pubkey,
-                        refund);
+              hc->infix,
+              TALER_amount2s (&refund));
+  TMH_long_poll_resume (hc->infix,
+                        hc->instance,
+                        &refund);
 
   {
     MHD_RESULT ret;
     char *taler_refund_uri;
 
     taler_refund_uri = make_taler_refund_uri (connection,
-                                              mi->id,
-                                              order_id);
-    ret = TALER_MHD_reply_json_pack (
-      connection,
-      MHD_HTTP_OK,
-      "{s:o, s:s}",
-      "h_contract_terms",
-      GNUNET_JSON_from_data_auto (&h_contract_terms),
-      "taler_refund_url",
-      taler_refund_uri);
+                                              hc->instance->settings.id,
+                                              hc->infix);
+    ret = TALER_MHD_reply_json_pack (connection,
+                                     MHD_HTTP_OK,
+                                     "{s:s}",
+                                     "taler_refund_url",
+                                     taler_refund_uri);
     GNUNET_free (taler_refund_uri);
     return ret;
   }
 }
 
 
-/**
- * Handle request for increasing the refund associated with
- * a contract.
- *
- * @param connection the MHD connection to handle
- * @param[in,out] connection_cls the connection's closure (can be updated)
- * @param upload_data upload data
- * @param[in,out] upload_data_size number of bytes (left) in @a upload_data
- * @param mi merchant backend instance, never NULL
- * @return MHD result code
- */
-MHD_RESULT
-MH_handler_refund_increase (struct TMH_RequestHandler *rh,
-                            struct MHD_Connection *connection,
-                            void **connection_cls,
-                            const char *upload_data,
-                            size_t *upload_data_size,
-                            struct MerchantInstance *mi)
-{
-  enum GNUNET_GenericReturnValue res;
-  struct TMH_JsonParseContext *ctx;
-  struct TALER_Amount refund;
-  const char *order_id;
-  const char *reason;
-  struct GNUNET_JSON_Specification spec[] = {
-    TALER_JSON_spec_amount ("refund", &refund),
-    GNUNET_JSON_spec_string ("order_id", &order_id),
-    GNUNET_JSON_spec_string ("reason", &reason),
-    GNUNET_JSON_spec_end ()
-  };
-  json_t *root;
-
-  if (NULL == *connection_cls)
-  {
-    ctx = GNUNET_new (struct TMH_JsonParseContext);
-    ctx->hc.cc = &json_parse_cleanup;
-    *connection_cls = ctx;
-  }
-  else
-  {
-    ctx = *connection_cls;
-  }
-
-  res = TALER_MHD_parse_post_json (connection,
-                                   &ctx->json_parse_context,
-                                   upload_data,
-                                   upload_data_size,
-                                   &root);
-  if (GNUNET_SYSERR == res)
-    return MHD_NO;
-  /* the POST's body has to be further fetched */
-  if ( (GNUNET_NO == res) ||
-       (NULL == root) )
-    return MHD_YES;
-
-  res = TALER_MHD_parse_json_data (connection,
-                                   root,
-                                   spec);
-  if (GNUNET_NO == res)
-  {
-    GNUNET_break_op (0);
-    json_decref (root);
-    return MHD_YES;
-  }
-  if (GNUNET_SYSERR == res)
-  {
-    GNUNET_break_op (0);
-    json_decref (root);
-    return TALER_MHD_reply_with_error (connection,
-                                       MHD_HTTP_BAD_REQUEST,
-                                       TALER_EC_JSON_INVALID,
-                                       "Request body does not match 
specification");
-  }
-  {
-    MHD_RESULT ret;
-
-    ret = process_refund (connection,
-                          mi,
-                          &refund,
-                          order_id,
-                          reason);
-    GNUNET_JSON_parse_free (spec);
-    json_decref (root);
-    return ret;
-  }
-}
-
-
-/* end of taler-merchant-httpd_refund_increase.c */
+/* end of taler-merchant-httpd_private-post-orders-ID-refund.c */
diff --git a/src/backend/taler-merchant-httpd_private-post-orders-ID-refund.h 
b/src/backend/taler-merchant-httpd_private-post-orders-ID-refund.h
index ff17800..8912011 100644
--- a/src/backend/taler-merchant-httpd_private-post-orders-ID-refund.h
+++ b/src/backend/taler-merchant-httpd_private-post-orders-ID-refund.h
@@ -1,6 +1,6 @@
 /*
   This file is part of TALER
-  (C) 2014, 2015, 2016, 2017 Taler Systems SA
+  (C) 2014, 2015, 2016, 2017, 2020 Taler Systems SA
 
   TALER is free software; you can redistribute it and/or modify it under the
   terms of the GNU Affero General Public License as published by the Free 
Software
@@ -13,15 +13,14 @@
   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 backend/taler-merchant-httpd_refund_increase.h
- * @brief HTTP serving layer mainly intended to communicate with the frontend
+ * @file backend/taler-merchant-httpd_private-post-orders-ID-refund.h
+ * @brief Handle request to increase the refund for an order
  * @author Marcello Stanisci
+ * @author Christian Grothoff
  */
-
-#ifndef TALER_MERCHANT_HTTPD_REFUND_INCREASE_H
-#define TALER_MERCHANT_HTTPD_REFUND_INCREASE_H
+#ifndef TALER_MERCHANT_HTTPD_PRIVATE_POST_ORDERS_ID_REFUND_H
+#define TALER_MERCHANT_HTTPD_PRIVATE_POST_ORDERS_ID_REFUND_H
 #include <microhttpd.h>
 #include "taler-merchant-httpd.h"
 
@@ -30,20 +29,15 @@
  * Handle request for increasing the refund associated with
  * a contract.
  *
+ * @param rh context of the handler
  * @param connection the MHD connection to handle
- * @param[in,out] connection_cls the connection's closure (can be updated)
- * @param upload_data upload data
- * @param[in,out] upload_data_size number of bytes (left) in @a upload_data
- * @param mi merchant backend instance, never NULL
+ * @param[in,out] hc context with further information about the request
  * @return MHD result code
  */
 MHD_RESULT
-MH_handler_refund_increase (struct TMH_RequestHandler *rh,
+MH_handler_refund_increase (const struct TMH_RequestHandler *rh,
                             struct MHD_Connection *connection,
-                            void **connection_cls,
-                            const char *upload_data,
-                            size_t *upload_data_size,
-                            struct MerchantInstance *mi);
+                            struct TMH_HandlerContext *hc);
 
 
 #endif
diff --git a/src/backend/taler-merchant-httpd_private-post-orders.c 
b/src/backend/taler-merchant-httpd_private-post-orders.c
index 9d3c5c0..e6af258 100644
--- a/src/backend/taler-merchant-httpd_private-post-orders.c
+++ b/src/backend/taler-merchant-httpd_private-post-orders.c
@@ -328,19 +328,10 @@ execute_order (struct MHD_Connection *connection,
     res = TALER_MHD_parse_json_data (connection,
                                      order,
                                      spec);
-    /* json is malformed */
-    if (GNUNET_NO == res)
-    {
-      return MHD_YES;
-    }
-    /* other internal errors might have occurred */
-    if (GNUNET_SYSERR == res)
-    {
-      return TALER_MHD_reply_with_error (connection,
-                                         MHD_HTTP_INTERNAL_SERVER_ERROR,
-                                         TALER_EC_PROPOSAL_ORDER_PARSE_ERROR,
-                                         "Impossible to parse the order");
-    }
+    if (GNUNET_OK != res)
+      return (GNUNET_NO == res)
+             ? MHD_YES
+             : MHD_NO;
   }
   if (0 !=
       strcasecmp (total.currency,
diff --git a/src/backend/taler-merchant-httpd_private-post-products-ID-lock.c 
b/src/backend/taler-merchant-httpd_private-post-products-ID-lock.c
index bc35efd..ddd891a 100644
--- a/src/backend/taler-merchant-httpd_private-post-products-ID-lock.c
+++ b/src/backend/taler-merchant-httpd_private-post-products-ID-lock.c
@@ -64,18 +64,10 @@ TMH_private_post_products_ID_lock (const struct 
TMH_RequestHandler *rh,
     res = TALER_MHD_parse_json_data (connection,
                                      hc->request_body,
                                      spec);
-    /* json is malformed */
-    if (GNUNET_NO == res)
-    {
-      GNUNET_break_op (0);
-      return MHD_YES;
-    }
-    /* other internal errors might have occurred */
-    if (GNUNET_SYSERR == res)
-      return TALER_MHD_reply_with_error (connection,
-                                         MHD_HTTP_INTERNAL_SERVER_ERROR,
-                                         TALER_EC_INTERNAL_INVARIANT_FAILURE,
-                                         "Impossible to parse the lock 
request");
+    if (GNUNET_OK != res)
+      return (GNUNET_NO == res)
+             ? MHD_YES
+             : MHD_NO;
   }
 
   qs = TMH_db->lock_product (TMH_db->cls,
diff --git a/src/backend/taler-merchant-httpd_private-post-products.c 
b/src/backend/taler-merchant-httpd_private-post-products.c
index 7fd62db..c291845 100644
--- a/src/backend/taler-merchant-httpd_private-post-products.c
+++ b/src/backend/taler-merchant-httpd_private-post-products.c
@@ -117,18 +117,10 @@ TMH_private_post_products (const struct 
TMH_RequestHandler *rh,
     res = TALER_MHD_parse_json_data (connection,
                                      hc->request_body,
                                      spec);
-    /* json is malformed */
-    if (GNUNET_NO == res)
-    {
-      GNUNET_break_op (0);
-      return MHD_YES;
-    }
-    /* other internal errors might have occurred */
-    if (GNUNET_SYSERR == res)
-      return TALER_MHD_reply_with_error (connection,
-                                         MHD_HTTP_INTERNAL_SERVER_ERROR,
-                                         TALER_EC_INTERNAL_INVARIANT_FAILURE,
-                                         "Impossible to parse the order");
+    if (GNUNET_OK != res)
+      return (GNUNET_NO == res)
+             ? MHD_YES
+             : MHD_NO;
   }
 
   if (-1 == total_stock)
@@ -148,22 +140,10 @@ TMH_private_post_products (const struct 
TMH_RequestHandler *rh,
     res = TALER_MHD_parse_json_data (connection,
                                      hc->request_body,
                                      spec);
-    /* json is malformed */
-    if (GNUNET_NO == res)
-    {
-      GNUNET_break_op (0);
-      GNUNET_JSON_parse_free (spec);
-      return MHD_YES;
-    }
-    /* other internal errors might have occurred */
-    if (GNUNET_SYSERR == res)
-    {
-      GNUNET_JSON_parse_free (spec);
-      return TALER_MHD_reply_with_error (connection,
-                                         MHD_HTTP_INTERNAL_SERVER_ERROR,
-                                         TALER_EC_INTERNAL_INVARIANT_FAILURE,
-                                         "Impossible to parse the restock 
time");
-    }
+    if (GNUNET_OK != res)
+      return (GNUNET_NO == res)
+             ? MHD_YES
+             : MHD_NO;
   }
   else
   {
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 569cf0a..a0f2ec3 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
@@ -171,7 +171,9 @@ MH_handler_tip_authorize (struct TMH_RequestHandler *rh,
     if (GNUNET_YES != res)
     {
       GNUNET_break_op (0);
-      return (GNUNET_NO == res) ? MHD_YES : MHD_NO;
+      return (GNUNET_NO == res)
+             ? MHD_YES
+             : MHD_NO;
     }
     tac->parsed_json = GNUNET_YES;
   }
diff --git a/src/include/taler_merchantdb_plugin.h 
b/src/include/taler_merchantdb_plugin.h
index bca1071..f5396a4 100644
--- a/src/include/taler_merchantdb_plugin.h
+++ b/src/include/taler_merchantdb_plugin.h
@@ -461,6 +461,40 @@ typedef void
   const struct TALER_Amount *refund_fee);
 
 
+/**
+ * Results from trying to increase a refund.
+ */
+enum TALER_MERCHANTDB_RefundStatus
+{
+
+  /**
+   * Refund amount exceeds original payment.
+   */
+  TALER_MERCHANTDB_RS_TOO_HIGH = -3,
+
+  /**
+   * Hard database failure.
+   */
+  TALER_MERCHANTDB_RS_HARD_ERROR = -2,
+
+  /**
+   * Soft database failure.
+   */
+  TALER_MERCHANTDB_RS_SOFT_ERROR = -1,
+
+  /**
+   * Order not found.
+   */
+  TALER_MERCHANTDB_RS_NO_SUCH_ORDER = 0,
+
+  /**
+   * Refund is now at or above the requested amount.
+   */
+  TALER_MERCHANTDB_RS_SUCCESS = 1
+
+};
+
+
 /**
  * Handle to interact with the database.
  *
@@ -1037,6 +1071,33 @@ struct TALER_MERCHANTDB_Plugin
                          bool *paid);
 
 
+  /**
+   * Function called when some backoffice staff decides to award or
+   * increase the refund on an existing contract.  This function
+   * MUST be called from within a transaction scope setup by the
+   * caller as it executes multiple SQL statements.
+   *
+   * @param cls closure
+   * @param instance_id instance identifier
+   * @param order_id the order to increase the refund for
+   * @param refund maximum refund to return to the customer for this contract
+   * @param reason 0-terminated UTF-8 string giving the reason why the customer
+   *               got a refund (free form, business-specific)
+   * @return transaction status
+   *        #GNUNET_DB_STATUS_SUCCESS_NO_RESULTS if @a refund is ABOVE the 
amount we
+   *        were originally paid and thus the transaction failed;
+   *        #GNUNET_DB_STATUS_SUCCESS_ONE_RESULT if the request is valid,
+   *        regardless of whether it actually increased the refund beyond
+   *        what was already refunded (idempotency!)
+   */
+  enum TALER_MERCHANTDB_RefundStatus
+  (*increase_refund)(void *cls,
+                     const char *instance_id,
+                     const char *order_id,
+                     const struct TALER_Amount *refund,
+                     const char *reason);
+
+
   /* ****************** OLD API ******************** */
 
 
@@ -1357,35 +1418,6 @@ struct TALER_MERCHANTDB_Plugin
                      struct TALER_MasterSignatureP *exchange_sig);
 
 
-  /**
-   * Function called when some backoffice staff decides to award or
-   * increase the refund on an existing contract.  This function
-   * MUST be called from within a transaction scope setup by the
-   * caller as it executes multiple SQL statements (NT).
-   *
-   * @param cls closure
-   * @param merchant_pub merchant's instance public key
-   * @param h_contract_terms
-   * @param merchant_pub merchant's instance public key
-   * @param refund maximum refund to return to the customer for this contract
-   * @param reason 0-terminated UTF-8 string giving the reason why the customer
-   *               got a refund (free form, business-specific)
-   * @return transaction status
-   *        #GNUNET_DB_STATUS_SUCCESS_NO_RESULTS if @a refund is ABOVE the 
amount we
-   *        were originally paid and thus the transaction failed;
-   *        #GNUNET_DB_STATUS_SUCCESS_ONE_RESULT if the request is valid,
-   *        regardless of whether it actually increased the refund beyond
-   *        what was already refunded (idempotency!)
-   */
-  enum GNUNET_DB_QueryStatus
-  (*increase_refund_for_contract_NT)(
-    void *cls,
-    const struct GNUNET_HashCode *h_contract_terms,
-    const struct TALER_MerchantPublicKeyP *merchant_pub,
-    const struct TALER_Amount *refund,
-    const char *reason);
-
-
   /**
    * Obtain refund proofs associated with a refund operation on a
    * coin.

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