merchant

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

pg_lookup_order_charity.c (3479B)


      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 backenddb/pg_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 
     27 #include "platform.h"
     28 #include <taler/taler_error_codes.h>
     29 #include <taler/taler_dbevents.h>
     30 #include <taler/taler_pq_lib.h>
     31 #include "donau/donau_service.h"
     32 #include "pg_lookup_order_charity.h"
     33 #include "pg_helper.h"
     34 
     35 
     36 enum GNUNET_DB_QueryStatus
     37 TMH_PG_lookup_order_charity (
     38   void *cls,
     39   const char *instance_id,
     40   const char *donau_url,
     41   uint64_t *charity_id,
     42   struct DONAU_CharityPrivateKeyP *charity_priv,
     43   struct TALER_Amount *charity_max_per_year,
     44   struct TALER_Amount *charity_receipts_to_date,
     45   json_t **donau_keys_json,
     46   uint64_t *donau_instance_serial)
     47 {
     48   struct PostgresClosure *pg = cls;
     49   struct GNUNET_PQ_QueryParam params[] = {
     50     GNUNET_PQ_query_param_string (instance_id),
     51     GNUNET_PQ_query_param_string (donau_url),
     52     GNUNET_PQ_query_param_end
     53   };
     54 
     55   struct GNUNET_PQ_ResultSpec rs[] = {
     56     GNUNET_PQ_result_spec_uint64 ("charity_id",
     57                                   charity_id),
     58     GNUNET_PQ_result_spec_auto_from_type ("merchant_priv",
     59                                           charity_priv),
     60     TALER_PQ_result_spec_json ("keys_json",
     61                                donau_keys_json),
     62     TALER_PQ_result_spec_amount_with_currency ("charity_max_per_year",
     63                                                charity_max_per_year),
     64     TALER_PQ_result_spec_amount_with_currency ("charity_receipts_to_date",
     65                                                charity_receipts_to_date),
     66     GNUNET_PQ_result_spec_uint64 ("donau_instances_serial",
     67                                   donau_instance_serial),
     68     GNUNET_PQ_result_spec_end
     69   };
     70 
     71   check_connection (pg);
     72   PREPARE (pg,
     73            "lookup_donau_charity",
     74            "SELECT"
     75            "  di.donau_instances_serial"
     76            " ,di.charity_id"
     77            " ,k.merchant_priv"
     78            " ,dk.keys_json::TEXT"
     79            " ,di.charity_max_per_year"
     80            " ,di.charity_receipts_to_date"
     81            " FROM merchant_donau_instances di"
     82            " JOIN merchant_donau_keys dk"
     83            "   ON dk.donau_url = di.donau_url"
     84            " JOIN merchant_instances mi"
     85            "   ON mi.merchant_serial = di.merchant_instance_serial"
     86            " JOIN merchant_keys k"
     87            "   ON k.merchant_serial = mi.merchant_serial"
     88            " WHERE mi.merchant_id = $1"
     89            "   AND di.donau_url = $2;");
     90 
     91   return GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
     92                                                    "lookup_donau_charity",
     93                                                    params,
     94                                                    rs);
     95 }