gnunet-svn
[Top][All Lists]
Advanced

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

[taler-merchant] branch master updated: address #7820


From: gnunet
Subject: [taler-merchant] branch master updated: address #7820
Date: Wed, 26 Apr 2023 00:20:06 +0200

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

grothoff pushed a commit to branch master
in repository merchant.

The following commit(s) were added to refs/heads/master by this push:
     new 7afc0181 address #7820
7afc0181 is described below

commit 7afc01815adb8d8d8d638526d1bf8caa66b7f3b4
Author: Christian Grothoff <christian@grothoff.org>
AuthorDate: Wed Apr 26 00:15:30 2023 +0200

    address #7820
---
 .../taler-merchant-httpd_post-orders-ID-paid.c     | 43 +++++++++++++---
 src/include/taler_merchant_service.h               | 32 +++++++++++-
 src/lib/merchant_api_post_order_paid.c             | 58 +++++++++++++++-------
 src/testing/test_kyc_api.c                         |  4 +-
 src/testing/test_merchant_api.c                    |  2 +-
 src/testing/testing_api_cmd_post_orders_paid.c     | 10 ++--
 6 files changed, 113 insertions(+), 36 deletions(-)

diff --git a/src/backend/taler-merchant-httpd_post-orders-ID-paid.c 
b/src/backend/taler-merchant-httpd_post-orders-ID-paid.c
index 946e30a1..54d4b930 100644
--- a/src/backend/taler-merchant-httpd_post-orders-ID-paid.c
+++ b/src/backend/taler-merchant-httpd_post-orders-ID-paid.c
@@ -1,6 +1,6 @@
 /*
   This file is part of TALER
-  (C) 2014-2021 Taler Systems SA
+  (C) 2014-2023 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
@@ -30,6 +30,26 @@
 #include "taler-merchant-httpd_post-orders-ID-paid.h"
 
 
+/**
+ * Function called with information about a refund.
+ * Sets the boolean in @a cls to true when called.
+ *
+ * @param cls closure, a `bool *`
+ * @param coin_pub public coin from which the refund comes from
+ * @param refund_amount refund amount which is being taken from @a coin_pub
+ */
+static void
+refund_cb (
+  void *cls,
+  const struct TALER_CoinSpendPublicKeyP *coin_pub,
+  const struct TALER_Amount *refund_amount)
+{
+  bool *refunded = cls;
+
+  *refunded = true;
+}
+
+
 /**
  * Use database to notify other clients about the
  * session being captured.
@@ -202,12 +222,21 @@ TMH_post_orders_ID_paid (const struct TMH_RequestHandler 
*rh,
                                   session_id,
                                   fulfillment_url);
   /* fulfillment_url is part of the contract_terms */
-  json_decref (contract_terms);
-  return TALER_MHD_reply_static (connection,
-                                 MHD_HTTP_NO_CONTENT,
-                                 NULL,
-                                 NULL,
-                                 0);
+  {
+    bool refunded = false;
+
+    qs = TMH_db->lookup_refunds (TMH_db->cls,
+                                 hc->instance->settings.id,
+                                 &hct,
+                                 &refund_cb,
+                                 &refunded);
+    json_decref (contract_terms);
+    return TALER_MHD_REPLY_JSON_PACK (
+      connection,
+      MHD_HTTP_OK,
+      GNUNET_JSON_pack_bool ("refunded",
+                             refunded));
+  }
 }
 
 
diff --git a/src/include/taler_merchant_service.h 
b/src/include/taler_merchant_service.h
index 8cf8fbcc..143556b1 100644
--- a/src/include/taler_merchant_service.h
+++ b/src/include/taler_merchant_service.h
@@ -2529,18 +2529,46 @@ TALER_MERCHANT_order_pay_cancel (struct 
TALER_MERCHANT_OrderPayHandle *oph);
  */
 struct TALER_MERCHANT_OrderPaidHandle;
 
