merchant

Merchant backend to process payments, run by merchants
Log | Files | Refs | Submodules | README | LICENSE

refund_coin.c (2954B)


      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_pq_lib.h>
     23 #include "merchant-database/refund_coin.h"
     24 #include "helper.h"
     25 
     26 
     27 enum GNUNET_DB_QueryStatus
     28 TALER_MERCHANTDB_refund_coin (
     29   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_auto_from_type (h_contract_terms),
     38     GNUNET_PQ_query_param_timestamp (&refund_timestamp),
     39     GNUNET_PQ_query_param_auto_from_type (coin_pub),
     40     GNUNET_PQ_query_param_string (reason),
     41     GNUNET_PQ_query_param_end
     42   };
     43 
     44   GNUNET_assert (NULL != pg->current_merchant_id);
     45   GNUNET_assert (0 == strcmp (instance_id,
     46                               pg->current_merchant_id));
     47   TMH_PQ_prepare_anon (pg,
     48                        "INSERT INTO merchant_refunds"
     49                        "(order_serial"
     50                        ",rtransaction_id"
     51                        ",refund_timestamp"
     52                        ",coin_pub"
     53                        ",reason"
     54                        ",refund_amount"
     55                        ") "
     56                        "SELECT "
     57                        " dcon.order_serial"
     58                        ",0" /* rtransaction_id always 0 for /abort */
     59                        ",$2"
     60                        ",dep.coin_pub"
     61                        ",$4"
     62                        ",dep.amount_with_fee"
     63                        " FROM merchant_deposits dep"
     64                        " JOIN merchant_deposit_confirmations dcon"
     65                        "   USING (deposit_confirmation_serial)"
     66                        " WHERE dep.coin_pub=$3"
     67                        "   AND dcon.order_serial="
     68                        "  (SELECT order_serial"
     69                        "     FROM merchant_contract_terms"
     70                        "    WHERE h_contract_terms=$1)");
     71   return GNUNET_PQ_eval_prepared_non_select (pg->conn,
     72                                              "",
     73                                              params);
     74 }