merchant

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

insert_instance.c (3922B)


      1 /*
      2    This file is part of TALER
      3    Copyright (C) 2022, 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/insert_instance.c
     18  * @brief Implementation of the insert_instance function for Postgres
     19  * @author Christian Grothoff
     20  * @author Iván Ávalos
     21  */
     22 #include "platform.h"
     23 #include <taler/taler_pq_lib.h>
     24 #include "merchant-database/insert_instance.h"
     25 #include "helper.h"
     26 
     27 
     28 enum GNUNET_DB_QueryStatus
     29 TALER_MERCHANTDB_insert_instance (
     30   struct TALER_MERCHANTDB_PostgresContext *pg,
     31   const struct TALER_MerchantPublicKeyP *merchant_pub,
     32   const struct TALER_MerchantPrivateKeyP *merchant_priv,
     33   const struct TALER_MERCHANTDB_InstanceSettings *is,
     34   const struct TALER_MERCHANTDB_InstanceAuthSettings *ias,
     35   bool validation_needed)
     36 {
     37   struct GNUNET_PQ_QueryParam params[] = {
     38     GNUNET_PQ_query_param_auto_from_type (merchant_pub),
     39     GNUNET_PQ_query_param_auto_from_type (merchant_priv),
     40     GNUNET_PQ_query_param_auto_from_type (&ias->auth_hash),
     41     GNUNET_PQ_query_param_auto_from_type (&ias->auth_salt),
     42     GNUNET_PQ_query_param_string (is->id),
     43     GNUNET_PQ_query_param_string (is->name),
     44     TALER_PQ_query_param_json (is->address),
     45     TALER_PQ_query_param_json (is->jurisdiction),
     46     GNUNET_PQ_query_param_bool (is->use_stefan),
     47     GNUNET_PQ_query_param_relative_time (
     48       &is->default_wire_transfer_delay),
     49     GNUNET_PQ_query_param_relative_time (&is->default_pay_delay),
     50     GNUNET_PQ_query_param_relative_time (&is->default_refund_delay),
     51     (NULL == is->website)
     52     ? GNUNET_PQ_query_param_null ()
     53     : GNUNET_PQ_query_param_string (is->website),
     54     (NULL == is->email)
     55     ? GNUNET_PQ_query_param_null ()
     56     : GNUNET_PQ_query_param_string (is->email),
     57     (NULL == is->logo)
     58     ? GNUNET_PQ_query_param_null ()
     59     : GNUNET_PQ_query_param_string (is->logo),
     60     (NULL == is->phone)
     61     ? GNUNET_PQ_query_param_null ()
     62     : GNUNET_PQ_query_param_string (is->phone),
     63     GNUNET_PQ_query_param_bool (is->phone_validated),
     64     GNUNET_PQ_query_param_bool (is->email_validated),
     65     GNUNET_PQ_query_param_bool (validation_needed),
     66     GNUNET_PQ_query_param_string (
     67       GNUNET_TIME_round_interval2s (
     68         is->default_wire_transfer_rounding_interval)),
     69     GNUNET_PQ_query_param_end
     70   };
     71 
     72   check_connection (pg);
     73   PREPARE (pg,
     74            "insert_instance",
     75            "INSERT INTO merchant.merchant_instances"
     76            "(merchant_pub"
     77            ",merchant_priv"
     78            ",auth_hash"
     79            ",auth_salt"
     80            ",merchant_id"
     81            ",merchant_name"
     82            ",address"
     83            ",jurisdiction"
     84            ",use_stefan"
     85            ",default_wire_transfer_delay"
     86            ",default_pay_delay"
     87            ",default_refund_delay"
     88            ",website"
     89            ",email"
     90            ",logo"
     91            ",phone_number"
     92            ",phone_validated"
     93            ",email_validated"
     94            ",validation_needed"
     95            ",default_wire_transfer_rounding_interval)"
     96            "VALUES"
     97            "($1,$2,$3,$4,LOWER($5),$6,$7::TEXT::JSONB,$8::TEXT::JSONB,"
     98            "$9,$10,$11,$12,$13,$14,$15,$16,$17,$18,$19,"
     99            "$20::merchant.time_rounder_interval)");
    100   return GNUNET_PQ_eval_prepared_non_select (pg->conn,
    101                                              "insert_instance",
    102                                              params);
    103 }