Line data Source code
1 : /*
2 : This file is part of TALER
3 : Copyright (C) 2024, 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/get_kyc_status.c
18 : * @brief Implementation of the get_kyc_status function for Postgres
19 : * @author Christian Grothoff
20 : */
21 : #include "platform.h"
22 : #include <taler/taler_pq_lib.h>
23 : #include "merchant-database/get_kyc_status.h"
24 : #include "helper.h"
25 :
26 :
27 : enum GNUNET_DB_QueryStatus
28 23 : TALER_MERCHANTDB_get_kyc_status (
29 : struct TALER_MERCHANTDB_PostgresContext *pg,
30 : struct TALER_FullPayto merchant_account_uri,
31 : const char *instance_id,
32 : const char *exchange_url,
33 : bool *auth_ok,
34 : struct TALER_AccountAccessTokenP *access_token,
35 : bool *kyc_ok,
36 : unsigned int *last_http_status,
37 : enum TALER_ErrorCode *last_ec,
38 : uint64_t *rule_gen,
39 : struct GNUNET_TIME_Timestamp *last_kyc_check,
40 : struct GNUNET_TIME_Absolute *next_kyc_poll,
41 : struct GNUNET_TIME_Relative *kyc_backoff,
42 : bool *aml_review,
43 : json_t **jlimits)
44 : {
45 23 : struct GNUNET_PQ_QueryParam params[] = {
46 23 : GNUNET_PQ_query_param_string (merchant_account_uri.full_payto),
47 23 : GNUNET_PQ_query_param_string (exchange_url),
48 : GNUNET_PQ_query_param_end
49 : };
50 23 : uint32_t h32 = 0;
51 23 : uint32_t e32 = 0;
52 23 : bool token_is_null = true;
53 23 : struct GNUNET_PQ_ResultSpec rs[] = {
54 23 : GNUNET_PQ_result_spec_allow_null (
55 : GNUNET_PQ_result_spec_auto_from_type ("access_token",
56 : access_token),
57 : &token_is_null),
58 23 : GNUNET_PQ_result_spec_uint32 ("exchange_http_status",
59 : &h32),
60 23 : GNUNET_PQ_result_spec_uint32 ("exchange_ec_code",
61 : &e32),
62 23 : GNUNET_PQ_result_spec_uint64 ("last_rule_gen",
63 : rule_gen),
64 23 : GNUNET_PQ_result_spec_bool ("kyc_ok",
65 : kyc_ok),
66 23 : GNUNET_PQ_result_spec_timestamp ("kyc_timestamp",
67 : last_kyc_check),
68 23 : GNUNET_PQ_result_spec_absolute_time ("next_kyc_poll",
69 : next_kyc_poll),
70 23 : GNUNET_PQ_result_spec_relative_time ("kyc_backoff",
71 : kyc_backoff),
72 23 : GNUNET_PQ_result_spec_bool ("aml_review",
73 : aml_review),
74 23 : GNUNET_PQ_result_spec_allow_null (
75 : TALER_PQ_result_spec_json ("jaccount_limits",
76 : jlimits),
77 : NULL),
78 : GNUNET_PQ_result_spec_end
79 : };
80 : enum GNUNET_DB_QueryStatus qs;
81 :
82 23 : GNUNET_assert (NULL != pg->current_merchant_id);
83 23 : GNUNET_assert (0 == strcmp (instance_id,
84 : pg->current_merchant_id));
85 23 : TMH_PQ_prepare_anon (pg,
86 : "SELECT"
87 : " mk.access_token"
88 : ",mk.exchange_http_status"
89 : ",mk.exchange_ec_code"
90 : ",mk.kyc_ok"
91 : ",mk.last_rule_gen"
92 : ",mk.kyc_timestamp"
93 : ",mk.next_kyc_poll"
94 : ",mk.kyc_backoff"
95 : ",mk.aml_review"
96 : ",mk.jaccount_limits::TEXT"
97 : " FROM merchant_kyc mk"
98 : " WHERE mk.exchange_url=$2"
99 : " AND mk.account_serial="
100 : " (SELECT account_serial"
101 : " FROM merchant_accounts"
102 : " WHERE payto_uri=$1);");
103 23 : *jlimits = NULL;
104 23 : qs = GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
105 : "",
106 : params,
107 : rs);
108 23 : *last_ec = (enum TALER_ErrorCode) (int) e32;
109 23 : *last_http_status = (unsigned int) h32;
110 23 : *auth_ok = ! token_is_null;
111 23 : return qs;
112 : }
|