merchant

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

update_template.c (2740B)


      1 /*
      2    This file is part of TALER
      3    Copyright (C) 2022-2024 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_template.c
     18  * @brief Implementation of the update_template function for Postgres
     19  * @author Christian Grothoff
     20  */
     21 #include "platform.h"
     22 #include <taler/taler_pq_lib.h>
     23 #include "merchant-database/update_template.h"
     24 #include "helper.h"
     25 
     26 
     27 enum GNUNET_DB_QueryStatus
     28 TALER_MERCHANTDB_update_template (
     29   struct TALER_MERCHANTDB_PostgresContext *pg,
     30   const char *instance_id,
     31   const char *template_id,
     32   const struct TALER_MERCHANTDB_TemplateDetails *td)
     33 {
     34   struct GNUNET_PQ_QueryParam params[] = {
     35     GNUNET_PQ_query_param_string (template_id),
     36     GNUNET_PQ_query_param_string (td->template_description),
     37     (NULL == td->otp_id)
     38     ? GNUNET_PQ_query_param_null ()
     39     : GNUNET_PQ_query_param_string (td->otp_id),
     40     TALER_PQ_query_param_json (td->template_contract),
     41     (NULL == td->editable_defaults)
     42     ? GNUNET_PQ_query_param_null ()
     43     : TALER_PQ_query_param_json (td->editable_defaults),
     44     GNUNET_PQ_query_param_end
     45   };
     46   enum GNUNET_DB_QueryStatus qs;
     47 
     48   GNUNET_assert (NULL != pg->current_merchant_id);
     49   GNUNET_assert (0 == strcmp (instance_id,
     50                               pg->current_merchant_id));
     51   check_connection (pg);
     52   TMH_PQ_prepare_anon (pg,
     53                        "WITH otp AS ("
     54                        "   SELECT otp_serial"
     55                        "     FROM merchant_otp_devices"
     56                        "    WHERE otp_id=$3)"
     57                        "UPDATE merchant_template SET"
     58                        " template_description=$2"
     59                        ",otp_device_id="
     60                        "  COALESCE((SELECT otp_serial"
     61                        "            FROM otp), NULL)"
     62                        ",template_contract=$4::TEXT::JSONB"
     63                        ",editable_defaults=$5::TEXT::JSONB"
     64                        " WHERE template_id=$1");
     65   qs = GNUNET_PQ_eval_prepared_non_select (pg->conn,
     66                                            "",
     67                                            params);
     68   GNUNET_PQ_cleanup_query_params_closures (params);
     69   return qs;
     70 }