gnunet-svn
[Top][All Lists]
Advanced

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

[taler-merchant] 01/51: add choice_index to private get orders id


From: gnunet
Subject: [taler-merchant] 01/51: add choice_index to private get orders id
Date: Thu, 13 Jun 2024 17:03:10 +0200

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

christian-blaettler pushed a commit to branch master
in repository merchant.

commit b15e3ce135f51d29d64864f2fdd227326a299947
Author: Christian Blättler <blatc2@bfh.ch>
AuthorDate: Thu Apr 18 15:01:13 2024 +0200

    add choice_index to private get orders id
---
 ...taler-merchant-httpd_private-delete-orders-ID.c |  5 ++++-
 .../taler-merchant-httpd_private-get-orders-ID.c   | 26 ++++++++++++++++++++--
 src/backenddb/pg_lookup_contract_terms3.c          | 15 ++++++++++++-
 src/backenddb/pg_lookup_contract_terms3.h          |  6 +++--
 src/include/taler_merchantdb_plugin.h              |  4 +++-
 5 files changed, 49 insertions(+), 7 deletions(-)

diff --git a/src/backend/taler-merchant-httpd_private-delete-orders-ID.c 
b/src/backend/taler-merchant-httpd_private-delete-orders-ID.c
index cd8aa10c..625b7b6b 100644
--- a/src/backend/taler-merchant-httpd_private-delete-orders-ID.c
+++ b/src/backend/taler-merchant-httpd_private-delete-orders-ID.c
@@ -20,6 +20,7 @@
  */
 #include "platform.h"
 #include "taler-merchant-httpd_private-delete-orders-ID.h"
+#include <stdint.h>
 #include <taler/taler_json_lib.h>
 
 
@@ -80,6 +81,7 @@ TMH_private_delete_orders_ID (const struct TMH_RequestHandler 
*rh,
       bool paid = false;
       bool wired = false;
       bool matches = false;
+      uint16_t *choice_index = NULL;
 
       qs = TMH_db->lookup_order (TMH_db->cls,
                                  mi->settings.id,
@@ -98,7 +100,8 @@ TMH_private_delete_orders_ID (const struct 
TMH_RequestHandler *rh,
                                              &paid,
                                              &wired,
                                              &matches,
-                                             NULL);
+                                             NULL,
+                                             &choice_index);
       }
       if (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS == qs)
         return TALER_MHD_reply_with_error (connection,
diff --git a/src/backend/taler-merchant-httpd_private-get-orders-ID.c 
b/src/backend/taler-merchant-httpd_private-get-orders-ID.c
index 98653997..50626876 100644
--- a/src/backend/taler-merchant-httpd_private-get-orders-ID.c
+++ b/src/backend/taler-merchant-httpd_private-get-orders-ID.c
@@ -22,6 +22,9 @@
 #include "platform.h"
 #include "taler-merchant-httpd_private-get-orders-ID.h"
 #include "taler-merchant-httpd_get-orders-ID.h"
+#include <gnunet/gnunet_json_lib.h>
+#include <jansson.h>
+#include <stdint.h>
 #include <taler/taler_json_lib.h>
 #include <taler/taler_dbevents.h>
 #include "taler-merchant-httpd_mhd.h"
@@ -315,6 +318,12 @@ struct GetOrderRequestContext
    */
   uint64_t order_serial;
 
+  /**
+   * Index of selected choice from ``choices`` array in the contract_terms.
+   * Is -1 for orders without choices.
+   */
+  int16_t choice_index;
+
   /**
    * Total refunds granted for this payment. Only initialized
    * if @e refunded is set to true.
@@ -610,6 +619,7 @@ phase_fetch_contract (struct GetOrderRequestContext *gorc)
     gorc->order_only = false;
   }
   TMH_db->preflight (TMH_db->cls);
+  /* TODO: Check if choice_index is actually set to NULL if not in db. */
   qs = TMH_db->lookup_contract_terms3 (TMH_db->cls,
                                        hc->instance->settings.id,
                                        hc->infix,
@@ -619,7 +629,8 @@ phase_fetch_contract (struct GetOrderRequestContext *gorc)
                                        &gorc->paid,
                                        &gorc->wired,
                                        &gorc->paid_session_matches,
-                                       &gorc->claim_token);
+                                       &gorc->claim_token,
+                                       &gorc->choice_index);
   GNUNET_log (GNUNET_ERROR_TYPE_INFO,
               "lookup_contract_terms (%s) returned %d\n",
               hc->infix,
@@ -1376,6 +1387,7 @@ phase_reply_result (struct GetOrderRequestContext *gorc)
   struct TMH_HandlerContext *hc = gorc->hc;
   MHD_RESULT ret;
   char *order_status_url;
+  json_t *choice_index = json_null();
 
   {
     struct TALER_PrivateContractHashP *h_contract = NULL;
@@ -1403,6 +1415,12 @@ phase_reply_result (struct GetOrderRequestContext *gorc)
                   TALER_amount_is_zero (&gorc->contract_amount));
     gorc->last_payment = gorc->timestamp;
   }
