merchant

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

taler-merchant-httpd_private-get-token-families.c (3959B)


      1 /*
      2   This file is part of TALER
      3   (C) 2023, 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-token-families.c
     18  * @brief implement GET /tokenfamilies
     19  * @author Christian Blättler
     20  */
     21 #include "platform.h"
     22 #include "taler-merchant-httpd_private-get-token-families.h"
     23 
     24 
     25 /**
     26  * Add token family details to our JSON array.
     27  *
     28  * @param cls a `json_t *` JSON array to build
     29  * @param slug slug of the token family
     30  * @param name name of the token family
     31  * @param valid_after start time of the token family's validity period
     32  * @param valid_before end time of the token family's validity period
     33  * @param kind kind of the token family
     34  */
     35 static void
     36 add_token_family (void *cls,
     37                   const char *slug,
     38                   const char *name,
     39                   const char *description,
     40                   const json_t *description_i18n,
     41                   struct GNUNET_TIME_Timestamp valid_after,
     42                   struct GNUNET_TIME_Timestamp valid_before,
     43                   const char *kind)
     44 {
     45   json_t *pa = cls;
     46 
     47   GNUNET_assert (0 ==
     48                  json_array_append_new (
     49                    pa,
     50                    GNUNET_JSON_PACK (
     51                      GNUNET_JSON_pack_string ("slug",
     52                                               slug),
     53                      GNUNET_JSON_pack_string ("name",
     54                                               name),
     55                      GNUNET_JSON_pack_string ("description",
     56                                               description),
     57                      GNUNET_JSON_pack_allow_null (
     58                        GNUNET_JSON_pack_object_incref ("description_i18n",
     59                                                        (json_t *)
     60                                                        description_i18n)),
     61                      GNUNET_JSON_pack_timestamp ("valid_after",
     62                                                  valid_after),
     63                      GNUNET_JSON_pack_timestamp ("valid_before",
     64                                                  valid_before),
     65                      GNUNET_JSON_pack_string ("kind",
     66                                               kind))));
     67 }
     68 
     69 
     70 MHD_RESULT
     71 TMH_private_get_tokenfamilies (const struct TMH_RequestHandler *rh,
     72                                struct MHD_Connection *connection,
     73                                struct TMH_HandlerContext *hc)
     74 {
     75   json_t *families;
     76   enum GNUNET_DB_QueryStatus qs;
     77 
     78   families = json_array ();
     79   GNUNET_assert (NULL != families);
     80   qs = TMH_db->lookup_token_families (TMH_db->cls,
     81                                       hc->instance->settings.id,
     82                                       &add_token_family,
     83                                       families);
     84   if (0 > qs)
     85   {
     86     GNUNET_break (0);
     87     json_decref (families);
     88     return TALER_MHD_reply_with_error (connection,
     89                                        MHD_HTTP_INTERNAL_SERVER_ERROR,
     90                                        TALER_EC_GENERIC_DB_FETCH_FAILED,
     91                                        NULL);
     92   }
     93   return TALER_MHD_REPLY_JSON_PACK (connection,
     94                                     MHD_HTTP_OK,
     95                                     GNUNET_JSON_pack_array_steal (
     96                                       "token_families",
     97                                       families));
     98 }
     99 
    100 
    101 /* end of taler-merchant-httpd_private-get-token-families.c */