merchant

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

taler-merchant-httpd_get-private-pots-POT_ID.c (3287B)


      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 Affero General Public License for more
     12   details.
     13 
     14   You should have received a copy of the GNU Affero General Public License
     15   along with TALER; see the file COPYING.  If not, see
     16   <http://www.gnu.org/licenses/>
     17 */
     18 /**
     19  * @file taler-merchant-httpd_get-private-pots-POT_ID.c
     20  * @brief implementation of GET /private/pots/$POT_ID
     21  * @author Christian Grothoff
     22  */
     23 #include "taler/platform.h"
     24 #include "taler-merchant-httpd_get-private-pots-POT_ID.h"
     25 #include <taler/taler_json_lib.h>
     26 
     27 
     28 MHD_RESULT
     29 TMH_private_get_pot (const struct TMH_RequestHandler *rh,
     30                      struct MHD_Connection *connection,
     31                      struct TMH_HandlerContext *hc)
     32 {
     33   const char *pot_id_str = hc->infix;
     34   unsigned long long pot_id;
     35   char *pot_name;
     36   char *description;
     37   size_t pot_total_len;
     38   struct TALER_Amount *pot_totals;
     39   enum GNUNET_DB_QueryStatus qs;
     40   char dummy;
     41 
     42   (void) rh;
     43   if (1 != sscanf (pot_id_str,
     44                    "%llu%c",
     45                    &pot_id,
     46                    &dummy))
     47   {
     48     GNUNET_break_op (0);
     49     return TALER_MHD_reply_with_error (connection,
     50                                        MHD_HTTP_BAD_REQUEST,
     51                                        TALER_EC_GENERIC_PARAMETER_MALFORMED,
     52                                        "pot_id");
     53   }
     54   qs = TMH_db->select_money_pot (TMH_db->cls,
     55                                  hc->instance->settings.id,
     56                                  pot_id,
     57                                  &pot_name,
     58                                  &description,
     59                                  &pot_total_len,
     60                                  &pot_totals);
     61 
     62   if (qs < 0)
     63   {
     64     GNUNET_break (0);
     65     return TALER_MHD_reply_with_error (connection,
     66                                        MHD_HTTP_INTERNAL_SERVER_ERROR,
     67                                        TALER_EC_GENERIC_DB_FETCH_FAILED,
     68                                        "select_money_pot");
     69   }
     70   if (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS == qs)
     71   {
     72     return TALER_MHD_reply_with_error (
     73       connection,
     74       MHD_HTTP_NOT_FOUND,
     75       TALER_EC_MERCHANT_GENERIC_MONEY_POT_UNKNOWN,
     76       pot_id_str);
     77   }
     78 
     79   {
     80     MHD_RESULT ret;
     81 
     82     ret = TALER_MHD_REPLY_JSON_PACK (
     83       connection,
     84       MHD_HTTP_OK,
     85       GNUNET_JSON_pack_string ("description",
     86                                description),
     87       GNUNET_JSON_pack_string ("pot_name",
     88                                pot_name),
     89       (0 == pot_total_len)
     90       ? GNUNET_JSON_pack_array_steal ("pot_totals",
     91                                       json_array ())
     92       : TALER_JSON_pack_amount_array ("pot_totals",
     93                                       pot_total_len,
     94                                       pot_totals));
     95     GNUNET_free (pot_totals);
     96     GNUNET_free (pot_name);
     97     GNUNET_free (description);
     98     return ret;
     99   }
    100 }