merchant

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

taler-merchant-httpd_config.c (6173B)


      1 /*
      2   This file is part of TALER
      3   (C) 2019, 2020, 2021, 2023, 2024, 2025 Taler Systems SA
      4 
      5   TALER is free software; you can redistribute it and/or modify it under the
      6   terms of the GNU Affero 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 taler-merchant-httpd_config.c
     18  * @brief implement API for querying configuration data of the backend
     19  * @author Florian Dold
     20  */
     21 #include "platform.h"
     22 #include <jansson.h>
     23 #include <taler/taler_util.h>
     24 #include <taler/taler_json_lib.h>
     25 #include "taler-merchant-httpd.h"
     26 #include "taler-merchant-httpd_config.h"
     27 #include "taler-merchant-httpd_mhd.h"
     28 #include "taler-merchant-httpd_exchanges.h"
     29 
     30 
     31 /**
     32  * Taler protocol version in the format CURRENT:REVISION:AGE
     33  * as used by GNU libtool.  See
     34  * https://www.gnu.org/software/libtool/manual/html_node/Libtool-versioning.html
     35  *
     36  * Please be very careful when updating and follow
     37  * https://www.gnu.org/software/libtool/manual/html_node/Updating-version-info.html#Updating-version-info
     38  * precisely.  Note that this version has NOTHING to do with the
     39  * release version, and the format is NOT the same that semantic
     40  * versioning uses either.
     41  *
     42  * When changing this version, you likely want to also update
     43  * #MERCHANT_PROTOCOL_CURRENT and #MERCHANT_PROTOCOL_AGE in
     44  * merchant_api_get_config.c!
     45  */
     46 #define MERCHANT_PROTOCOL_VERSION "24:0:12"
     47 
     48 
     49 /**
     50  * Callback on an exchange known to us. Does not warrant
     51  * that the "keys" information is actually available for
     52  * @a exchange.
     53  *
     54  * @param cls closure with `json_t *` array to expand
     55  * @param url base URL of the exchange
     56  * @param exchange internal handle for the exchange
     57  */
     58 static void
     59 add_exchange (void *cls,
     60               const char *url,
     61               const struct TMH_Exchange *exchange)
     62 {
     63   json_t *xa = cls;
     64   json_t *xi;
     65 
     66   xi = GNUNET_JSON_PACK (
     67     GNUNET_JSON_pack_data_auto ("master_pub",
     68                                 TMH_EXCHANGES_get_master_pub (exchange)),
     69     GNUNET_JSON_pack_string ("currency",
     70                              TMH_EXCHANGES_get_currency (exchange)),
     71     GNUNET_JSON_pack_string ("base_url",
     72                              url));
     73   GNUNET_assert (NULL != xi);
     74   GNUNET_assert (0 ==
     75                  json_array_append_new (xa,
     76                                         xi));
     77 }
     78 
     79 
     80 MHD_RESULT
     81 MH_handler_config (const struct TMH_RequestHandler *rh,
     82                    struct MHD_Connection *connection,
     83                    struct TMH_HandlerContext *hc)
     84 {
     85   static struct MHD_Response *response;
     86 
     87   (void) rh;
     88   (void) hc;
     89   if (NULL == response)
     90   {
     91     json_t *specs = json_object ();
     92     json_t *exchanges = json_array ();
     93     json_t *mtc = json_array ();
     94 
     95     GNUNET_assert (NULL != specs);
     96     GNUNET_assert (NULL != exchanges);
     97     GNUNET_assert (NULL != mtc);
     98     TMH_exchange_get_trusted (&add_exchange,
     99                               exchanges);
    100     if (0 != (TEH_TCS_SMS & TEH_mandatory_tan_channels))
    101       GNUNET_assert (0 ==
    102                      json_array_append_new (mtc,
    103                                             json_string ("sms")));
    104     if (0 != (TEH_TCS_EMAIL & TEH_mandatory_tan_channels))
    105       GNUNET_assert (0 ==
    106                      json_array_append_new (mtc,
    107                                             json_string ("email")));
    108     for (unsigned int i = 0; i<TMH_num_cspecs; i++)
    109     {
    110       const struct TALER_CurrencySpecification *cspec = &TMH_cspecs[i];
    111 
    112       if (TMH_test_exchange_configured_for_currency (cspec->currency))
    113         GNUNET_assert (0 ==
    114                        json_object_set_new (
    115                          specs,
    116                          cspec->currency,
    117                          TALER_JSON_currency_specs_to_json (
    118                            cspec)));
    119     }
    120     response = TALER_MHD_MAKE_JSON_PACK (
    121       GNUNET_JSON_pack_string ("currency",
    122                                TMH_currency),
    123       GNUNET_JSON_pack_string ("payment_target_types",
    124                                TMH_allowed_payment_targets),
    125       GNUNET_JSON_pack_time_rel ("default_refund_delay",
    126                                  TMH_default_refund_delay),
    127       GNUNET_JSON_pack_time_rel ("default_wire_transfer_delay",
    128                                  TMH_default_wire_transfer_delay),
    129       GNUNET_JSON_pack_time_rel ("default_pay_delay",
    130                                  TMH_default_pay_delay),
    131       GNUNET_JSON_pack_string ("default_persona",
    132                                TMH_default_persona),
    133       GNUNET_JSON_pack_allow_null (
    134         GNUNET_JSON_pack_string ("payment_target_regex",
    135                                  TMH_payment_target_regex)),
    136       GNUNET_JSON_pack_bool ("have_self_provisioning",
    137                              GNUNET_YES ==
    138                              TMH_have_self_provisioning),
    139 #ifdef HAVE_DONAU_DONAU_SERVICE_H
    140       GNUNET_JSON_pack_bool ("have_donau",
    141                              true),
    142 #else
    143       GNUNET_JSON_pack_bool ("have_donau",
    144                              false),
    145 #endif
    146       GNUNET_JSON_pack_object_steal ("currencies",
    147                                      specs),
    148       GNUNET_JSON_pack_array_steal ("exchanges",
    149                                     exchanges),
    150       GNUNET_JSON_pack_array_steal ("mandatory_tan_channels",
    151                                     mtc),
    152       GNUNET_JSON_pack_string (
    153         "implementation",
    154         "urn:net:taler:specs:taler-merchant:c-reference"),
    155       GNUNET_JSON_pack_string ("name",
    156                                "taler-merchant"),
    157       GNUNET_JSON_pack_string ("version",
    158                                MERCHANT_PROTOCOL_VERSION));
    159   }
    160   return MHD_queue_response (connection,
    161                              MHD_HTTP_OK,
    162                              response);
    163 }
    164 
    165 
    166 /* end of taler-merchant-httpd_config.c */