merchant

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

pg_insert_deposit_confirmation.c (5591B)


      1 /*
      2    This file is part of TALER
      3    Copyright (C) 2022, 2023, 2024, 2026 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_confirmation.c
     18  * @brief Implementation of the insert_deposit_confirmation function for Postgres
     19  * @author Christian Grothoff
     20  */
     21 #include "taler/platform.h"
     22 #include <taler/taler_error_codes.h>
     23 #include <taler/taler_dbevents.h>
     24 #include <taler/taler_pq_lib.h>
     25 #include "pg_insert_deposit_confirmation.h"
     26 #include "pg_helper.h"
     27 
     28 
     29 enum GNUNET_DB_QueryStatus
     30 TMH_PG_insert_deposit_confirmation (
     31   void *cls,
     32   const char *instance_id,
     33   struct GNUNET_TIME_Timestamp deposit_timestamp,
     34   const struct TALER_PrivateContractHashP *h_contract_terms,
     35   const char *exchange_url,
     36   struct GNUNET_TIME_Timestamp wire_transfer_deadline,
     37   const struct TALER_Amount *total_without_fees,
     38   const struct TALER_Amount *wire_fee,
     39   const struct TALER_MerchantWireHashP *h_wire,
     40   const struct TALER_ExchangeSignatureP *exchange_sig,
     41   const struct TALER_ExchangePublicKeyP *exchange_pub,
     42   uint64_t *deposit_confirmation_serial_id)
     43 {
     44   struct PostgresClosure *pg = cls;
     45   struct GNUNET_TIME_AbsoluteNBO nbo
     46     = GNUNET_TIME_absolute_hton (wire_transfer_deadline.abs_time);
     47   char *nbo_str
     48     = GNUNET_STRINGS_data_to_string_alloc (&nbo,
     49                                            sizeof (nbo));
     50   struct GNUNET_PQ_QueryParam params[] = {
     51     GNUNET_PQ_query_param_string (instance_id),
     52     GNUNET_PQ_query_param_auto_from_type (h_contract_terms),
     53     GNUNET_PQ_query_param_timestamp (&deposit_timestamp),
     54     GNUNET_PQ_query_param_string (exchange_url),
     55     TALER_PQ_query_param_amount_with_currency (pg->conn,
     56                                                total_without_fees),
     57     TALER_PQ_query_param_amount_with_currency (pg->conn,
     58                                                wire_fee),
     59     GNUNET_PQ_query_param_auto_from_type (h_wire), /* 7 */
     60     GNUNET_PQ_query_param_auto_from_type (exchange_sig),
     61     GNUNET_PQ_query_param_auto_from_type (exchange_pub),
     62     GNUNET_PQ_query_param_timestamp (&wire_transfer_deadline),
     63     GNUNET_PQ_query_param_string (nbo_str),
     64     GNUNET_PQ_query_param_end
     65   };
     66   bool no_instance;
     67   bool no_order;
     68   bool no_account;
     69   bool no_signkey;
     70   bool conflict;
     71   struct GNUNET_PQ_ResultSpec rs[] = {
     72     GNUNET_PQ_result_spec_bool ("no_instance",
     73                                 &no_instance),
     74     GNUNET_PQ_result_spec_bool ("no_order",
     75                                 &no_order),
     76     GNUNET_PQ_result_spec_bool ("no_account",
     77                                 &no_account),
     78     GNUNET_PQ_result_spec_bool ("no_signkey",
     79                                 &no_signkey),
     80     GNUNET_PQ_result_spec_bool ("conflict",
     81                                 &conflict),
     82     GNUNET_PQ_result_spec_uint64 ("deposit_confirmation_serial",
     83                                   deposit_confirmation_serial_id),
     84     GNUNET_PQ_result_spec_end
     85   };
     86   enum GNUNET_DB_QueryStatus qs;
     87 
     88   /* no preflight check here, run in transaction by caller! */
     89   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
     90               "Storing deposit confirmation for instance `%s' h_contract_terms `%s', total_without_fees: %s and wire transfer deadline in %s\n",
     91               instance_id,
     92               GNUNET_h2s (&h_contract_terms->hash),
     93               TALER_amount2s (total_without_fees),
     94               GNUNET_TIME_relative2s (
     95                 GNUNET_TIME_absolute_get_remaining (
     96                   wire_transfer_deadline.abs_time),
     97                 true));
     98   check_connection (pg);
     99   PREPARE (pg,
    100            "insert_deposit_confirmation",
    101            "SELECT "
    102            "  out_no_instance AS no_instance"
    103            " ,out_no_account AS no_account"
    104            " ,out_no_order AS no_order"
    105            " ,out_no_signkey AS no_signkey"
    106            " ,out_conflict AS conflict"
    107            " ,out_deposit_confirmation_serial AS deposit_confirmation_serial"
    108            " FROM merchant_do_insert_deposit_confirmation"
    109            "  ($1, $2 ,$3, $4, $5, $6, $7, $8, $9, $10, $11);");
    110   qs = GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
    111                                                  "insert_deposit_confirmation",
    112                                                  params,
    113                                                  rs);
    114   GNUNET_free (nbo_str);
    115   GNUNET_break (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS != qs);
    116   if (qs < 0)
    117     return qs;
    118   // FIXME: in the future, return these codes to the client and
    119   // return more specific error codes to the client from the API!
    120   if (no_instance)
    121   {
    122     GNUNET_break (0);
    123     return GNUNET_DB_STATUS_SUCCESS_NO_RESULTS;
    124   }
    125   if (no_order)
    126   {
    127     GNUNET_break (0);
    128     return GNUNET_DB_STATUS_SUCCESS_NO_RESULTS;
    129   }
    130   if (no_account)
    131   {
    132     GNUNET_break (0);
    133     return GNUNET_DB_STATUS_SUCCESS_NO_RESULTS;
    134   }
    135   if (no_signkey)
    136   {
    137     GNUNET_break (0);
    138     return GNUNET_DB_STATUS_SUCCESS_NO_RESULTS;
    139   }
    140   if (conflict)
    141   {
    142     GNUNET_break (0);
    143     return GNUNET_DB_STATUS_SUCCESS_NO_RESULTS;
    144   }
    145   return qs;
    146 }