merchant

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

upsert_donau_keys.c (2671B)


      1 /*
      2    This file is part of TALER
      3    Copyright (C) 2024 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/upsert_donau_keys.c
     18  * @brief Implementation of the upsert_donau_keys function for Postgres
     19  * @author Bohdan Potuzhnyi
     20  * @author Vlada Svirsh
     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 "donau/donau_service.h"
     27 #include "merchant-database/upsert_donau_keys.h"
     28 #include "helper.h"
     29 
     30 enum GNUNET_DB_QueryStatus
     31 TALER_MERCHANTDB_upsert_donau_keys (struct TALER_MERCHANTDB_PostgresContext *pg,
     32                                     const struct DONAU_Keys *keys,
     33                                     struct GNUNET_TIME_Absolute first_retry)
     34 {
     35   enum GNUNET_DB_QueryStatus qs;
     36   json_t *jkeys = DONAU_keys_to_json (keys);
     37 
     38   if (NULL == jkeys)
     39     return GNUNET_DB_STATUS_HARD_ERROR;
     40 
     41   {
     42     struct GNUNET_PQ_QueryParam params[] = {
     43       TALER_PQ_query_param_json (jkeys),
     44       GNUNET_PQ_query_param_absolute_time (&first_retry),
     45       GNUNET_PQ_query_param_string (keys->donau_url),
     46       GNUNET_PQ_query_param_end
     47     };
     48 
     49     check_connection (pg);
     50     PREPARE (pg,
     51              "insert_donau_keys",
     52              "INSERT INTO merchant_donau_keys"
     53              "(keys_json"
     54              ",first_retry"
     55              ",donau_url"
     56              ") VALUES ($1::TEXT::JSONB, $2, $3);");
     57     PREPARE (pg,
     58              "update_donau_keys",
     59              "UPDATE merchant_donau_keys SET"
     60              " keys_json=$1::TEXT::JSONB,"
     61              " first_retry=$2"
     62              " WHERE"
     63              " donau_url=$3;");
     64     qs = GNUNET_PQ_eval_prepared_non_select (pg->conn,
     65                                              "update_donau_keys",
     66                                              params);
     67     if (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS == qs)
     68       qs = GNUNET_PQ_eval_prepared_non_select (pg->conn,
     69                                                "insert_donau_keys",
     70                                                params);
     71   }
     72 
     73   json_decref (jkeys);
     74   return qs;
     75 }