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 (b98a6a4 -> 4432516)


From: gnunet
Subject: [GNUnet-SVN] [taler-merchant] branch master updated (b98a6a4 -> 4432516)
Date: Wed, 14 Jun 2017 15:29:06 +0200

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

marcello pushed a change to branch master
in repository merchant.

    from b98a6a4  refund table takes merchant public key too
     new e486247  add /refund route
     new 4432516  Implementing POST /refund logic.

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 src/backend/taler-merchant-httpd.c         |  18 +++--
 src/backend/taler-merchant-httpd_mhd.c     |   8 +--
 src/backend/taler-merchant-httpd_parsing.c |   3 +
 src/backend/taler-merchant-httpd_refund.c  | 105 ++++++++++++++++++++++++++++-
 src/backenddb/plugin_merchantdb_postgres.c |   2 +-
 5 files changed, 125 insertions(+), 11 deletions(-)

diff --git a/src/backend/taler-merchant-httpd.c 
b/src/backend/taler-merchant-httpd.c
index 8930c10..44831cc 100644
--- a/src/backend/taler-merchant-httpd.c
+++ b/src/backend/taler-merchant-httpd.c
@@ -175,9 +175,6 @@ url_handler (void *cls,
       { "/", MHD_HTTP_METHOD_GET, "text/plain",
         "Hello, I'm a merchant's Taler backend. This HTTP server is not for 
humans.\n", 0,
         &TMH_MHD_handler_static_response, MHD_HTTP_OK },
-      { "/proposal", MHD_HTTP_METHOD_POST, "application/json",
-        NULL, 0,
-        &MH_handler_proposal_put, MHD_HTTP_OK },
       { "/pay", MHD_HTTP_METHOD_POST, "application/json",
         NULL, 0,
         &MH_handler_pay, MHD_HTTP_OK },
@@ -199,13 +196,24 @@ url_handler (void *cls,
       { "/history", MHD_HTTP_METHOD_GET, "text/plain",
         "Only GET is allowed", 0,
         &MH_handler_history, MHD_HTTP_OK},
+      { "/proposal", MHD_HTTP_METHOD_POST, "application/json",
+        NULL, 0,
+        &MH_handler_proposal_put, MHD_HTTP_OK },
       { "/proposal", MHD_HTTP_METHOD_GET, "text/plain",
-        "Only GET is allowed", 0,
+        NULL, 0,
         &MH_handler_proposal_lookup, MHD_HTTP_OK},
       { "/proposal", NULL, "text/plain",
         "Only GET/POST are allowed", 0,
         &TMH_MHD_handler_send_json_pack_error, MHD_HTTP_METHOD_NOT_ALLOWED },
-
+      { "/refund", MHD_HTTP_METHOD_POST, "application/json",
+        NULL, 0,
+        &MH_handler_refund_increase, MHD_HTTP_OK},
+      { "/refund", MHD_HTTP_METHOD_GET, "text/plain",
+        NULL, 0,
+        &MH_handler_refund_lookup, MHD_HTTP_OK},
+      { "/refund", NULL, "application/json",
+        "Only POST/GET are allowed", 0,
+        &TMH_MHD_handler_send_json_pack_error, MHD_HTTP_METHOD_NOT_ALLOWED},
       {NULL, NULL, NULL, NULL, 0, 0 }
     };
   static struct TMH_RequestHandler h404 =
diff --git a/src/backend/taler-merchant-httpd_mhd.c 
b/src/backend/taler-merchant-httpd_mhd.c
index 9debb67..e4e5329 100644
--- a/src/backend/taler-merchant-httpd_mhd.c
+++ b/src/backend/taler-merchant-httpd_mhd.c
@@ -146,10 +146,10 @@ TMH_MHD_handler_send_json_pack_error (struct 
TMH_RequestHandler *rh,
                                          size_t *upload_data_size)
 {
   return TMH_RESPONSE_reply_json_pack (connection,
-                                     rh->response_code,
-                                     "{s:s}",
-                                     "error",
-                                     rh->data);
+                                       rh->response_code,
+                                       "{s:s}",
+                                       "error",
+                                       rh->data);
 }
 
 
