merchant

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

insert_deposit.c (3331B)


      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 src/backenddb/insert_deposit.c
     18  * @brief Implementation of the insert_deposit function for Postgres
     19  * @author Christian Grothoff
     20  * @author Iván Ávalos
     21  */
     22 #include "platform.h"
     23 #include <taler/taler_error_codes.h>
     24 #include <taler/taler_dbevents.h>
     25 #include <taler/taler_pq_lib.h>
     26 #include "merchant-database/insert_deposit.h"
     27 #include "helper.h"
     28 
     29 
     30 enum GNUNET_DB_QueryStatus
     31 TALER_MERCHANTDB_insert_deposit (struct TALER_MERCHANTDB_PostgresContext *pg,
     32                                  uint32_t offset,
     33                                  uint64_t deposit_confirmation_serial,
     34                                  const struct TALER_CoinSpendPublicKeyP *coin_pub,
     35                                  const struct TALER_CoinSpendSignatureP *coin_sig,
     36                                  const struct TALER_Amount *amount_with_fee,
     37                                  const struct TALER_Amount *deposit_fee,
     38                                  const struct TALER_Amount *refund_fee,
     39                                  struct GNUNET_TIME_Absolute check_time)
     40 {
     41   struct GNUNET_PQ_QueryParam params[] = {
     42     GNUNET_PQ_query_param_uint64 (&deposit_confirmation_serial),
     43     GNUNET_PQ_query_param_uint32 (&offset),
     44     GNUNET_PQ_query_param_auto_from_type (coin_pub),
     45     GNUNET_PQ_query_param_auto_from_type (coin_sig),
     46     TALER_PQ_query_param_amount_with_currency (pg->conn,
     47                                                amount_with_fee),
     48     TALER_PQ_query_param_amount_with_currency (pg->conn,
     49                                                deposit_fee),
     50     TALER_PQ_query_param_amount_with_currency (pg->conn,
     51                                                refund_fee),
     52     GNUNET_PQ_query_param_absolute_time (&check_time),
     53     GNUNET_PQ_query_param_end
     54   };
     55 
     56   /* no preflight check here, run in transaction by caller! */
     57   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
     58               "Storing deposit for coin_pub: `%s', amount_with_fee: %s\n",
     59               TALER_B2S (coin_pub),
     60               TALER_amount2s (amount_with_fee));
     61   check_connection (pg);
     62   PREPARE (pg,
     63            "insert_deposit",
     64            "INSERT INTO merchant_deposits"
     65            "(deposit_confirmation_serial"
     66            ",coin_offset"
     67            ",coin_pub"
     68            ",coin_sig"
     69            ",amount_with_fee"
     70            ",deposit_fee"
     71            ",refund_fee"
     72            ",settlement_retry_time"
     73            ") VALUES ($1,$2,$3,$4,$5,$6,$7,$8)"
     74            " ON CONFLICT DO NOTHING;");
     75   return GNUNET_PQ_eval_prepared_non_select (pg->conn,
     76                                              "insert_deposit",
     77                                              params);
     78 }