merchant

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

commit 6b35253b5ebefe033ac94a480cf7ad15ea011691
parent 9dc5fe1e05c4819a83a35324c0286b472d26298a
Author: Christian Grothoff <christian@grothoff.org>
Date:   Fri, 26 Dec 2025 21:56:17 +0100

begin REST API implementation

Diffstat:
Asrc/backend/taler-merchant-httpd_private-delete-report.c | 76++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/backend/taler-merchant-httpd_private-delete-report.h | 40++++++++++++++++++++++++++++++++++++++++
Msrc/backenddb/pg_lookup_reports_pending.c | 13+++++++------
Msrc/include/taler_merchantdb_plugin.h | 9++++++---
4 files changed, 129 insertions(+), 9 deletions(-)

diff --git a/src/backend/taler-merchant-httpd_private-delete-report.c b/src/backend/taler-merchant-httpd_private-delete-report.c @@ -0,0 +1,76 @@ +/* + This file is part of TALER + (C) 2025 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 Affero General Public License for more + details. + + You should have received a copy of the GNU Affero General Public License + along with TALER; see the file COPYING. If not, see + <http://www.gnu.org/licenses/> +*/ +/** + * @file merchant/backend/taler-merchant-httpd_private-delete-report.c + * @brief implementation of DELETE /private/reports/$REPORT_ID + * @author Christian Grothoff + */ +#include "platform.h" +#include "taler-merchant-httpd_private-delete-report.h" +#include <taler/taler_json_lib.h> + + +MHD_RESULT +TMH_private_delete_report (const struct TMH_RequestHandler *rh, + struct MHD_Connection *connection, + struct TMH_HandlerContext *hc) +{ + const char *report_id_str = hc->infix; + unsigned long long report_id; + enum GNUNET_DB_QueryStatus qs; + char dummy; + + (void) rh; + + if (1 != + sscanf (report_id_str, + "%llu%c", + &report_id, + &dummy)) + { + GNUNET_break_op (0); + return TALER_MHD_reply_with_error (connection, + MHD_HTTP_BAD_REQUEST, + TALER_EC_GENERIC_PARAMETER_MALFORMED, + "report_id"); + } + + qs = TMH_db->delete_report (TMH_db->cls, + hc->instance->settings.id, + (uint64_t) report_id); + if (qs < 0) + { + GNUNET_break_op (0); + return TALER_MHD_reply_with_error (connection, + MHD_HTTP_INTERNAL_SERVER_ERROR, + TALER_EC_GENERIC_DB_STORE_FAILED, + "delete_report"); + } + if (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS == qs) + { + return TALER_MHD_reply_with_error (connection, + MHD_HTTP_NOT_FOUND, + TALER_EC_MERCHANT_GENERIC_REPORT_UNKNOWN, + report_id_str); + } + return TALER_MHD_reply_static (connection, + MHD_HTTP_NO_CONTENT, + NULL, + NULL, + 0); +} diff --git a/src/backend/taler-merchant-httpd_private-delete-report.h b/src/backend/taler-merchant-httpd_private-delete-report.h @@ -0,0 +1,40 @@ +/* + This file is part of TALER + (C) 2025 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 Affero General Public License for more + details. + + You should have received a copy of the GNU Affero General Public License + along with TALER; see the file COPYING. If not, see + <http://www.gnu.org/licenses/> +*/ +/** + * @file merchant/backend/taler-merchant-httpd_private-delete-report.h + * @brief HTTP serving layer for deleting reports + * @author Christian Grothoff + */ +#ifndef TALER_MERCHANT_HTTPD_PRIVATE_DELETE_REPORT_H +#define TALER_MERCHANT_HTTPD_PRIVATE_DELETE_REPORT_H +#include "taler-merchant-httpd.h" + +/** + * Handle DELETE /private/reports/$REPORT_ID request. + * + * @param rh context of the handler + * @param connection the MHD connection to handle + * @param[in,out] hc context with further information about the request + * @return MHD result code + */ +MHD_RESULT +TMH_private_delete_report (const struct TMH_RequestHandler *rh, + struct MHD_Connection *connection, + struct TMH_HandlerContext *hc); + +#endif diff --git a/src/backenddb/pg_lookup_reports_pending.c b/src/backenddb/pg_lookup_reports_pending.c @@ -74,6 +74,7 @@ select_pending_reports_cb (void *cls, char *target_address; struct GNUNET_TIME_Relative frequency; struct GNUNET_TIME_Relative frequency_shift; + struct GNUNET_TIME_Absolute next_transmission; struct GNUNET_PQ_ResultSpec rs[] = { GNUNET_PQ_result_spec_string ("merchant_id", &instance_id), @@ -93,6 +94,8 @@ select_pending_reports_cb (void *cls, &frequency), GNUNET_PQ_result_spec_relative_time ("frequency_shift", &frequency_shift), + GNUNET_PQ_result_spec_absolute_time ("next_transmission", + &next_transmission), GNUNET_PQ_result_spec_end }; @@ -114,7 +117,8 @@ select_pending_reports_cb (void *cls, data_source, target_address, frequency, - frequency_shift); + frequency_shift, + next_transmission); GNUNET_PQ_cleanup_result (rs); } } @@ -132,10 +136,7 @@ TMH_PG_lookup_reports_pending (void *cls, /* Can be overwritten by the lookup_reports_cb */ .extract_failed = false, }; - struct GNUNET_TIME_Absolute now - = GNUNET_TIME_absolute_get (); struct GNUNET_PQ_QueryParam params[] = { - GNUNET_PQ_query_param_absolute_time (&now), GNUNET_PQ_query_param_end }; enum GNUNET_DB_QueryStatus qs; @@ -153,12 +154,12 @@ TMH_PG_lookup_reports_pending (void *cls, " ,mr.target_address" " ,mr.frequency" " ,mr.frequency_shift" + " ,mr.next_transmission" " FROM merchant_reports mr" " JOIN merchant_instances mi" " USING (merchant_serial)" - " WHERE next_transmission <= $1" " ORDER BY next_transmission ASC" - " LIMIT 1000"); + " LIMIT 1;"); qs = GNUNET_PQ_eval_prepared_multi_select ( pg->conn, "lookup_reports_pending", diff --git a/src/include/taler_merchantdb_plugin.h b/src/include/taler_merchantdb_plugin.h @@ -1381,6 +1381,8 @@ typedef void * @param frequency report frequency * @param frequency_shift how much to shift the report time from a * multiple of the report @a frequency + * @param next_transmission when is the next transmission of this report + * due */ typedef void (*TALER_MERCHANTDB_ReportsPendingCallback)( @@ -1393,7 +1395,8 @@ typedef void const char *data_source, const char *target_address, struct GNUNET_TIME_Relative frequency, - struct GNUNET_TIME_Relative frequency_shift); + struct GNUNET_TIME_Relative frequency_shift, + struct GNUNET_TIME_Absolute next_transmission); /** @@ -5146,10 +5149,10 @@ struct TALER_MERCHANTDB_Plugin /** - * Insert details about a particular pot. + * Insert details about a particular report. * * @param cls closure - * @param instance_id instance to insert pot for + * @param instance_id instance to insert report for * @param report_program_section configuration section of program * for report generation * @param report_description text describing the report