merchant

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

taler-merchant-httpd_private-get-units.c (3300B)


      1 /*
      2   This file is part of TALER
      3   (C) 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_private-get-units.c
     18  * @brief implement GET /private/units
     19  * @author Bohdan Potuzhnyi
     20  */
     21 #include "platform.h"
     22 #include "taler-merchant-httpd_private-get-units.h"
     23 
     24 
     25 static void
     26 add_unit (void *cls,
     27           uint64_t unit_serial,
     28           const struct TALER_MERCHANTDB_UnitDetails *ud)
     29 {
     30   json_t *ua = cls;
     31 
     32   GNUNET_assert (
     33     0 ==
     34     json_array_append_new (
     35       ua,
     36       GNUNET_JSON_PACK (
     37         GNUNET_JSON_pack_uint64 ("unit_serial",
     38                                  unit_serial),
     39         GNUNET_JSON_pack_string ("unit",
     40                                  ud->unit),
     41         GNUNET_JSON_pack_string ("unit_name_long",
     42                                  ud->unit_name_long),
     43         GNUNET_JSON_pack_object_incref ("unit_name_long_i18n",
     44                                         (json_t *) ud->unit_name_long_i18n),
     45         GNUNET_JSON_pack_string ("unit_name_short",
     46                                  ud->unit_name_short),
     47         GNUNET_JSON_pack_object_incref ("unit_name_short_i18n",
     48                                         (json_t *) ud->unit_name_short_i18n),
     49         GNUNET_JSON_pack_bool ("unit_allow_fraction",
     50                                ud->unit_allow_fraction),
     51         GNUNET_JSON_pack_uint64 ("unit_precision_level",
     52                                  ud->unit_precision_level),
     53         GNUNET_JSON_pack_bool ("unit_active",
     54                                ud->unit_active),
     55         GNUNET_JSON_pack_bool ("unit_builtin",
     56                                ud->unit_builtin))));
     57 }
     58 
     59 
     60 MHD_RESULT
     61 TMH_private_get_units (const struct TMH_RequestHandler *rh,
     62                        struct MHD_Connection *connection,
     63                        struct TMH_HandlerContext *hc)
     64 {
     65   json_t *ua;
     66   enum GNUNET_DB_QueryStatus qs;
     67 
     68   (void) rh;
     69   ua = json_array ();
     70   GNUNET_assert (NULL != ua);
     71   qs = TMH_db->lookup_units (TMH_db->cls,
     72                              hc->instance->settings.id,
     73                              &add_unit,
     74                              ua);
     75   if (0 > qs)
     76   {
     77     GNUNET_break (0);
     78     json_decref (ua);
     79     return TALER_MHD_reply_with_error (connection,
     80                                        MHD_HTTP_INTERNAL_SERVER_ERROR,
     81                                        TALER_EC_GENERIC_DB_FETCH_FAILED,
     82                                        NULL);
     83   }
     84   return TALER_MHD_REPLY_JSON_PACK (connection,
     85                                     MHD_HTTP_OK,
     86                                     GNUNET_JSON_pack_array_steal ("units",
     87                                                                   ua));
     88 }
     89 
     90 
     91 /* end of taler-merchant-httpd_private-get-units.c */