merchant

Merchant backend to process payments, run by merchants
Log | Files | Refs | Submodules | README | LICENSE

update_contract_session.c (3363B)


      1 /*
      2    This file is part of TALER
      3    Copyright (C) 2025 Taler Systems SA
      4 
      5    TALER is free software; you can redistribute it and/or modify it under the
      6    terms of the GNU General Public License as published by the Free Software
      7    Foundation; either version 3, or (at your option) any later version.
      8 
      9    TALER is distributed in the hope that it will be useful, but WITHOUT ANY
     10    WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
     11    A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
     12 
     13    You should have received a copy of the GNU General Public License along with
     14    TALER; see the file COPYING.  If not, see <http://www.gnu.org/licenses/>
     15  */
     16 /**
     17  * @file src/backenddb/update_contract_session.c
     18  * @brief Implementation of the update_contract_session function for Postgres
     19  * @author Christian Grothoff
     20  */
     21 #include "platform.h"
     22 #include <taler/taler_error_codes.h>
     23 #include <taler/taler_dbevents.h>
     24 #include <taler/taler_pq_lib.h>
     25 #include "merchant-database/update_contract_session.h"
     26 #include "helper.h"
     27 
     28 
     29 enum GNUNET_DB_QueryStatus
     30 TALER_MERCHANTDB_update_contract_session (struct TALER_MERCHANTDB_PostgresContext *pg,
     31                                           const char *instance_id,
     32                                           const struct TALER_PrivateContractHashP *h_contract_terms,
     33                                           const char *session_id,
     34                                           char **fulfillment_url,
     35                                           bool *refunded)
     36 {
     37   struct GNUNET_PQ_QueryParam params[] = {
     38     GNUNET_PQ_query_param_string (instance_id),
     39     GNUNET_PQ_query_param_auto_from_type (h_contract_terms),
     40     GNUNET_PQ_query_param_string (session_id),
     41     GNUNET_PQ_query_param_end
     42   };
     43   struct GNUNET_PQ_ResultSpec rs[] = {
     44     GNUNET_PQ_result_spec_allow_null (
     45       GNUNET_PQ_result_spec_string ("fulfillment_url",
     46                                     fulfillment_url),
     47       NULL),
     48     GNUNET_PQ_result_spec_bool ("refunded",
     49                                 refunded),
     50     GNUNET_PQ_result_spec_end
     51   };
     52 
     53   /* Session ID must always be given by the caller. */
     54   GNUNET_assert (NULL != session_id);
     55 
     56   /* no preflight check here, run in transaction by caller! */
     57   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
     58               "Updating session for h_contract_terms '%s' of `%s' to `%s'\n",
     59               GNUNET_h2s (&h_contract_terms->hash),
     60               instance_id,
     61               session_id);
     62   PREPARE (pg,
     63            "update_contract_session",
     64            "UPDATE merchant_contract_terms mct SET"
     65            " session_id=$3"
     66            " WHERE h_contract_terms=$2"
     67            "   AND merchant_serial="
     68            "     (SELECT merchant_serial"
     69            "        FROM merchant_instances"
     70            "       WHERE merchant_id=$1)"
     71            " RETURNING"
     72            "  contract_terms->>'fulfillment_url' AS fulfillment_url"
     73            " ,EXISTS (SELECT 1"
     74            "            FROM merchant_refunds mr"
     75            "           WHERE order_serial=mct.order_serial"
     76            " ) AS refunded");
     77   *fulfillment_url = NULL;
     78   return GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
     79                                                    "update_contract_session",
     80                                                    params,
     81                                                    rs);
     82 }