merchant

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

taler-merchant-httpd_get-private-accounts-H_WIRE.c (4112B)


      1 /*
      2   This file is part of TALER
      3   (C) 2023, 2026 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-accounts-H_WIRE.c
     18  * @brief implement GET /accounts/$ID
     19  * @author Christian Grothoff
     20  */
     21 #include "platform.h"
     22 #include "taler-merchant-httpd_get-private-accounts-H_WIRE.h"
     23 #include <taler/taler_json_lib.h>
     24 #include "merchant-database/select_account.h"
     25 
     26 
     27 /**
     28  * Handle a GET "/accounts/$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_accounts_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   const char *h_wire_s = hc->infix;
     42   struct TALER_MerchantWireHashP h_wire;
     43   struct TALER_MERCHANTDB_AccountDetails tp = { 0 };
     44   enum GNUNET_DB_QueryStatus qs;
     45 
     46   GNUNET_assert (NULL != mi);
     47   GNUNET_assert (NULL != h_wire_s);
     48   if (GNUNET_OK !=
     49       GNUNET_STRINGS_string_to_data (h_wire_s,
     50                                      strlen (h_wire_s),
     51                                      &h_wire,
     52                                      sizeof (h_wire)))
     53   {
     54     GNUNET_break_op (0);
     55     return TALER_MHD_reply_with_error (connection,
     56                                        MHD_HTTP_BAD_REQUEST,
     57                                        TALER_EC_MERCHANT_GENERIC_H_WIRE_MALFORMED,
     58                                        h_wire_s);
     59   }
     60   qs = TALER_MERCHANTDB_select_account (TMH_db,
     61                                         mi->settings.id,
     62                                         &h_wire,
     63                                         &tp);
     64   if (0 > qs)
     65   {
     66     GNUNET_break (0);
     67     return TALER_MHD_reply_with_error (connection,
     68                                        MHD_HTTP_INTERNAL_SERVER_ERROR,
     69                                        TALER_EC_GENERIC_DB_FETCH_FAILED,
     70                                        "lookup_account");
     71   }
     72   if (0 == qs)
     73   {
     74     return TALER_MHD_reply_with_error (connection,
     75                                        MHD_HTTP_NOT_FOUND,
     76                                        TALER_EC_MERCHANT_GENERIC_ACCOUNT_UNKNOWN,
     77                                        hc->infix);
     78   }
     79   {
     80     enum MHD_Result ret;
     81 
     82     ret = TALER_MHD_REPLY_JSON_PACK (
     83       connection,
     84       MHD_HTTP_OK,
     85       GNUNET_JSON_pack_bool ("active",
     86                              tp.active),
     87       TALER_JSON_pack_full_payto ("payto_uri",
     88                                   tp.payto_uri),
     89       GNUNET_JSON_pack_data_auto ("h_wire",
     90                                   &tp.h_wire),
     91       GNUNET_JSON_pack_data_auto ("salt",
     92                                   &tp.salt),
     93       GNUNET_JSON_pack_allow_null (
     94         GNUNET_JSON_pack_string ("extra_wire_subject_metadata",
     95                                  tp.extra_wire_subject_metadata)),
     96       GNUNET_JSON_pack_allow_null (
     97         GNUNET_JSON_pack_string ("credit_facade_url",
     98                                  tp.credit_facade_url)));
     99     /* We do not return the credentials, as they may
    100        be sensitive */
    101     json_decref (tp.credit_facade_credentials);
    102     GNUNET_free (tp.extra_wire_subject_metadata);
    103     GNUNET_free (tp.payto_uri.full_payto);
    104     GNUNET_free (tp.credit_facade_url);
    105     return ret;
    106   }
    107 }
    108 
    109 
    110 /* end of taler-merchant-httpd_get-private-accounts-H_WIRE.c */