diff --git a/src/backend/taler-merchant-httpd_parsing.c 
b/src/backend/taler-merchant-httpd_parsing.c
index 754ea90..6dc91ac 100644
--- a/src/backend/taler-merchant-httpd_parsing.c
+++ b/src/backend/taler-merchant-httpd_parsing.c
@@ -303,6 +303,9 @@ TMH_PARSE_json_data (struct MHD_Connection *connection,
   {
     if (NULL == error_json_name)
       error_json_name = "<no field>";
+    GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+                "Parsing failed due to field '%s'\n",
+                error_json_name);
     ret = (MHD_YES ==
            TMH_RESPONSE_reply_json_pack (connection,
                                          MHD_HTTP_BAD_REQUEST,
diff --git a/src/backend/taler-merchant-httpd_refund.c 
b/src/backend/taler-merchant-httpd_refund.c
index a55eb70..6167a9f 100644
--- a/src/backend/taler-merchant-httpd_refund.c
+++ b/src/backend/taler-merchant-httpd_refund.c
@@ -85,7 +85,21 @@ MH_handler_refund_increase (struct TMH_RequestHandler *rh,
 {
   int res;
   struct TMH_JsonParseContext *ctx;
+  struct TALER_Amount refund;
   json_t *root;
+  json_t *contract_terms;
+  const char *order_id;
+  const char *reason;
+  struct MerchantInstance *mi;
+  struct GNUNET_HashCode h_contract_terms;
+
+  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
+  }; 
+
 
   if (NULL == *connection_cls)
   {
@@ -109,9 +123,98 @@ MH_handler_refund_increase (struct TMH_RequestHandler *rh,
   if ((GNUNET_NO == res) || (NULL == root))
     return MHD_YES;
 
-  /* FIXME: TBD */
+  res = TMH_PARSE_json_data (connection,
+                             root,
+                             spec);
+  if (GNUNET_NO == res)
+  {
+    GNUNET_break_op (0);
+    return MHD_YES;
+  }
+
+  if (GNUNET_SYSERR == res)
+  {
+    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                "Hard error from JSON parser\n");
+    return MHD_NO;
+  }
+
+  mi = get_instance (root);
+  if (NULL == mi)
+  {
+    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                "No instance found\n");
+    GNUNET_JSON_parse_free (spec);
+    return TMH_RESPONSE_reply_not_found (connection,
+                                         TALER_EC_REFUND_INSTANCE_UNKNOWN,
+                                        "Unknown instance given");
+  }
+  
+  /* Convert order id to h_contract_terms */
+  if (GNUNET_OK != db->find_contract_terms (db->cls,
+                                            &contract_terms,
+                                            order_id,
+                                            &mi->pubkey))
+  {
+    GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 
+                "Unknown order id given: %s\n",
+                order_id);
+    return TMH_RESPONSE_reply_not_found (connection,
+                                         TALER_EC_REFUND_ORDER_ID_UNKNOWN,
+                                         "Order id not found in database");
+  }
+
+  if (GNUNET_OK !=
+      TALER_JSON_hash (contract_terms,
+                       &h_contract_terms))
+  {
+    GNUNET_JSON_parse_free (spec);
+    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                "Could not hash contract terms\n");
+    /**
+     * Do we really need a error code for failing to hash something?
+     * The HTTP 500 Internal server error sufficies for now.
+     */
+    return TMH_RESPONSE_reply_internal_error (connection,
+                                              TALER_EC_NONE,
+                                              "Could not hash contract terms");
+  }
+
+  res = db->increase_refund_for_contract (db->cls,
+                                          &h_contract_terms,
+                                          &mi->pubkey,
+                                          &refund,
+                                          reason);
+  if (GNUNET_NO == res)
+  {
+    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                "Inconsistent refund amount: %s\n",
+                TALER_amount_to_string (&refund));
+    GNUNET_JSON_parse_free (spec);
+    /**
+     * FIXME: should the db function distinguish between a refund amount
+     * lower than the previous one and a one which is too big to be paid back?
+     */
+    return TMH_RESPONSE_reply_external_error (connection,
+                                              
TALER_EC_REFUND_INCONSISTENT_AMOUNT,
+                                              "Amount either lower than the 
previous"
+                                              " or too big to be paid back");
+  }
+
+  /**
+   * FIXME: return to the frontend.  The frontend will then return
+   * a "402 Payment required" carrying a "X-Taler-Refund-Url: www"
+   * where 'www' is the URL where the wallet can automatically fetch
+   * the refund permission.
+   *
+   * Just a "200 OK" should be fine here, as the frontend has all
+   * the information needed to generate the right response.
+   */
+  return MHD_YES;
 
+  json_decref (contract_terms);
   json_decref (root);
+  GNUNET_JSON_parse_free (spec);
   return res;
 }
 
diff --git a/src/backenddb/plugin_merchantdb_postgres.c 
b/src/backenddb/plugin_merchantdb_postgres.c
index 3335051..679b055 100644
--- a/src/backenddb/plugin_merchantdb_postgres.c
+++ b/src/backenddb/plugin_merchantdb_postgres.c
@@ -602,7 +602,7 @@ postgres_find_contract_terms_from_hash (void *cls,
  * Retrieve proposal data given its order id.
  *
  * @param cls closure
- * @param[out] contract_terms where to store the retrieved proposal data
+ * @param[out] contract_terms where to store the retrieved contract terms
  * @param order id order id used to perform the lookup
  * @return #GNUNET_OK on success, #GNUNET_NO if no proposal is
  * found, #GNUNET_SYSERR upon error

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



reply via email to

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