merchant

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

lookup_template.c (3324B)


      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/lookup_template.c
     18  * @brief Implementation of the lookup_template function for Postgres
     19  * @author Christian Grothoff
     20  */
     21 #include "platform.h"
     22 #include <taler/taler_pq_lib.h>
     23 #include "merchant-database/lookup_template.h"
     24 #include "helper.h"
     25 
     26 
     27 /**
     28  * Lookup details about a particular template.
     29  *
     30  * @param pg database context
     31  * @param instance_id instance to lookup template for
     32  * @param template_id template to lookup
     33  * @param[out] td set to the template details on success, can be NULL
     34  *             (in that case we only want to check if the template exists)
     35  * @return database result code
     36  */
     37 enum GNUNET_DB_QueryStatus
     38 TALER_MERCHANTDB_lookup_template (
     39   struct TALER_MERCHANTDB_PostgresContext *pg,
     40   const char *instance_id,
     41   const char *template_id,
     42   struct TALER_MERCHANTDB_TemplateDetails *td)
     43 {
     44   struct GNUNET_PQ_QueryParam params[] = {
     45     GNUNET_PQ_query_param_string (template_id),
     46     GNUNET_PQ_query_param_end
     47   };
     48   struct GNUNET_PQ_ResultSpec rs[] = {
     49     GNUNET_PQ_result_spec_string ("template_description",
     50                                   &td->template_description),
     51     GNUNET_PQ_result_spec_allow_null (
     52       GNUNET_PQ_result_spec_string ("otp_id",
     53                                     &td->otp_id),
     54       NULL),
     55     TALER_PQ_result_spec_json ("template_contract",
     56                                &td->template_contract),
     57     GNUNET_PQ_result_spec_allow_null (
     58       TALER_PQ_result_spec_json ("editable_defaults",
     59                                  &td->editable_defaults),
     60       NULL),
     61     GNUNET_PQ_result_spec_end
     62   };
     63   enum GNUNET_DB_QueryStatus qs;
     64 
     65   GNUNET_assert (NULL != pg->current_merchant_id);
     66   GNUNET_assert (0 == strcmp (instance_id,
     67                               pg->current_merchant_id));
     68   check_connection (pg);
     69   TMH_PQ_prepare_anon (pg,
     70                        "SELECT"
     71                        " mt.template_description"
     72                        ",mod.otp_id"
     73                        ",mt.template_contract::TEXT"
     74                        ",mt.editable_defaults::TEXT"
     75                        " FROM merchant_template mt"
     76                        " LEFT JOIN merchant_otp_devices mod"
     77                        "   ON (mod.otp_serial = mt.otp_device_id)"
     78                        " WHERE mt.template_id=$1");
     79   memset (td,
     80           0,
     81           sizeof (*td));
     82   qs = GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
     83                                                  "",
     84                                                  params,
     85                                                  rs);
     86   GNUNET_PQ_cleanup_query_params_closures (params);
     87   return qs;
     88 }