merchant

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

store_wire_fee_by_exchange.c (2880B)


      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/store_wire_fee_by_exchange.c
     18  * @brief Implementation of the store_wire_fee_by_exchange function for Postgres
     19  * @author Christian Grothoff
     20  */
     21 #include "platform.h"
     22 #include <taler/taler_pq_lib.h>
     23 #include "merchant-database/store_wire_fee_by_exchange.h"
     24 #include "helper.h"
     25 
     26 
     27 enum GNUNET_DB_QueryStatus
     28 TALER_MERCHANTDB_store_wire_fee_by_exchange (
     29   struct TALER_MERCHANTDB_PostgresContext *pg,
     30   const struct TALER_MasterPublicKeyP *master_pub,
     31   const struct GNUNET_HashCode *h_wire_method,
     32   const struct TALER_WireFeeSet *fees,
     33   struct GNUNET_TIME_Timestamp start_date,
     34   struct GNUNET_TIME_Timestamp end_date,
     35   const struct TALER_MasterSignatureP *master_sig)
     36 {
     37   struct GNUNET_PQ_QueryParam params[] = {
     38     GNUNET_PQ_query_param_auto_from_type (master_pub),
     39     GNUNET_PQ_query_param_auto_from_type (h_wire_method),
     40     TALER_PQ_query_param_amount_with_currency (pg->conn,
     41                                                &fees->wire),
     42     TALER_PQ_query_param_amount_with_currency (pg->conn,
     43                                                &fees->closing),
     44     GNUNET_PQ_query_param_timestamp (&start_date),
     45     GNUNET_PQ_query_param_timestamp (&end_date),
     46     GNUNET_PQ_query_param_auto_from_type (master_sig),
     47     GNUNET_PQ_query_param_end
     48   };
     49 
     50   /* no preflight check here, run in its own transaction by the caller */
     51   PREPARE (pg,
     52            "insert_wire_fee",
     53            "INSERT INTO merchant.merchant_exchange_wire_fees"
     54            "(master_pub"
     55            ",h_wire_method"
     56            ",wire_fee"
     57            ",closing_fee"
     58            ",start_date"
     59            ",end_date"
     60            ",master_sig)"
     61            " VALUES "
     62            "($1, $2, $3, $4, $5, $6, $7)"
     63            " ON CONFLICT DO NOTHING");
     64   check_connection (pg);
     65   GNUNET_log (GNUNET_ERROR_TYPE_INFO,
     66               "Storing wire fee for %s starting at %s of %s\n",
     67               TALER_B2S (master_pub),
     68               GNUNET_TIME_timestamp2s (start_date),
     69               TALER_amount2s (&fees->wire));
     70   return GNUNET_PQ_eval_prepared_non_select (pg->conn,
     71                                              "insert_wire_fee",
     72                                              params);
     73 }