merchant

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

insert_deposit.c (3142B)


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