Line data Source code
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 8 : TALER_MERCHANTDB_insert_account (
31 : struct TALER_MERCHANTDB_PostgresContext *pg,
32 : const struct TALER_MERCHANTDB_AccountDetails *account_details)
33 : {
34 8 : struct GNUNET_PQ_QueryParam params[] = {
35 8 : GNUNET_PQ_query_param_auto_from_type (&account_details->h_wire),
36 8 : GNUNET_PQ_query_param_auto_from_type (&account_details->salt),
37 8 : GNUNET_PQ_query_param_string (account_details->payto_uri.full_payto),
38 8 : NULL ==account_details->credit_facade_url
39 8 : ? GNUNET_PQ_query_param_null ()
40 8 : : GNUNET_PQ_query_param_string (account_details->credit_facade_url),
41 8 : NULL == account_details->credit_facade_credentials
42 8 : ? GNUNET_PQ_query_param_null ()
43 8 : : TALER_PQ_query_param_json (account_details->credit_facade_credentials),
44 8 : GNUNET_PQ_query_param_bool (account_details->active),
45 8 : NULL == account_details->extra_wire_subject_metadata
46 8 : ? GNUNET_PQ_query_param_null ()
47 8 : : GNUNET_PQ_query_param_string (
48 0 : account_details->extra_wire_subject_metadata),
49 : GNUNET_PQ_query_param_end
50 : };
51 :
52 8 : GNUNET_assert (NULL != pg->current_merchant_id);
53 8 : GNUNET_assert (0 == strcmp (account_details->instance_id,
54 : pg->current_merchant_id));
55 8 : TMH_PQ_prepare_anon (pg,
56 : "INSERT INTO merchant_accounts AS ma"
57 : "(h_wire"
58 : ",salt"
59 : ",payto_uri"
60 : ",credit_facade_url"
61 : ",credit_facade_credentials"
62 : ",active"
63 : ",extra_wire_subject_metadata)"
64 : " VALUES ($1, $2, $3, $4, $5::TEXT::JSONB, $6, $7)"
65 : " ON CONFLICT(payto_uri)"
66 : " DO UPDATE SET"
67 : " active = TRUE"
68 : ",credit_facade_url = EXCLUDED.credit_facade_url"
69 : ",credit_facade_credentials = EXCLUDED.credit_facade_credentials"
70 : ",extra_wire_subject_metadata = EXCLUDED.extra_wire_subject_metadata"
71 : " WHERE NOT ma.active");
72 8 : return GNUNET_PQ_eval_prepared_non_select (pg->conn,
73 : "",
74 : params);
75 : }
|