merchant

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

pg_insert_deposit.c (3027B)


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