merchant

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

pg_upsert_donau_keys.c (2585B)


      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 backenddb/pg_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 "pg_upsert_donau_keys.h"
     28 #include "pg_helper.h"
     29 
     30 enum GNUNET_DB_QueryStatus
     31 TMH_PG_upsert_donau_keys (
     32   void *cls,
     33   const struct DONAU_Keys *keys,
     34   struct GNUNET_TIME_Absolute first_retry)
     35 {
     36   enum GNUNET_DB_QueryStatus qs;
     37   struct PostgresClosure *pg = cls;
     38   json_t *jkeys = DONAU_keys_to_json (keys);
     39 
     40   if (NULL == jkeys)
     41     return GNUNET_DB_STATUS_HARD_ERROR;
     42 
     43   {
     44     struct GNUNET_PQ_QueryParam params[] = {
     45       TALER_PQ_query_param_json (jkeys),
     46       GNUNET_PQ_query_param_absolute_time (&first_retry),
     47       GNUNET_PQ_query_param_string (keys->donau_url),
     48       GNUNET_PQ_query_param_end
     49     };
     50 
     51     check_connection (pg);
     52     PREPARE (pg,
     53              "insert_donau_keys",
     54              "INSERT INTO merchant_donau_keys"
     55              "(keys_json"
     56              ",first_retry"
     57              ",donau_url"
     58              ") VALUES ($1::TEXT::JSONB, $2, $3);");
     59     PREPARE (pg,
     60              "update_donau_keys",
     61              "UPDATE merchant_donau_keys SET"
     62              " keys_json=$1::TEXT::JSONB,"
     63              " first_retry=$2"
     64              " WHERE"
     65              " donau_url=$3;");
     66     qs = GNUNET_PQ_eval_prepared_non_select (pg->conn,
     67                                              "update_donau_keys",
     68                                              params);
     69     if (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS == qs)
     70       qs = GNUNET_PQ_eval_prepared_non_select (pg->conn,
     71                                                "insert_donau_keys",
     72                                                params);
     73   }
     74 
     75   json_decref (jkeys);
     76   return qs;
     77 }