insert_account.c (3209B)
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 (struct TALER_MERCHANTDB_PostgresContext *pg, 31 const struct TALER_MERCHANTDB_AccountDetails *account_details) 32 { 33 struct GNUNET_PQ_QueryParam params[] = { 34 GNUNET_PQ_query_param_string (account_details->instance_id), 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 check_connection (pg); 53 PREPARE (pg, 54 "insert_account", 55 "INSERT INTO merchant_accounts AS ma" 56 "(merchant_serial" 57 ",h_wire" 58 ",salt" 59 ",payto_uri" 60 ",credit_facade_url" 61 ",credit_facade_credentials" 62 ",active" 63 ",extra_wire_subject_metadata)" 64 " SELECT merchant_serial, $2, $3, $4, $5, $6::TEXT::JSONB, $7, $8" 65 " FROM merchant_instances" 66 " WHERE merchant_id=$1" 67 " ON CONFLICT(merchant_serial,payto_uri)" 68 " DO UPDATE SET" 69 " active = true" 70 ",credit_facade_url = EXCLUDED.credit_facade_url" 71 ",credit_facade_credentials = EXCLUDED.credit_facade_credentials" 72 ",extra_wire_subject_metadata = EXCLUDED.extra_wire_subject_metadata" 73 " WHERE NOT ma.active"); 74 return GNUNET_PQ_eval_prepared_non_select (pg->conn, 75 "insert_account", 76 params); 77 }