merchant

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

insert_unit.c (2922B)


      1 /*
      2    This file is part of TALER
      3    Copyright (C) 2025, 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 src/backenddb/insert_unit.c
     18  * @brief Implementation of the insert_unit function for Postgres
     19  * @author Bohdan Potuzhnyi
     20  */
     21 #include "platform.h"
     22 #include <taler/taler_pq_lib.h>
     23 #include "merchant-database/insert_unit.h"
     24 #include "helper.h"
     25 
     26 
     27 enum GNUNET_DB_QueryStatus
     28 TALER_MERCHANTDB_insert_unit (
     29   struct TALER_MERCHANTDB_PostgresContext *pg,
     30   const char *instance_id,
     31   const struct TALER_MERCHANTDB_UnitDetails *ud,
     32   bool *conflict,
     33   uint64_t *unit_serial)
     34 {
     35   struct GNUNET_PQ_QueryParam params[] = {
     36     GNUNET_PQ_query_param_string (ud->unit),
     37     GNUNET_PQ_query_param_string (ud->unit_name_long),
     38     GNUNET_PQ_query_param_string (ud->unit_name_short),
     39     TALER_PQ_query_param_json (ud->unit_name_long_i18n),
     40     TALER_PQ_query_param_json (ud->unit_name_short_i18n),
     41     GNUNET_PQ_query_param_bool (ud->unit_allow_fraction),
     42     GNUNET_PQ_query_param_uint32 (&ud->unit_precision_level),
     43     GNUNET_PQ_query_param_bool (ud->unit_active),
     44     GNUNET_PQ_query_param_end
     45   };
     46   bool unit_serial_present = true;
     47   struct GNUNET_PQ_ResultSpec rs[] = {
     48     GNUNET_PQ_result_spec_bool ("conflict",
     49                                 conflict),
     50     GNUNET_PQ_result_spec_allow_null (
     51       GNUNET_PQ_result_spec_uint64 ("unit_serial",
     52                                     unit_serial),
     53       &unit_serial_present),
     54     GNUNET_PQ_result_spec_end
     55   };
     56   enum GNUNET_DB_QueryStatus qs;
     57 
     58   *conflict = false;
     59   GNUNET_assert (NULL != pg->current_merchant_id);
     60   GNUNET_assert (0 == strcmp (instance_id,
     61                               pg->current_merchant_id));
     62   check_connection (pg);
     63   TMH_PQ_prepare_anon (pg,
     64                        "SELECT"
     65                        " out_conflict AS conflict"
     66                        " ,out_unit_serial AS unit_serial"
     67                        " FROM merchant_do_insert_unit"
     68                        " ($1,$2,$3,$4,$5,$6,$7,$8);");
     69   qs = GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
     70                                                  "",
     71                                                  params,
     72                                                  rs);
     73   GNUNET_PQ_cleanup_query_params_closures (params);
     74   if (! unit_serial_present)
     75     *unit_serial = 0;
     76   return qs;
     77 }