merchant

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

taler-merchant-httpd_private-get-units-ID.c (3963B)


      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-ID.c
     18  * @brief implement GET /private/units/$UNIT
     19  * @author Bohdan Potuzhnyi
     20  */
     21 #include "platform.h"
     22 #include "taler-merchant-httpd_private-get-units-ID.h"
     23 
     24 
     25 MHD_RESULT
     26 TMH_private_get_units_ID (const struct TMH_RequestHandler *rh,
     27                           struct MHD_Connection *connection,
     28                           struct TMH_HandlerContext *hc)
     29 {
     30   struct TALER_MERCHANTDB_UnitDetails ud = { 0 };
     31   enum GNUNET_DB_QueryStatus qs;
     32   MHD_RESULT ret;
     33 
     34   (void) rh;
     35   GNUNET_assert (NULL != hc->infix);
     36   qs = TMH_db->select_unit (TMH_db->cls,
     37                             hc->instance->settings.id,
     38                             hc->infix,
     39                             &ud);
     40   switch (qs)
     41   {
     42   case GNUNET_DB_STATUS_SUCCESS_ONE_RESULT:
     43     break;
     44   case GNUNET_DB_STATUS_SUCCESS_NO_RESULTS:
     45     return TALER_MHD_reply_with_error (connection,
     46                                        MHD_HTTP_NOT_FOUND,
     47                                        TALER_EC_MERCHANT_GENERIC_UNIT_UNKNOWN,
     48                                        hc->infix);
     49   case GNUNET_DB_STATUS_SOFT_ERROR:
     50   case GNUNET_DB_STATUS_HARD_ERROR:
     51     GNUNET_break (0);
     52     return TALER_MHD_reply_with_error (connection,
     53                                        MHD_HTTP_INTERNAL_SERVER_ERROR,
     54                                        TALER_EC_GENERIC_DB_FETCH_FAILED,
     55                                        "unit");
     56   }
     57 
     58   ret = TALER_MHD_REPLY_JSON_PACK (connection,
     59                                    MHD_HTTP_OK,
     60                                    GNUNET_JSON_pack_uint64 ("unit_serial",
     61                                                             ud.unit_serial),
     62                                    GNUNET_JSON_pack_string ("unit",
     63                                                             ud.unit),
     64                                    GNUNET_JSON_pack_string ("unit_name_long",
     65                                                             ud.unit_name_long),
     66                                    GNUNET_JSON_pack_object_incref (
     67                                      "unit_name_long_i18n",
     68                                      ud.unit_name_long_i18n),
     69                                    GNUNET_JSON_pack_string ("unit_name_short",
     70                                                             ud.unit_name_short),
     71                                    GNUNET_JSON_pack_object_incref (
     72                                      "unit_name_short_i18n",
     73                                      ud.unit_name_short_i18n),
     74                                    GNUNET_JSON_pack_bool ("unit_allow_fraction",
     75                                                           ud.unit_allow_fraction),
     76                                    GNUNET_JSON_pack_uint64 (
     77                                      "unit_precision_level",
     78                                      ud.unit_precision_level),
     79                                    GNUNET_JSON_pack_bool ("unit_active",
     80                                                           ud.unit_active),
     81                                    GNUNET_JSON_pack_bool ("unit_builtin",
     82                                                           ud.unit_builtin));
     83   TALER_MERCHANTDB_unit_details_free (&ud);
     84   return ret;
     85 }
     86 
     87 
     88 /* end of taler-merchant-httpd_private-get-units-ID.c */