+  if (-1 != gorc->choice_index) {
+    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+                "Choice index is %d\n",
+                gorc->choice_index);
+    choice_index = json_integer ((json_int_t) gorc->choice_index);
+  }
   ret = TALER_MHD_REPLY_JSON_PACK (
     gorc->sc.con,
     MHD_HTTP_OK,
@@ -1440,7 +1458,11 @@ phase_reply_result (struct GetOrderRequestContext *gorc)
     GNUNET_JSON_pack_array_steal ("refund_details",
                                   gorc->refund_details),
     GNUNET_JSON_pack_string ("order_status_url",
-                             order_status_url));
+                             order_status_url),
+    {
+      .field_name = "choice_index",
+      .object = choice_index,
+    });
   GNUNET_free (order_status_url);
   gorc->wire_details = NULL;
   gorc->refund_details = NULL;
diff --git a/src/backenddb/pg_lookup_contract_terms3.c 
b/src/backenddb/pg_lookup_contract_terms3.c
index ef955a51..4c6fd477 100644
--- a/src/backenddb/pg_lookup_contract_terms3.c
+++ b/src/backenddb/pg_lookup_contract_terms3.c
@@ -20,6 +20,7 @@
  * @author Christian Grothoff
  */
 #include "platform.h"
+#include <sys/types.h>
 #include <taler/taler_error_codes.h>
 #include <taler/taler_dbevents.h>
 #include <taler/taler_pq_lib.h>
@@ -38,11 +39,14 @@ TMH_PG_lookup_contract_terms3 (
   bool *paid,
   bool *wired,
   bool *session_matches,
-  struct TALER_ClaimTokenP *claim_token)
+  struct TALER_ClaimTokenP *claim_token,
+  int16_t *choice_index)
 {
   struct PostgresClosure *pg = cls;
   enum GNUNET_DB_QueryStatus qs;
   struct TALER_ClaimTokenP ct;
+  uint16_t ci;
+  bool choice_index_null = false;
   struct GNUNET_PQ_QueryParam params[] = {
     GNUNET_PQ_query_param_string (instance_id),
     GNUNET_PQ_query_param_string (order_id),
@@ -67,6 +71,10 @@ TMH_PG_lookup_contract_terms3 (
       NULL),
     GNUNET_PQ_result_spec_auto_from_type ("claim_token",
                                           &ct),
+    GNUNET_PQ_result_spec_allow_null (
+      GNUNET_PQ_result_spec_uint16 ("choice_index",
+                                    &ci),
+      &choice_index_null),
     GNUNET_PQ_result_spec_end
   };
 
@@ -81,6 +89,7 @@ TMH_PG_lookup_contract_terms3 (
            ",paid"
            ",wired"
            ",(session_id=$3) AS session_matches"
+           ",choice_index"
            " FROM merchant_contract_terms"
            " WHERE order_id=$2"
            "   AND merchant_serial="
@@ -95,5 +104,9 @@ TMH_PG_lookup_contract_terms3 (
                                                    : &rs[1]);
   if (NULL != claim_token)
     *claim_token = ct;
+  if (! choice_index_null)
+    *choice_index = ci;
+  else
+    *choice_index = -1;
   return qs;
 }
diff --git a/src/backenddb/pg_lookup_contract_terms3.h 
b/src/backenddb/pg_lookup_contract_terms3.h
index d1cc78a2..14463835 100644
--- a/src/backenddb/pg_lookup_contract_terms3.h
+++ b/src/backenddb/pg_lookup_contract_terms3.h
@@ -37,7 +37,8 @@
  * @param[out] paid set to true if the order is fully paid
  * @param[out] wired set to true if the exchange wired the funds
  * @param[out] session_matches set to true if @a session_id matches session 
stored for this contract
-   * @param[out] claim_token set to token to use for access control
+ * @param[out] claim_token set to token to use for access control
+ * @param[out] choice_index set to the choice index, -1 if not set
  * @return transaction status
  */
 enum GNUNET_DB_QueryStatus
@@ -51,6 +52,7 @@ TMH_PG_lookup_contract_terms3 (
   bool *paid,
   bool *wired,
   bool *session_matches,
-  struct TALER_ClaimTokenP *claim_token);
+  struct TALER_ClaimTokenP *claim_token,
+  int16_t *choice_index);
 
 #endif
diff --git a/src/include/taler_merchantdb_plugin.h 
b/src/include/taler_merchantdb_plugin.h
index 44fdc0ab..23122702 100644
--- a/src/include/taler_merchantdb_plugin.h
+++ b/src/include/taler_merchantdb_plugin.h
@@ -1903,6 +1903,7 @@ struct TALER_MERCHANTDB_Plugin
    * @param[out] wired set to true if the exchange wired the funds
    * @param[out] session_matches set to true if @a session_id matches session 
stored for this contract
    * @param[out] claim_token set to the claim token, NULL to only check for 
existence
+   * @param[out] choice_index set to the choice index, -1 if not set
    * @return transaction status
    */
   enum GNUNET_DB_QueryStatus
@@ -1916,7 +1917,8 @@ struct TALER_MERCHANTDB_Plugin
     bool *paid,
     bool *wired,
     bool *session_matches,
-    struct TALER_ClaimTokenP *claim_token);
+    struct TALER_ClaimTokenP *claim_token,
+    int16_t *choice_index);
 
 
   /**

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