+/**
+ * Reponse to an /orders/$ID/paid request.
+ */
+struct TALER_MERCHANT_OrderPaidResponse
+{
+  /**
+   * HTTP response details.
+   */
+  struct TALER_MERCHANT_HttpResponse hr;
+  /**
+   * HTTP-status code dependent details.
+   */
+  union
+  {
+    /**
+     * Details on success.
+     */
+    struct
+    {
+      /**
+       * Set to true if the order was paid but also
+       * refunded.
+       */
+      bool refunded;
+    } success;
+  } details;
+};
+
 
 /**
  * Callbacks of this type are used to serve the result of submitting a
  * POST /orders/$ID/paid request to a merchant.
  *
  * @param cls closure
- * @param hr HTTP response details
+ * @param oprr response details
  */
 typedef void
 (*TALER_MERCHANT_OrderPaidCallback) (
   void *cls,
-  const struct TALER_MERCHANT_HttpResponse *hr);
+  const struct TALER_MERCHANT_OrderPaidResponse *opr);
 
 
 /**
diff --git a/src/lib/merchant_api_post_order_paid.c 
b/src/lib/merchant_api_post_order_paid.c
index a42b1255..a483ba41 100644
--- a/src/lib/merchant_api_post_order_paid.c
+++ b/src/lib/merchant_api_post_order_paid.c
@@ -90,9 +90,9 @@ handle_paid_finished (void *cls,
 {
   struct TALER_MERCHANT_OrderPaidHandle *oph = cls;
   const json_t *json = response;
-  struct TALER_MERCHANT_HttpResponse hr = {
-    .http_status = (unsigned int) response_code,
-    .reply = json
+  struct TALER_MERCHANT_OrderPaidResponse opr = {
+    .hr.http_status = (unsigned int) response_code,
+    .hr.reply = json
   };
 
   oph->job = NULL;
@@ -102,61 +102,81 @@ handle_paid_finished (void *cls,
   switch (response_code)
   {
   case 0:
-    hr.ec = TALER_EC_GENERIC_INVALID_RESPONSE;
+    opr.hr.ec = TALER_EC_GENERIC_INVALID_RESPONSE;
     break;
-  case MHD_HTTP_NO_CONTENT:
+  case MHD_HTTP_OK:
+    {
+      bool refunded;
+      struct GNUNET_JSON_Specification spec[] = {
+        GNUNET_JSON_spec_bool ("refunded",
+                               &refunded),
+        GNUNET_JSON_spec_end ()
+      };
+
+      if (GNUNET_OK !=
+          GNUNET_JSON_parse (opr.hr.reply,
+                             spec,
+                             NULL,
+                             NULL))
+      {
+        GNUNET_break_op (0);
+        opr.hr.ec = TALER_EC_GENERIC_INVALID_RESPONSE;
+        break;
+      }
+      break;
+    }
     break;
   case MHD_HTTP_BAD_REQUEST:
-    hr.ec = TALER_JSON_get_error_code (json);
-    hr.hint = TALER_JSON_get_error_hint (json);
+    opr.hr.ec = TALER_JSON_get_error_code (json);
+    opr.hr.hint = TALER_JSON_get_error_hint (json);
     /* This should never happen, either us
      * or the merchant is buggy (or API version conflict);
      * just pass JSON reply to the application */
     break;
   case MHD_HTTP_FORBIDDEN:
-    hr.ec = TALER_JSON_get_error_code (json);
-    hr.hint = TALER_JSON_get_error_hint (json);
+    opr.hr.ec = TALER_JSON_get_error_code (json);
+    opr.hr.hint = TALER_JSON_get_error_hint (json);
     /* The signature provided was invalid */
     break;
   case MHD_HTTP_NOT_FOUND:
-    hr.ec = TALER_JSON_get_error_code (json);
-    hr.hint = TALER_JSON_get_error_hint (json);
+    opr.hr.ec = TALER_JSON_get_error_code (json);
+    opr.hr.hint = TALER_JSON_get_error_hint (json);
     /* Nothing really to verify, this should never
        happen, we should pass the JSON reply to the
        application */
     break;
   case MHD_HTTP_CONFLICT:
-    hr.ec = TALER_JSON_get_error_code (json);
-    hr.hint = TALER_JSON_get_error_hint (json);
+    opr.hr.ec = TALER_JSON_get_error_code (json);
+    opr.hr.hint = TALER_JSON_get_error_hint (json);
     /* The hashed contract terms don't match with the order_id. */
     break;
   case MHD_HTTP_INTERNAL_SERVER_ERROR:
