merchant

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

taler-merchant-httpd_get-private-templates-TEMPLATE_ID.c (2724B)


      1 /*
      2   This file is part of TALER
      3   (C) 2022 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-templates-TEMPLATE_ID.c
     18  * @brief implement GET /templates/$ID
     19  * @author Priscilla HUANG
     20  */
     21 #include "platform.h"
     22 #include "taler-merchant-httpd_get-private-templates-TEMPLATE_ID.h"
     23 #include <taler/taler_json_lib.h>
     24 #include "merchant-database/lookup_template.h"
     25 
     26 
     27 enum MHD_Result
     28 TMH_private_get_templates_ID (
     29   const struct TMH_RequestHandler *rh,
     30   struct MHD_Connection *connection,
     31   struct TMH_HandlerContext *hc)
     32 {
     33   struct TMH_MerchantInstance *mi = hc->instance;
     34   struct TALER_MERCHANTDB_TemplateDetails tp = { 0 };
     35   enum GNUNET_DB_QueryStatus qs;
     36 
     37   GNUNET_assert (NULL != mi);
     38   qs = TALER_MERCHANTDB_lookup_template (TMH_db,
     39                                          mi->settings.id,
     40                                          hc->infix,
     41                                          &tp);
     42   if (0 > qs)
     43   {
     44     GNUNET_break (0);
     45     return TALER_MHD_reply_with_error (
     46       connection,
     47       MHD_HTTP_INTERNAL_SERVER_ERROR,
     48       TALER_EC_GENERIC_DB_FETCH_FAILED,
     49       "lookup_template");
     50   }
     51   if (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS == qs)
     52   {
     53     return TALER_MHD_reply_with_error (
     54       connection,
     55       MHD_HTTP_NOT_FOUND,
     56       TALER_EC_MERCHANT_GENERIC_TEMPLATE_UNKNOWN,
     57       hc->infix);
     58   }
     59   {
     60     enum MHD_Result ret;
     61 
     62     ret = TALER_MHD_REPLY_JSON_PACK (
     63       connection,
     64       MHD_HTTP_OK,
     65       GNUNET_JSON_pack_allow_null (
     66         GNUNET_JSON_pack_object_incref ("editable_defaults",
     67                                         tp.editable_defaults)),
     68       GNUNET_JSON_pack_string ("template_description",
     69                                tp.template_description),
     70       GNUNET_JSON_pack_allow_null (
     71         GNUNET_JSON_pack_string ("otp_id",
     72                                  tp.otp_id)),
     73       GNUNET_JSON_pack_object_incref ("template_contract",
     74                                       tp.template_contract));
     75     TALER_MERCHANTDB_template_details_free (&tp);
     76     return ret;
     77   }
     78 }
     79 
     80 
     81 /* end of taler-merchant-httpd_get-private-templates-TEMPLATE_ID.c */