merchant

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

taler-merchant-httpd_get-private-tokenfamilies.c (4186B)


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