merchant

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

lookup_order_charity.c (3276B)


      1 /*
      2    This file is part of TALER
      3    Copyright (C) 2025 Taler Systems SA
      4 
      5    TALER is free software; you can redistribute it and/or modify it
      6    under the terms of the GNU General Public License as published by the
      7    Free Software Foundation; either version 3, or (at your option) any
      8    later version.
      9 
     10    TALER is distributed in the hope that it will be useful, but WITHOUT
     11    ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
     12    or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public
     13    License for more details.
     14 
     15    You should have received a copy of the GNU General Public License
     16    along with TALER; see the file COPYING.  If not, see
     17    <http://www.gnu.org/licenses/>
     18  */
     19 /**
     20  * @file src/backenddb/lookup_order_charity.c
     21  * @brief Implementation for retrieving Donau charity_id and corresponding private key
     22  *        by Donau URL.
     23  * @author Bohdan Potuzhnyi
     24  * @author Vlada Svirsh
     25  */
     26 #include "platform.h"
     27 #include <taler/taler_error_codes.h>
     28 #include <taler/taler_dbevents.h>
     29 #include <taler/taler_pq_lib.h>
     30 #include "merchantdb_lib.h"
     31 #include "donau/donau_service.h"
     32 #include "merchant-database/lookup_order_charity.h"
     33 #include "helper.h"
     34 
     35 
     36 enum GNUNET_DB_QueryStatus
     37 TALER_MERCHANTDB_lookup_order_charity (
     38   struct TALER_MERCHANTDB_PostgresContext *pg,
     39   const char *instance_id,
     40   const char *donau_url,
     41   uint64_t *charity_id,
     42   struct TALER_Amount *charity_max_per_year,
     43   struct TALER_Amount *charity_receipts_to_date,
     44   json_t **donau_keys_json,
     45   uint64_t *donau_instance_serial)
     46 {
     47   struct GNUNET_PQ_QueryParam params[] = {
     48     GNUNET_PQ_query_param_string (donau_url),
     49     GNUNET_PQ_query_param_end
     50   };
     51   struct GNUNET_PQ_ResultSpec rs[] = {
     52     GNUNET_PQ_result_spec_uint64 ("charity_id",
     53                                   charity_id),
     54     TALER_PQ_result_spec_json ("keys_json",
     55                                donau_keys_json),
     56     TALER_PQ_result_spec_amount_with_currency ("charity_max_per_year",
     57                                                charity_max_per_year),
     58     TALER_PQ_result_spec_amount_with_currency ("charity_receipts_to_date",
     59                                                charity_receipts_to_date),
     60     GNUNET_PQ_result_spec_uint64 ("donau_instances_serial",
     61                                   donau_instance_serial),
     62     GNUNET_PQ_result_spec_end
     63   };
     64 
     65   GNUNET_assert (NULL != pg->current_merchant_id);
     66   GNUNET_assert (0 == strcmp (instance_id,
     67                               pg->current_merchant_id));
     68   check_connection (pg);
     69   TMH_PQ_prepare_anon (pg,
     70                        "SELECT"
     71                        "  di.donau_instances_serial"
     72                        " ,di.charity_id"
     73                        " ,dk.keys_json::TEXT"
     74                        " ,di.charity_max_per_year"
     75                        " ,di.charity_receipts_to_date"
     76                        " FROM merchant_donau_instances di"
     77                        " JOIN merchant.merchant_donau_keys dk"
     78                        "   ON dk.donau_url = di.donau_url"
     79                        " WHERE di.donau_url = $1;");
     80   return GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
     81                                                    "",
     82                                                    params,
     83                                                    rs);
     84 }