merchant

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

taler-merchant-httpd_get-private-webhooks-WEBHOOK_ID.c (3292B)


      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-webhooks-WEBHOOK_ID.c
     18  * @brief implement GET /webhooks/$ID
     19  * @author Priscilla HUANG
     20  */
     21 #include "platform.h"
     22 #include "taler-merchant-httpd_get-private-webhooks-WEBHOOK_ID.h"
     23 #include <taler/taler_json_lib.h>
     24 #include "merchant-database/lookup_webhook.h"
     25 
     26 
     27 /**
     28  * Handle a GET "/webhooks/$ID" request.
     29  *
     30  * @param rh context of the handler
     31  * @param connection the MHD connection to handle
     32  * @param[in,out] hc context with further information about the request
     33  * @return MHD result code
     34  */
     35 enum MHD_Result
     36 TMH_private_get_webhooks_ID (const struct TMH_RequestHandler *rh,
     37                              struct MHD_Connection *connection,
     38                              struct TMH_HandlerContext *hc)
     39 {
     40   struct TMH_MerchantInstance *mi = hc->instance;
     41   struct TALER_MERCHANTDB_WebhookDetails wb = { 0 };
     42   enum GNUNET_DB_QueryStatus qs;
     43 
     44   GNUNET_assert (NULL != mi);
     45   qs = TALER_MERCHANTDB_lookup_webhook (TMH_db,
     46                                         mi->settings.id,
     47                                         hc->infix,
     48                                         &wb);
     49   if (0 > qs)
     50   {
     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                                        "lookup_webhook");
     56   }
     57   if (0 == qs)
     58   {
     59     return TALER_MHD_reply_with_error (connection,
     60                                        MHD_HTTP_NOT_FOUND,
     61                                        TALER_EC_MERCHANT_GENERIC_WEBHOOK_UNKNOWN,
     62                                        hc->infix);
     63   }
     64   {
     65     enum MHD_Result ret;
     66 
     67     ret = TALER_MHD_REPLY_JSON_PACK (
     68       connection,
     69       MHD_HTTP_OK,
     70       GNUNET_JSON_pack_string ("event_type",
     71                                wb.event_type),
     72       GNUNET_JSON_pack_string ("url",
     73                                wb.url),
     74       GNUNET_JSON_pack_string ("http_method",
     75                                wb.http_method),
     76       GNUNET_JSON_pack_allow_null (
     77         GNUNET_JSON_pack_string ("header_template",
     78                                  wb.header_template)),
     79       GNUNET_JSON_pack_allow_null (
     80         GNUNET_JSON_pack_string ("body_template",
     81                                  wb.body_template)));
     82     GNUNET_free (wb.event_type);
     83     GNUNET_free (wb.url);
     84     GNUNET_free (wb.http_method);
     85     GNUNET_free (wb.header_template);
     86     GNUNET_free (wb.body_template);
     87 
     88     return ret;
     89   }
     90 }
     91 
     92 
     93 /* end of taler-merchant-httpd_get-private-webhooks-WEBHOOK_ID.c */