merchant

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

insert_account.c (3311B)


      1 /*
      2    This file is part of TALER
      3    Copyright (C) 2022, 2023, 2026 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_account.c
     18  * @brief Implementation of the insert_account 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/insert_account.h"
     26 #include "helper.h"
     27 
     28 
     29 enum GNUNET_DB_QueryStatus
     30 TALER_MERCHANTDB_insert_account (
     31   struct TALER_MERCHANTDB_PostgresContext *pg,
     32   const struct TALER_MERCHANTDB_AccountDetails *account_details)
     33 {
     34   struct GNUNET_PQ_QueryParam params[] = {
     35     GNUNET_PQ_query_param_auto_from_type (&account_details->h_wire),
     36     GNUNET_PQ_query_param_auto_from_type (&account_details->salt),
     37     GNUNET_PQ_query_param_string (account_details->payto_uri.full_payto),
     38     NULL ==account_details->credit_facade_url
     39     ? GNUNET_PQ_query_param_null ()
     40     : GNUNET_PQ_query_param_string (account_details->credit_facade_url),
     41     NULL == account_details->credit_facade_credentials
     42     ? GNUNET_PQ_query_param_null ()
     43     : TALER_PQ_query_param_json (account_details->credit_facade_credentials),
     44     GNUNET_PQ_query_param_bool (account_details->active),
     45     NULL == account_details->extra_wire_subject_metadata
     46     ? GNUNET_PQ_query_param_null ()
     47     : GNUNET_PQ_query_param_string (
     48       account_details->extra_wire_subject_metadata),
     49     GNUNET_PQ_query_param_end
     50   };
     51 
     52   GNUNET_assert (NULL != pg->current_merchant_id);
     53   GNUNET_assert (0 == strcmp (account_details->instance_id,
     54                               pg->current_merchant_id));
     55   check_connection (pg);
     56   TMH_PQ_prepare_anon (pg,
     57                        "INSERT INTO merchant_accounts AS ma"
     58                        "(h_wire"
     59                        ",salt"
     60                        ",payto_uri"
     61                        ",credit_facade_url"
     62                        ",credit_facade_credentials"
     63                        ",active"
     64                        ",extra_wire_subject_metadata)"
     65                        " VALUES ($1, $2, $3, $4, $5::TEXT::JSONB, $6, $7)"
     66                        " ON CONFLICT(payto_uri)"
     67                        " DO UPDATE SET"
     68                        " active = TRUE"
     69                        ",credit_facade_url = EXCLUDED.credit_facade_url"
     70                        ",credit_facade_credentials = EXCLUDED.credit_facade_credentials"
     71                        ",extra_wire_subject_metadata = EXCLUDED.extra_wire_subject_metadata"
     72                        " WHERE NOT ma.active");
     73   return GNUNET_PQ_eval_prepared_non_select (pg->conn,
     74                                              "",
     75                                              params);
     76 }