Line data Source code
1 : /*
2 : This file is part of TALER
3 : Copyright (C) 2022 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 backenddb/pg_refund_coin.c
18 : * @brief Implementation of the refund_coin function for Postgres
19 : * @author Iván Ávalos
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 "pg_refund_coin.h"
26 : #include "pg_helper.h"
27 :
28 : enum GNUNET_DB_QueryStatus
29 4 : TMH_PG_refund_coin (void *cls,
30 : const char *instance_id,
31 : const struct TALER_PrivateContractHashP *h_contract_terms,
32 : struct GNUNET_TIME_Timestamp refund_timestamp,
33 : const struct TALER_CoinSpendPublicKeyP *coin_pub,
34 : const char *reason)
35 : {
36 4 : struct PostgresClosure *pg = cls;
37 4 : struct GNUNET_PQ_QueryParam params[] = {
38 4 : GNUNET_PQ_query_param_string (instance_id),
39 4 : GNUNET_PQ_query_param_auto_from_type (h_contract_terms),
40 4 : GNUNET_PQ_query_param_timestamp (&refund_timestamp),
41 4 : GNUNET_PQ_query_param_auto_from_type (coin_pub),
42 4 : GNUNET_PQ_query_param_string (reason),
43 : GNUNET_PQ_query_param_end
44 : };
45 4 : PREPARE (pg,
46 : "refund_coin",
47 : "INSERT INTO merchant_refunds"
48 : "(order_serial"
49 : ",rtransaction_id"
50 : ",refund_timestamp"
51 : ",coin_pub"
52 : ",reason"
53 : ",refund_amount"
54 : ") "
55 : "SELECT "
56 : " dcon.order_serial"
57 : ",0" /* rtransaction_id always 0 for /abort */
58 : ",$3"
59 : ",dep.coin_pub"
60 : ",$5"
61 : ",dep.amount_with_fee"
62 : " FROM merchant_deposits dep"
63 : " JOIN merchant_deposit_confirmations dcon"
64 : " USING (deposit_confirmation_serial)"
65 : " WHERE dep.coin_pub=$4"
66 : " AND dcon.order_serial="
67 : " (SELECT order_serial"
68 : " FROM merchant_contract_terms"
69 : " WHERE h_contract_terms=$2"
70 : " AND merchant_serial="
71 : " (SELECT merchant_serial"
72 : " FROM merchant_instances"
73 : " WHERE merchant_id=$1))");
74 4 : return GNUNET_PQ_eval_prepared_non_select (pg->conn,
75 : "refund_coin",
76 : params);
77 : }
|