refund_coin.c (2984B)
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 src/backenddb/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 "merchant-database/refund_coin.h" 26 #include "helper.h" 27 28 enum GNUNET_DB_QueryStatus 29 TALER_MERCHANTDB_refund_coin (struct TALER_MERCHANTDB_PostgresContext *pg, 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 struct GNUNET_PQ_QueryParam params[] = { 37 GNUNET_PQ_query_param_string (instance_id), 38 GNUNET_PQ_query_param_auto_from_type (h_contract_terms), 39 GNUNET_PQ_query_param_timestamp (&refund_timestamp), 40 GNUNET_PQ_query_param_auto_from_type (coin_pub), 41 GNUNET_PQ_query_param_string (reason), 42 GNUNET_PQ_query_param_end 43 }; 44 PREPARE (pg, 45 "refund_coin", 46 "INSERT INTO merchant_refunds" 47 "(order_serial" 48 ",rtransaction_id" 49 ",refund_timestamp" 50 ",coin_pub" 51 ",reason" 52 ",refund_amount" 53 ") " 54 "SELECT " 55 " dcon.order_serial" 56 ",0" /* rtransaction_id always 0 for /abort */ 57 ",$3" 58 ",dep.coin_pub" 59 ",$5" 60 ",dep.amount_with_fee" 61 " FROM merchant_deposits dep" 62 " JOIN merchant_deposit_confirmations dcon" 63 " USING (deposit_confirmation_serial)" 64 " WHERE dep.coin_pub=$4" 65 " AND dcon.order_serial=" 66 " (SELECT order_serial" 67 " FROM merchant_contract_terms" 68 " WHERE h_contract_terms=$2" 69 " AND merchant_serial=" 70 " (SELECT merchant_serial" 71 " FROM merchant_instances" 72 " WHERE merchant_id=$1))"); 73 return GNUNET_PQ_eval_prepared_non_select (pg->conn, 74 "refund_coin", 75 params); 76 }