-    hr.ec = TALER_JSON_get_error_code (json);
-    hr.hint = TALER_JSON_get_error_hint (json);
+    opr.hr.ec = TALER_JSON_get_error_code (json);
+    opr.hr.hint = TALER_JSON_get_error_hint (json);
     /* Server had an internal issue; we should retry,
        but this API leaves this to the application */
     break;
   case MHD_HTTP_SERVICE_UNAVAILABLE:
     TALER_MERCHANT_parse_error_details_ (json,
                                          response_code,
-                                         &hr);
+                                         &opr.hr);
     /* Exchange couldn't respond properly; the retry is
        left to the application */
     break;
   default:
     TALER_MERCHANT_parse_error_details_ (json,
                                          response_code,
-                                         &hr);
+                                         &opr.hr);
     /* unexpected response code */
     GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
                 "Unexpected response code %u/%d\n",
                 (unsigned int) response_code,
-                (int) hr.ec);
+                (int) opr.hr.ec);
     GNUNET_break_op (0);
     break;
   }
   oph->paid_cb (oph->paid_cb_cls,
-                &hr);
+                &opr);
   TALER_MERCHANT_order_paid_cancel (oph);
 }
 
diff --git a/src/testing/test_kyc_api.c b/src/testing/test_kyc_api.c
index 8cb30f8b..902a46ce 100644
--- a/src/testing/test_kyc_api.c
+++ b/src/testing/test_kyc_api.c
@@ -210,7 +210,7 @@ run (void *cls,
                                                  merchant_url,
                                                  "deposit-simple",
                                                  "session-1",
-                                                 MHD_HTTP_NO_CONTENT),
+                                                 MHD_HTTP_OK),
     TALER_TESTING_cmd_check_bank_empty ("check_bank_empty-1"),
     CMD_EXEC_AGGREGATOR ("run-aggregator"),
     /* KYC: hence nothing happened at the bank yet: */
@@ -324,7 +324,7 @@ run (void *cls,
                                                  merchant_url,
                                                  "deposit-simple",
                                                  "session-aml",
-                                                 MHD_HTTP_NO_CONTENT),
+                                                 MHD_HTTP_OK),
     TALER_TESTING_cmd_check_bank_empty ("check_bank_empty-aml-1"),
     CMD_EXEC_AGGREGATOR ("run-aggregator-aml-frozen"),
     /* AML-frozen: hence nothing happened at the bank yet: */
diff --git a/src/testing/test_merchant_api.c b/src/testing/test_merchant_api.c
index a106b8be..99ed291b 100644
--- a/src/testing/test_merchant_api.c
+++ b/src/testing/test_merchant_api.c
@@ -451,7 +451,7 @@ run (void *cls,
                                                  merchant_url,
                                                  "deposit-simple",
                                                  "session-1",
-                                                 MHD_HTTP_NO_CONTENT),
+                                                 MHD_HTTP_OK),
     TALER_TESTING_cmd_wallet_get_order ("get-order-wallet-1-2",
                                         merchant_url,
                                         "create-proposal-1",
diff --git a/src/testing/testing_api_cmd_post_orders_paid.c 
b/src/testing/testing_api_cmd_post_orders_paid.c
index 6c4e41cd..645a0010 100644
--- a/src/testing/testing_api_cmd_post_orders_paid.c
+++ b/src/testing/testing_api_cmd_post_orders_paid.c
@@ -71,21 +71,21 @@ struct PostOrdersPaidState
  * Response from the merchant after POST /paid.
  *
  * @param cls pointer to `struct PostOrdersPaidState`.
- * @param hr the http response.
+ * @param opr the response.
  */
 static void
 paid_cb (void *cls,
-         const struct TALER_MERCHANT_HttpResponse *hr)
+         const struct TALER_MERCHANT_OrderPaidResponse *opr)
 {
   struct PostOrdersPaidState *ops = cls;
 
   ops->oph = NULL;
-  if (ops->http_status != hr->http_status)
+  if (ops->http_status != opr->hr.http_status)
   {
     GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
                 "Unexpected response code %u (%d) to command %s\n",
-                hr->http_status,
-                (int) hr->ec,
+                opr->hr.http_status,
+                (int) opr->hr.ec,
                 TALER_TESTING_interpreter_get_current_label (ops->is));
     TALER_TESTING_FAIL (ops->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]