exchange

Base system with REST service to issue digital coins, run by the payment service provider
Log | Files | Refs | Submodules | README | LICENSE

insert_refund.c (2593B)


      1 /*
      2    This file is part of TALER
      3    Copyright (C) 2022-2023 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 exchangedb/insert_refund.c
     18  * @brief Implementation of the insert_refund function for Postgres
     19  * @author Christian Grothoff
     20  */
     21 #include "taler/taler_error_codes.h"
     22 #include "taler/taler_pq_lib.h"
     23 #include "exchange-database/insert_refund.h"
     24 #include "helper.h"
     25 
     26 
     27 enum GNUNET_DB_QueryStatus
     28 TALER_EXCHANGEDB_insert_refund (struct TALER_EXCHANGEDB_PostgresContext *pg,
     29                                 const struct TALER_EXCHANGEDB_Refund *refund)
     30 {
     31   struct GNUNET_PQ_QueryParam params[] = {
     32     GNUNET_PQ_query_param_auto_from_type (&refund->coin.coin_pub),
     33     GNUNET_PQ_query_param_auto_from_type (&refund->details.merchant_pub),
     34     GNUNET_PQ_query_param_auto_from_type (&refund->details.merchant_sig),
     35     GNUNET_PQ_query_param_auto_from_type (&refund->details.h_contract_terms),
     36     GNUNET_PQ_query_param_uint64 (&refund->details.rtransaction_id),
     37     TALER_PQ_query_param_amount (pg->conn,
     38                                  &refund->details.refund_amount),
     39     GNUNET_PQ_query_param_end
     40   };
     41 
     42   GNUNET_assert (GNUNET_YES ==
     43                  TALER_amount_cmp_currency (&refund->details.refund_amount,
     44                                             &refund->details.refund_fee));
     45   PREPARE (pg,
     46            "insert_refund",
     47            "INSERT INTO refunds "
     48            "(coin_pub"
     49            ",batch_deposit_serial_id"
     50            ",merchant_sig"
     51            ",rtransaction_id"
     52            ",amount_with_fee"
     53            ") SELECT $1, cdep.batch_deposit_serial_id, $3, $5, $6"
     54            "    FROM coin_deposits cdep"
     55            "    JOIN batch_deposits bdep USING (batch_deposit_serial_id)"
     56            "   WHERE coin_pub=$1"
     57            "     AND h_contract_terms=$4"
     58            "     AND merchant_pub=$2");
     59   return GNUNET_PQ_eval_prepared_non_select (pg->conn,
     60                                              "insert_refund",
     61                                              params);
     62 }