Line data Source code
1 : /*
2 : This file is part of TALER
3 : Copyright (C) 2025 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/update_contract_terms_session.c
18 : * @brief Implementation of the update_contract_terms_session function for Postgres
19 : * @author Christian Grothoff
20 : */
21 : #include "platform.h"
22 : #include <taler/taler_pq_lib.h>
23 : #include "merchant-database/update_contract_terms_session.h"
24 : #include "helper.h"
25 :
26 :
27 : enum GNUNET_DB_QueryStatus
28 4 : TALER_MERCHANTDB_update_contract_terms_session (
29 : struct TALER_MERCHANTDB_PostgresContext *pg,
30 : const char *instance_id,
31 : const struct TALER_PrivateContractHashP *h_contract_terms,
32 : const char *session_id,
33 : char **fulfillment_url,
34 : bool *refunded)
35 : {
36 4 : struct GNUNET_PQ_QueryParam params[] = {
37 4 : GNUNET_PQ_query_param_auto_from_type (h_contract_terms),
38 4 : GNUNET_PQ_query_param_string (session_id),
39 : GNUNET_PQ_query_param_end
40 : };
41 4 : struct GNUNET_PQ_ResultSpec rs[] = {
42 4 : GNUNET_PQ_result_spec_allow_null (
43 : GNUNET_PQ_result_spec_string ("fulfillment_url",
44 : fulfillment_url),
45 : NULL),
46 4 : GNUNET_PQ_result_spec_bool ("refunded",
47 : refunded),
48 : GNUNET_PQ_result_spec_end
49 : };
50 :
51 : /* Session ID must always be given by the caller. */
52 4 : GNUNET_assert (NULL != session_id);
53 4 : GNUNET_assert (NULL != pg->current_merchant_id);
54 4 : GNUNET_assert (0 == strcmp (instance_id,
55 : pg->current_merchant_id));
56 :
57 : /* no preflight check here, run in transaction by caller! */
58 4 : GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
59 : "Updating session for h_contract_terms '%s' of `%s' to `%s'\n",
60 : GNUNET_h2s (&h_contract_terms->hash),
61 : instance_id,
62 : session_id);
63 4 : TMH_PQ_prepare_anon (pg,
64 : "UPDATE merchant_contract_terms mct SET"
65 : " session_id=$2"
66 : " WHERE h_contract_terms=$1"
67 : " RETURNING"
68 : " contract_terms->>'fulfillment_url' AS fulfillment_url"
69 : " ,EXISTS (SELECT 1"
70 : " FROM merchant_refunds mr"
71 : " WHERE order_serial=mct.order_serial"
72 : " ) AS refunded");
73 4 : *fulfillment_url = NULL;
74 4 : return GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
75 : "",
76 : params,
77 : rs);
78 : }
|