exchange

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

do_refund.c (3547B)


      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 exchangedb/do_refund.c
     18  * @brief Implementation of the do_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/do_refund.h"
     24 #include "helper.h"
     25 #include "exchange-database/compute_shard.h"
     26 
     27 
     28 enum GNUNET_DB_QueryStatus
     29 TALER_EXCHANGEDB_do_refund (
     30   struct TALER_EXCHANGEDB_PostgresContext *pg,
     31   const struct TALER_EXCHANGEDB_Refund *refund,
     32   const struct TALER_Amount *deposit_fee,
     33   uint64_t known_coin_id,
     34   bool *not_found,
     35   bool *refund_ok,
     36   bool *gone,
     37   bool *conflict)
     38 {
     39   uint64_t deposit_shard = TALER_EXCHANGEDB_compute_shard (&refund->details.
     40                                                            merchant_pub);
     41   struct TALER_Amount amount_without_fee;
     42   struct GNUNET_PQ_QueryParam params[] = {
     43     TALER_PQ_query_param_amount (pg->conn,
     44                                  &refund->details.refund_amount),
     45     TALER_PQ_query_param_amount (pg->conn,
     46                                  &amount_without_fee),
     47     TALER_PQ_query_param_amount (pg->conn,
     48                                  deposit_fee),
     49     GNUNET_PQ_query_param_auto_from_type (&refund->details.h_contract_terms),
     50     GNUNET_PQ_query_param_uint64 (&refund->details.rtransaction_id),
     51     GNUNET_PQ_query_param_uint64 (&deposit_shard),
     52     GNUNET_PQ_query_param_uint64 (&known_coin_id),
     53     GNUNET_PQ_query_param_auto_from_type (&refund->coin.coin_pub),
     54     GNUNET_PQ_query_param_auto_from_type (&refund->details.merchant_pub),
     55     GNUNET_PQ_query_param_auto_from_type (&refund->details.merchant_sig),
     56     GNUNET_PQ_query_param_end
     57   };
     58   struct GNUNET_PQ_ResultSpec rs[] = {
     59     GNUNET_PQ_result_spec_bool ("not_found",
     60                                 not_found),
     61     GNUNET_PQ_result_spec_bool ("refund_ok",
     62                                 refund_ok),
     63     GNUNET_PQ_result_spec_bool ("gone",
     64                                 gone),
     65     GNUNET_PQ_result_spec_bool ("conflict",
     66                                 conflict),
     67     GNUNET_PQ_result_spec_end
     68   };
     69 
     70   if (0 >
     71       TALER_amount_subtract (&amount_without_fee,
     72                              &refund->details.refund_amount,
     73                              &refund->details.refund_fee))
     74   {
     75     GNUNET_break (0);
     76     return GNUNET_DB_STATUS_HARD_ERROR;
     77   }
     78   PREPARE (pg,
     79            "call_refund",
     80            "SELECT "
     81            " out_not_found AS not_found"
     82            ",out_refund_ok AS refund_ok"
     83            ",out_gone AS gone"
     84            ",out_conflict AS conflict"
     85            " FROM exchange_do_refund"
     86            " ($1,$2,$3,$4,$5,$6,$7,$8,$9,$10);");
     87   return GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
     88                                                    "call_refund",
     89                                                    params,
     90                                                    rs);
     91 }