merchant

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

insert_instance.c (4540B)


      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_error_codes.h>
     24 #include <taler/taler_dbevents.h>
     25 #include <taler/taler_pq_lib.h>
     26 #include "merchant-database/insert_instance.h"
     27 #include "helper.h"
     28 
     29 enum GNUNET_DB_QueryStatus
     30 TALER_MERCHANTDB_insert_instance (
     31   struct TALER_MERCHANTDB_PostgresContext *pg,
     32   const struct TALER_MerchantPublicKeyP *merchant_pub,
     33   const struct TALER_MerchantPrivateKeyP *merchant_priv,
     34   const struct TALER_MERCHANTDB_InstanceSettings *is,
     35   const struct TALER_MERCHANTDB_InstanceAuthSettings *ias,
     36   bool validation_needed)
     37 {
     38   struct GNUNET_PQ_QueryParam params[] = {
     39     GNUNET_PQ_query_param_auto_from_type (merchant_pub),
     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   struct GNUNET_PQ_QueryParam params_priv[] = {
     72     GNUNET_PQ_query_param_auto_from_type (merchant_priv),
     73     GNUNET_PQ_query_param_string (is->id),
     74     GNUNET_PQ_query_param_end
     75   };
     76   enum GNUNET_DB_QueryStatus qs;
     77 
     78   check_connection (pg);
     79   PREPARE (pg,
     80            "insert_instance",
     81            "INSERT INTO merchant_instances"
     82            "(merchant_pub"
     83            ",auth_hash"
     84            ",auth_salt"
     85            ",merchant_id"
     86            ",merchant_name"
     87            ",address"
     88            ",jurisdiction"
     89            ",use_stefan"
     90            ",default_wire_transfer_delay"
     91            ",default_pay_delay"
     92            ",default_refund_delay"
     93            ",website"
     94            ",email"
     95            ",logo"
     96            ",phone_number"
     97            ",phone_validated"
     98            ",email_validated"
     99            ",validation_needed"
    100            ",default_wire_transfer_rounding_interval)"
    101            "VALUES"
    102            "($1,$2,$3,LOWER($4),$5,$6::TEXT::JSONB,$7::TEXT::JSONB,$8,$9,$10,$11,"
    103            "$12,$13,$14,$15,$16,$17,$18,$19::time_rounder_interval)");
    104   PREPARE (pg,
    105            "insert_keys",
    106            "INSERT INTO merchant_keys"
    107            "(merchant_priv"
    108            ",merchant_serial)"
    109            " SELECT $1, merchant_serial"
    110            " FROM merchant_instances"
    111            " WHERE merchant_id=$2");
    112   qs = GNUNET_PQ_eval_prepared_non_select (pg->conn,
    113                                            "insert_instance",
    114                                            params);
    115   if (qs <= 0)
    116     return qs;
    117   return GNUNET_PQ_eval_prepared_non_select (pg->conn,
    118                                              "insert_keys",
    119                                              params_priv);
    120 }