Line data Source code
1 : /*
2 : This file is part of TALER
3 : Copyright (C) 2024 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_kyc_failure.c
18 : * @brief Implementation of the insert_kyc_failure function for Postgres
19 : * @author Christian Grothoff
20 : */
21 : #include "platform.h"
22 : #include <taler/taler_dbevents.h>
23 : #include <taler/taler_pq_lib.h>
24 : #include "merchant-database/insert_kyc_failure.h"
25 : #include "helper.h"
26 :
27 :
28 : enum GNUNET_DB_QueryStatus
29 3 : TALER_MERCHANTDB_insert_kyc_failure (
30 : struct TALER_MERCHANTDB_PostgresContext *pg,
31 : const char *merchant_id,
32 : const struct TALER_MerchantWireHashP *h_wire,
33 : const char *exchange_url,
34 : struct GNUNET_TIME_Timestamp timestamp,
35 : unsigned int exchange_http_status,
36 : bool kyc_ok)
37 : {
38 3 : struct TALER_MERCHANTDB_MerchantKycStatusChangeEventP ev = {
39 3 : .header.size = htons (sizeof (ev)),
40 3 : .header.type = htons (TALER_DBEVENT_MERCHANT_EXCHANGE_KYC_STATUS_CHANGED),
41 : .merchant_pub = pg->current_merchant_pub,
42 : .h_wire = *h_wire
43 : };
44 3 : struct TALER_MERCHANTDB_InstanceKycStatusChangeEventP hdr = {
45 3 : .header.size = htons (sizeof (hdr)),
46 3 : .header.type = htons (TALER_DBEVENT_MERCHANT_KYC_STATUS_CHANGED),
47 : .merchant_pub = pg->current_merchant_pub
48 : };
49 : char *notify_s
50 3 : = GNUNET_PQ_get_event_notify_channel (&ev.header);
51 : char *notify2_s
52 3 : = GNUNET_PQ_get_event_notify_channel (&hdr.header);
53 3 : uint32_t http_status32 = (uint32_t) exchange_http_status;
54 3 : struct GNUNET_PQ_QueryParam params[] = {
55 3 : GNUNET_PQ_query_param_auto_from_type (h_wire),
56 3 : GNUNET_PQ_query_param_string (exchange_url),
57 3 : GNUNET_PQ_query_param_timestamp (×tamp),
58 3 : GNUNET_PQ_query_param_uint32 (&http_status32),
59 3 : GNUNET_PQ_query_param_bool (kyc_ok),
60 3 : GNUNET_PQ_query_param_string (notify_s),
61 3 : GNUNET_PQ_query_param_string (notify2_s),
62 : GNUNET_PQ_query_param_end
63 : };
64 : bool no_account;
65 3 : struct GNUNET_PQ_ResultSpec rs[] = {
66 3 : GNUNET_PQ_result_spec_bool ("no_account",
67 : &no_account),
68 : GNUNET_PQ_result_spec_end
69 : };
70 : enum GNUNET_DB_QueryStatus qs;
71 :
72 3 : GNUNET_assert (NULL != pg->current_merchant_id);
73 3 : GNUNET_assert (0 == strcmp (merchant_id,
74 : pg->current_merchant_id));
75 3 : TMH_PQ_prepare_anon (pg,
76 : "SELECT "
77 : " out_no_account AS no_account"
78 : " FROM merchant_do_account_kyc_set_failed"
79 : "($1, $2, $3, $4, $5, $6, $7);");
80 3 : qs = GNUNET_PQ_eval_prepared_singleton_select (
81 : pg->conn,
82 : "",
83 : params,
84 : rs);
85 3 : GNUNET_free (notify_s);
86 3 : GNUNET_free (notify2_s);
87 3 : if (qs <= 0)
88 : {
89 0 : GNUNET_break (GNUNET_DB_STATUS_SOFT_ERROR != qs);
90 0 : GNUNET_break (GNUNET_DB_STATUS_HARD_ERROR != qs);
91 0 : GNUNET_break (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS != qs);
92 0 : return qs;
93 : }
94 3 : GNUNET_break (! no_account);
95 3 : return qs;
96 : }
|