gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] [taler-merchant] 02/04: Increase refund on a unpaid contrac


From: gnunet
Subject: [GNUnet-SVN] [taler-merchant] 02/04: Increase refund on a unpaid contract.
Date: Tue, 22 May 2018 08:59:24 +0200

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

marcello pushed a commit to branch master
in repository merchant.

commit 07f3974c54b8bf4084ddc452cf1f10263c20050d
Author: Marcello Stanisci <address@hidden>
AuthorDate: Mon May 21 14:44:10 2018 +0200

    Increase refund on a unpaid contract.
---
 src/lib/merchant_api_refund.c    | 27 ++++++++++++++++++++-------
 src/lib/test_merchant_api_new.c  | 34 ++++++++++++++++++++++++++++++++++
 src/lib/testing_api_cmd_refund.c |  2 +-
 3 files changed, 55 insertions(+), 8 deletions(-)

diff --git a/src/lib/merchant_api_refund.c b/src/lib/merchant_api_refund.c
index 2f02735..e3a09d6 100644
--- a/src/lib/merchant_api_refund.c
+++ b/src/lib/merchant_api_refund.c
@@ -121,9 +121,13 @@ handle_refund_increase_finished (void *cls,
     GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
                 "Backend didn't even return from POST /refund\n");
     return;
+
+  /* Tolerate Bad Request here in order to let
+   * test cases move along.  */
   case MHD_HTTP_OK:
+  case MHD_HTTP_BAD_REQUEST:
     rio->cb (rio->cb_cls,
-             MHD_HTTP_OK,
+             response_code,
              TALER_EC_NONE,
              json);
     break;
@@ -133,13 +137,22 @@ handle_refund_increase_finished (void *cls,
      * NOTE that json must be a Taler-specific error object (FIXME,
      * need a link to error objects at docs)
      */
-    json_unpack ((json_t *) json,
-                 "{s:s, s:I, s:s}",
-                 "error", &error,
-                 "code", &code,
-                 "hint", &hint);
+    if (-1 == json_unpack
+        ((json_t *) json,
+         "{s:s, s:I, s:s}",
+         "error", &error,
+         "code", &code,
+         "hint", &hint))
+    
+    {
+      GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                "/refund failed (HTTP code: %lu), backend did "
+                "not give a valid error object\n", response_code);
+      break;
+    }
+
     GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
-                "Failed POST /refund, error: %s, code: %d, hint: %s\n",
+                "/refund, error: %s, code: %d, hint: %s\n",
                 error,
                 code,
                 hint);
diff --git a/src/lib/test_merchant_api_new.c b/src/lib/test_merchant_api_new.c
index e78c57c..2c8b953 100644
--- a/src/lib/test_merchant_api_new.c
+++ b/src/lib/test_merchant_api_new.c
@@ -472,6 +472,40 @@ run (void *cls,
                                      "deposit-simple",
                                      "1"),
 
+    /* Test /refund on a contract that was never paid.  */
+
+    TALER_TESTING_cmd_proposal
+      ("create-proposal-not-to-be-paid",
+       merchant_url,
+       is->ctx,
+       MHD_HTTP_OK,
+       "{\"max_fee\":\
+          {\"currency\":\"EUR\",\
+           \"value\":0,\
+           \"fraction\":50000000},\
+        \"order_id\":\"1-unpaid\",\
+        \"refund_deadline\":\"\\/Date(0)\\/\",\
+        \"pay_deadline\":\"\\/Date(99999999999)\\/\",\
+        \"amount\":\
+          {\"currency\":\"EUR\",\
+           \"value\":5,\
+           \"fraction\":0},\
+        \"summary\": \"useful product\",\
+        \"fulfillment_url\": \"https://example.com/\",\
+        \"products\": [ {\"description\":\"ice cream\",\
+                         \"value\":\"{EUR:5}\"} ] }",
+        NULL),
+
+    TALER_TESTING_cmd_refund_increase
+      ("refund-increase-unpaid-proposal",
+       merchant_url,
+       is->ctx,
+       "refund test",
+       "1-unpaid",
+       "EUR:0.1",
+       "EUR:0.01",
+       MHD_HTTP_BAD_REQUEST),
+
     /* Test tipping.  */
     TALER_TESTING_cmd_fakebank_transfer_with_instance
       ("create-reserve-tip-1",
diff --git a/src/lib/testing_api_cmd_refund.c b/src/lib/testing_api_cmd_refund.c
index 2202510..2abc89a 100644
--- a/src/lib/testing_api_cmd_refund.c
+++ b/src/lib/testing_api_cmd_refund.c
@@ -129,7 +129,7 @@ refund_increase_cb (void *cls,
   struct RefundIncreaseState *ris = cls;
 
   ris->rio = NULL;
-  if (MHD_HTTP_OK != http_status)
+  if (ris->http_code != http_status)
     TALER_TESTING_FAIL (ris->is);
 
   TALER_TESTING_interpreter_next (ris->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]