merchant

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

commit 05bbd2001bdc26b1aa0e8a25efa282e607cffb8c
parent e7b7ede1bb63d2dd5563dba070830587b0330bca
Author: Christian Grothoff <christian@grothoff.org>
Date:   Sat,  7 Feb 2026 21:54:38 +0100

add new GET /exchanges endpoint

Diffstat:
Msrc/backend/Makefile.am | 5++++-
Msrc/backend/taler-merchant-httpd_dispatcher.c | 8++++++++
Asrc/backend/taler-merchant-httpd_get-exchanges.c | 109+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/backend/taler-merchant-httpd_get-exchanges.h | 40++++++++++++++++++++++++++++++++++++++++
Msrc/backend/taler-merchant-httpd_private-get-templates.c | 2+-
5 files changed, 162 insertions(+), 2 deletions(-)

diff --git a/src/backend/Makefile.am b/src/backend/Makefile.am @@ -78,7 +78,6 @@ taler_merchant_httpd_SOURCES = \ taler-merchant-httpd.c taler-merchant-httpd.h \ taler-merchant-httpd_auth.c \ taler-merchant-httpd_auth.h \ - taler-merchant-httpd_get-config.c taler-merchant-httpd_get-config.h \ taler-merchant-httpd_contract.c taler-merchant-httpd_contract.h \ taler-merchant-httpd_dispatcher.c \ taler-merchant-httpd_dispatcher.h \ @@ -89,6 +88,10 @@ taler_merchant_httpd_SOURCES = \ taler-merchant-httpd_get-sessions-ID.h \ taler-merchant-httpd_get-products-HASH-image.c \ taler-merchant-httpd_get-products-HASH-image.h \ + taler-merchant-httpd_get-config.c \ + taler-merchant-httpd_get-config.h \ + taler-merchant-httpd_get-exchanges.c \ + taler-merchant-httpd_get-exchanges.h \ taler-merchant-httpd_get-templates-ID.c \ taler-merchant-httpd_get-templates-ID.h \ taler-merchant-httpd_helper.c \ diff --git a/src/backend/taler-merchant-httpd_dispatcher.c b/src/backend/taler-merchant-httpd_dispatcher.c @@ -20,6 +20,7 @@ */ #include "platform.h" #include "taler-merchant-httpd_get-config.h" +#include "taler-merchant-httpd_get-exchanges.h" #include "taler-merchant-httpd_dispatcher.h" #include "taler-merchant-httpd_exchanges.h" #include "taler-merchant-httpd_get-orders-ID.h" @@ -1075,6 +1076,13 @@ determine_handler_group (const char **urlp, .handler = &MH_handler_config }, { + .url_prefix = "/exchanges", + .method = MHD_HTTP_METHOD_GET, + .skip_instance = true, + .default_only = true, + .handler = &MH_handler_exchanges + }, + { /* for "normal" instance,s they must exist before we give the WebUI */ .url_prefix = "/", diff --git a/src/backend/taler-merchant-httpd_get-exchanges.c b/src/backend/taler-merchant-httpd_get-exchanges.c @@ -0,0 +1,109 @@ +/* + This file is part of TALER + (C) 2026 Taler Systems SA + + TALER is free software; you can redistribute it and/or modify it under the + terms of the GNU Affero General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + TALER is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> +*/ +/** + * @file taler-merchant-httpd_exchanges.c + * @brief implement API for querying exchange status + * @author Christian Grothoff + */ +#include "platform.h" +#include <jansson.h> +#include <taler/taler_util.h> +#include <taler/taler_json_lib.h> +#include "taler-merchant-httpd.h" +#include "taler-merchant-httpd_get-exchanges.h" +#include "taler-merchant-httpd_mhd.h" +#include "taler-merchant-httpd_exchanges.h" + + +/** + * Callback on an exchange known to us. + * + * @param cls closure with `json_t *` array to expand + * @param exchange_url base URL of the exchange + * @param next_download when will be the next download + * @param keys_expiration when does the current ``/keys`` response expire + * @param http_status last HTTP status from ``/keys`` + * @param ec last error code from fetching ``/keys`` + */ +static void +add_exchange ( + void *cls, + const char *exchange_url, + struct GNUNET_TIME_Absolute next_download, + struct GNUNET_TIME_Absolute keys_expiration, + unsigned int http_status, + enum TALER_ErrorCode ec) +{ + json_t *xa = cls; + json_t *xi; + + xi = GNUNET_JSON_PACK ( + GNUNET_JSON_pack_string ("exchange_url", + exchange_url), + GNUNET_JSON_pack_timestamp ("next_download", + GNUNET_TIME_absolute_to_timestamp (next_download + )), + GNUNET_TIME_absolute_is_zero (keys_expiration) + ? GNUNET_JSON_pack_allow_null ( + GNUNET_JSON_pack_string ("dummy", + NULL)) + : GNUNET_JSON_pack_timestamp ("keys_expiration", + GNUNET_TIME_absolute_to_timestamp ( + keys_expiration)), + GNUNET_JSON_pack_uint64 ("keys_http_status", + http_status), + GNUNET_JSON_pack_uint64 ("keys_ec", + ec), + GNUNET_JSON_pack_string ("keys_hint", + TALER_ErrorCode_get_hint (ec))); + GNUNET_assert (NULL != xi); + GNUNET_assert (0 == + json_array_append_new (xa, + xi)); +} + + +MHD_RESULT +MH_handler_exchanges (const struct TMH_RequestHandler *rh, + struct MHD_Connection *connection, + struct TMH_HandlerContext *hc) +{ + json_t *exchanges; + enum GNUNET_DB_QueryStatus qs; + + exchanges = json_array (); + GNUNET_assert (NULL != exchanges); + qs = TMH_db->select_exchanges (TMH_db->cls, + &add_exchange, + exchanges); + if (0 > qs) + { + GNUNET_break (0); + json_decref (exchanges); + return TALER_MHD_reply_with_error (connection, + MHD_HTTP_INTERNAL_SERVER_ERROR, + TALER_EC_GENERIC_DB_FETCH_FAILED, + "select_exchanges"); + } + return TALER_MHD_REPLY_JSON_PACK ( + connection, + MHD_HTTP_OK, + GNUNET_JSON_pack_object_steal ("exchanges", + exchanges)); +} + + +/* end of taler-merchant-httpd_exchanges.c */ diff --git a/src/backend/taler-merchant-httpd_get-exchanges.h b/src/backend/taler-merchant-httpd_get-exchanges.h @@ -0,0 +1,40 @@ +/* + This file is part of TALER + (C) 2026 Taler Systems SA + + TALER is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + TALER is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> +*/ +/** + * @file taler-merchant-httpd_exchanges.h + * @brief headers for /exchanges handler + * @author Christian Grothoff + */ +#ifndef TALER_MERCHANT_HTTPD_GET_EXCHANGES_H +#define TALER_MERCHANT_HTTPD_GET_EXCHANGES_H +#include <microhttpd.h> +#include "taler-merchant-httpd.h" + + +/** + * Manages a /exchanges call. + * + * @param rh context of the handler + * @param connection the MHD connection to handle + * @param[in,out] hc handler context (can be updated) + * @return MHD result code + */ +MHD_RESULT +MH_handler_exchanges (const struct TMH_RequestHandler *rh, + struct MHD_Connection *connection, + struct TMH_HandlerContext *hc); + +#endif diff --git a/src/backend/taler-merchant-httpd_private-get-templates.c b/src/backend/taler-merchant-httpd_private-get-templates.c @@ -67,7 +67,7 @@ TMH_private_get_templates (const struct TMH_RequestHandler *rh, return TALER_MHD_reply_with_error (connection, MHD_HTTP_INTERNAL_SERVER_ERROR, TALER_EC_GENERIC_DB_FETCH_FAILED, - NULL); + "lookup_templates"); } return TALER_MHD_REPLY_JSON_PACK (connection, MHD_HTTP_OK,