merchant

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

taler-merchant-httpd_private-get-instances-ID.c (5592B)


      1 /*
      2   This file is part of TALER
      3   (C) 2019-2023 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_private-get-instances-ID.c
     18  * @brief implement GET /instances/$ID
     19  * @author Christian Grothoff
     20  */
     21 #include "platform.h"
     22 #include "taler-merchant-httpd_private-get-instances-ID.h"
     23 #include <taler/taler_json_lib.h>
     24 
     25 
     26 /**
     27  * Handle a GET "/instances/$ID" request.
     28  *
     29  * @param mi instance to return information about
     30  * @param connection the MHD connection to handle
     31  * @return MHD result code
     32  */
     33 static MHD_RESULT
     34 get_instances_ID (struct TMH_MerchantInstance *mi,
     35                   struct MHD_Connection *connection)
     36 {
     37   json_t *ja;
     38   json_t *auth;
     39 
     40   GNUNET_assert (NULL != mi);
     41   ja = json_array ();
     42   GNUNET_assert (NULL != ja);
     43   for (struct TMH_WireMethod *wm = mi->wm_head;
     44        NULL != wm;
     45        wm = wm->next)
     46   {
     47     GNUNET_assert (
     48       0 ==
     49       json_array_append_new (
     50         ja,
     51         GNUNET_JSON_PACK (
     52           TALER_JSON_pack_full_payto (
     53             "payto_uri",
     54             wm->payto_uri),
     55           GNUNET_JSON_pack_allow_null (
     56             GNUNET_JSON_pack_string (
     57               "credit_facade_url",
     58               wm->credit_facade_url)),
     59           GNUNET_JSON_pack_data_auto ("h_wire",
     60                                       &wm->h_wire),
     61           GNUNET_JSON_pack_data_auto (
     62             "salt",
     63             &wm->wire_salt),
     64           GNUNET_JSON_pack_bool ("active",
     65                                  wm->active))));
     66   }
     67   if (GNUNET_YES == TMH_strict_v19)
     68   {
     69     // When pre v19 is deprecated this if guard can be removed
     70     // and the code below should never return "external"
     71     GNUNET_assert (! GNUNET_is_zero (&mi->auth.auth_hash));
     72   }
     73   auth = GNUNET_JSON_PACK (
     74     GNUNET_JSON_pack_string ("method",
     75                              GNUNET_is_zero (&mi->auth.auth_hash)
     76                              ? "external"
     77                              : "token"));
     78   return TALER_MHD_REPLY_JSON_PACK (
     79     connection,
     80     MHD_HTTP_OK,
     81     GNUNET_JSON_pack_array_steal ("accounts",
     82                                   ja),
     83     GNUNET_JSON_pack_string ("name",
     84                              mi->settings.name),
     85     GNUNET_JSON_pack_allow_null (
     86       GNUNET_JSON_pack_string ("website",
     87                                mi->settings.website)),
     88     GNUNET_JSON_pack_allow_null (
     89       GNUNET_JSON_pack_string ("email",
     90                                mi->settings.email)),
     91     GNUNET_JSON_pack_bool ("email_validated",
     92                            mi->settings.email_validated),
     93     GNUNET_JSON_pack_allow_null (
     94       GNUNET_JSON_pack_string ("phone_number",
     95                                mi->settings.phone)),
     96     GNUNET_JSON_pack_bool ("phone_validated",
     97                            mi->settings.phone_validated),
     98     GNUNET_JSON_pack_allow_null (
     99       GNUNET_JSON_pack_string ("logo",
    100                                mi->settings.logo)),
    101     GNUNET_JSON_pack_data_auto ("merchant_pub",
    102                                 &mi->merchant_pub),
    103     GNUNET_JSON_pack_object_incref ("address",
    104                                     mi->settings.address),
    105     GNUNET_JSON_pack_object_incref ("jurisdiction",
    106                                     mi->settings.jurisdiction),
    107     GNUNET_JSON_pack_bool ("use_stefan",
    108                            mi->settings.use_stefan),
    109     GNUNET_JSON_pack_time_rel ("default_wire_transfer_delay",
    110                                mi->settings.default_wire_transfer_delay),
    111     GNUNET_JSON_pack_time_rel ("default_pay_delay",
    112                                mi->settings.default_pay_delay),
    113     GNUNET_JSON_pack_time_rel ("default_refund_delay",
    114                                mi->settings.default_refund_delay),
    115     GNUNET_JSON_pack_time_rounder_interval (
    116       "default_wire_transfer_rounding_interval",
    117       mi->settings.default_wire_transfer_rounding_interval),
    118     GNUNET_JSON_pack_object_steal ("auth",
    119                                    auth));
    120 }
    121 
    122 
    123 MHD_RESULT
    124 TMH_private_get_instances_ID (const struct TMH_RequestHandler *rh,
    125                               struct MHD_Connection *connection,
    126                               struct TMH_HandlerContext *hc)
    127 {
    128   struct TMH_MerchantInstance *mi = hc->instance;
    129 
    130   return get_instances_ID (mi,
    131                            connection);
    132 }
    133 
    134 
    135 MHD_RESULT
    136 TMH_private_get_instances_default_ID (const struct TMH_RequestHandler *rh,
    137                                       struct MHD_Connection *connection,
    138                                       struct TMH_HandlerContext *hc)
    139 {
    140   struct TMH_MerchantInstance *mi;
    141 
    142   mi = TMH_lookup_instance (hc->infix);
    143   if ( (NULL == mi) ||
    144        (mi->deleted) )
    145   {
    146     return TALER_MHD_reply_with_error (connection,
    147                                        MHD_HTTP_NOT_FOUND,
    148                                        TALER_EC_MERCHANT_GENERIC_INSTANCE_UNKNOWN,
    149                                        hc->infix);
    150   }
    151   return get_instances_ID (mi,
    152                            connection);
    153 }
    154 
    155 
    156 /* end of taler-merchant-httpd_private-get-instances-ID.c */