merchant

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

commit ce2b782914fcca9a0e95be3be7883bad3051b19b
parent d6a79317b64a03844cc4d27d52016b589a6743d1
Author: Bohdan Potuzhnyi <potub1@bfh.ch>
Date:   Wed,  9 Oct 2024 12:26:37 +0000

get,post,delete is working for /donau(/id) some improvements still could be made though

Diffstat:
Msrc/backend/Makefile.am | 4+++-
Msrc/backend/taler-merchant-httpd.c | 9+++++----
Asrc/backend/taler-merchant-httpd_private-delete-donau-instance-ID.c | 88+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/backend/taler-merchant-httpd_private-delete-donau-instance-ID.h | 44++++++++++++++++++++++++++++++++++++++++++++
Msrc/backend/taler-merchant-httpd_private-get-donau-instances.c | 87+++++++++++++++++++++++++++++++++++++++++++++++++++----------------------------
Asrc/backend/taler-merchant-httpd_private-post-donau-instance.c | 95+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/backend/taler-merchant-httpd_private-post-donau-instance.h | 41+++++++++++++++++++++++++++++++++++++++++
Msrc/backenddb/pg_delete_donau_instance.c | 2+-
Msrc/backenddb/pg_select_donau_instance.c | 182+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++------------------
Msrc/backenddb/pg_select_donau_instance.h | 6+++---
Msrc/include/taler_merchant_donau.h | 27+++++++++++++++++++++++++++
Msrc/include/taler_merchantdb_plugin.h | 3++-
12 files changed, 506 insertions(+), 82 deletions(-)

diff --git a/src/backend/Makefile.am b/src/backend/Makefile.am @@ -228,7 +228,9 @@ taler_merchant_httpd_SOURCES += \ taler-merchant-httpd_private-get-donau-instances.c \ taler-merchant-httpd_private-get-donau-instances.h \ taler-merchant-httpd_private-post-donau-instance.c \ - taler-merchant-httpd_private-post-donau-instance.h + taler-merchant-httpd_private-post-donau-instance.h \ + taler-merchant-httpd_private-delete-donau-instance-ID.c \ + taler-merchant-httpd_private-delete-donau-instance-ID.h endif taler_merchant_httpd_CFLAGS = \ diff --git a/src/backend/taler-merchant-httpd.c b/src/backend/taler-merchant-httpd.c @@ -100,7 +100,7 @@ #ifdef HAVE_DONAU_DONAU_SERVICE_H #include "taler-merchant-httpd_private-get-donau-instances.h" #include "taler-merchant-httpd_private-post-donau-instance.h" -//#include "taler-merchant-httpd_private-delete-donau-instance.h" +#include "taler-merchant-httpd_private-delete-donau-instance-ID.h" #endif /** @@ -1356,11 +1356,12 @@ url_handler (void *cls, .handler = &TMH_private_post_donau_instance }, /* DELETE /donau/$charity-id */ - /* { + { .url_prefix = "/donau/", .method = MHD_HTTP_METHOD_DELETE, - .handler = &TMH_private_delete_donau_instance - } */ + .have_id_segment = true, + .handler = &TMH_private_delete_donau_instance_ID + }, #endif { .url_prefix = NULL diff --git a/src/backend/taler-merchant-httpd_private-delete-donau-instance-ID.c b/src/backend/taler-merchant-httpd_private-delete-donau-instance-ID.c @@ -0,0 +1,87 @@ +/* + This file is part of TALER + (C) 2024 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_private-delete-donau-instance-ID.c + * @brief implement DELETE /private/donau/$charity_id + * @author Bohdan Potuzhnyi + * @author Vlada Svirsh + */ + +#include "platform.h" +#include "taler-merchant-httpd_private-delete-donau-instance-ID.h" +#include <taler/taler_json_lib.h> +#include <taler/taler_error_codes.h> +#include <taler/taler_dbevents.h> + +/** + * Handle a DELETE "/donau/$charity_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_donau_instance_ID (const struct TMH_RequestHandler *rh, + struct MHD_Connection *connection, + struct TMH_HandlerContext *hc) +{ + struct TMH_MerchantInstance *mi = hc->instance; + enum GNUNET_DB_QueryStatus qs; + uint64_t charity_id; + char dummy; + + (void) rh; + GNUNET_assert(NULL != mi); + + if (1 != sscanf(hc->infix, "%lu%c", &charity_id, &dummy)) + { + return TALER_MHD_reply_with_error(connection, + MHD_HTTP_BAD_REQUEST, + TALER_EC_GENERIC_PARAMETER_MALFORMED, + hc->infix); + } + + qs = TMH_db->delete_donau_instance(TMH_db->cls, charity_id); + + switch (qs) + { + case GNUNET_DB_STATUS_HARD_ERROR: + return TALER_MHD_reply_with_error(connection, + MHD_HTTP_INTERNAL_SERVER_ERROR, + TALER_EC_GENERIC_DB_STORE_FAILED, + "delete_donau_instance"); + + case GNUNET_DB_STATUS_SOFT_ERROR: + GNUNET_break(0); + return TALER_MHD_reply_with_error(connection, + MHD_HTTP_INTERNAL_SERVER_ERROR, + TALER_EC_GENERIC_INTERNAL_INVARIANT_FAILURE, + "delete_donau_instance (soft)"); + + case GNUNET_DB_STATUS_SUCCESS_NO_RESULTS: + return TALER_MHD_reply_with_error(connection, + MHD_HTTP_NOT_FOUND, + TALER_EC_MERCHANT_GENERIC_INSTANCE_UNKNOWN, + hc->infix); + + case GNUNET_DB_STATUS_SUCCESS_ONE_RESULT: + return TALER_MHD_reply_static(connection, MHD_HTTP_NO_CONTENT, NULL, NULL, 0); + } + + GNUNET_assert(0); + return MHD_NO; +} +\ No newline at end of file diff --git a/src/backend/taler-merchant-httpd_private-delete-donau-instance-ID.h b/src/backend/taler-merchant-httpd_private-delete-donau-instance-ID.h @@ -0,0 +1,44 @@ +/* + This file is part of TALER + (C) 2024 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_private-delete-donau-instance-ID.h + * @brief implement DELETE /private/donau/$charity_id/ + * @author Bohdan Potuzhnyi + * @author Vlada Svirsh + */ + +#ifndef TALER_MERCHANT_HTTPD_PRIVATE_DELETE_DONAU_INSTANCE_ID_H +#define TALER_MERCHANT_HTTPD_PRIVATE_DELETE_DONAU_INSTANCE_ID_H + +#include "taler-merchant-httpd.h" + + +/** + * Handle a DELETE "/donau/$charity_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_donau_instance_ID ( + const struct TMH_RequestHandler *rh, + struct MHD_Connection *connection, + struct TMH_HandlerContext *hc); + +/* end of taler-merchant-httpd_private-delete-donau-instance-ID.h */ +#endif diff --git a/src/backend/taler-merchant-httpd_private-get-donau-instances.c b/src/backend/taler-merchant-httpd_private-get-donau-instances.c @@ -32,27 +32,52 @@ * Add details about a Donau instance to the JSON array. * * @param json_instances JSON array to which Donau instance information is added - * @param di pointer to the Donau instance info + * @param donau_url the URL of the Donau instance + * @param charity_name the name of the charity + * @param charity_pub_key the public key of the charity + * @param charity_id the ID of the charity + * @param charity_max_per_year the maximum donation amount per year + * @param charity_receipts_to_date the total donations received so far this year + * @param current_year the current year being tracked for donations + * @param donau_keys_json JSON object with key information specific to the Donau instance */ static void -add_donau_instance_to_json (json_t *json_instances, const struct TALER_MERCHANTDB_DonauInstance *di) +add_donau_instance (void *cls, + const char *donau_url, + const char *charity_name, + const struct DONAU_CharityPublicKeyP *charity_pub_key, + uint64_t charity_id, + const struct TALER_Amount *charity_max_per_year, + const struct TALER_Amount *charity_receipts_to_date, + int64_t current_year, + const json_t *donau_keys_json) { - GNUNET_assert (NULL != json_instances); - json_t *instance; - instance = GNUNET_JSON_PACK ( - GNUNET_JSON_pack_string ("donau_url", di->donau_url), - GNUNET_JSON_pack_string ("charity_name", di->charity_name), - GNUNET_JSON_pack_data_auto("charity_pub_key", &di->charity_pub_key), - GNUNET_JSON_pack_uint64 ("charity_id", di->charity_id), - TALER_JSON_pack_amount ("charity_max_per_year", &di->charity_max_per_year), - TALER_JSON_pack_amount ("charity_receipts_to_date", &di->charity_receipts_to_date), - GNUNET_JSON_pack_int64 ("current_year", di->current_year), - GNUNET_JSON_pack_object_incref ("donau_keys_json", di->donau_keys_json) - ); + json_t *json_instances = cls; - GNUNET_assert (0 == json_array_append_new (json_instances, instance)); + GNUNET_assert ( + 0 == json_array_append_new ( + json_instances, + GNUNET_JSON_PACK ( + GNUNET_JSON_pack_string ("donau_url", + donau_url), + GNUNET_JSON_pack_string ("charity_name", + charity_name), + GNUNET_JSON_pack_data_auto ("charity_pub_key", + charity_pub_key), + GNUNET_JSON_pack_uint64 ("charity_id", + charity_id), + TALER_JSON_pack_amount ("charity_max_per_year", + charity_max_per_year), + TALER_JSON_pack_amount ("charity_receipts_to_date", + charity_receipts_to_date), + GNUNET_JSON_pack_int64 ("current_year", + current_year), + GNUNET_JSON_pack_object_incref ("donau_keys_json", + (json_t *) donau_keys_json) + ))); } + /** * Handle a GET "/donau" request. * @@ -66,28 +91,27 @@ TMH_private_get_donau_instances (const struct TMH_RequestHandler *rh, struct MHD_Connection *connection, struct TMH_HandlerContext *hc) { - json_t *json_instances = json_array (); - struct TALER_MERCHANTDB_DonauInstance di; /* Data structure for Donau instances */ + json_t *json_donau_instances = json_array(); enum GNUNET_DB_QueryStatus qs; - /* Query the database to fetch Donau instances */ - while (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT == (qs = TMH_db->select_donau_instance(TMH_db->cls, &di))) - { - add_donau_instance_to_json(json_instances, &di); /* Add the instance to the JSON array */ - } + GNUNET_assert (NULL != json_donau_instances); + qs = TMH_db->select_donau_instance(TMH_db->cls, + &add_donau_instance, + json_donau_instances); if (0 > qs) { - /* If there was a database error, return an internal server error */ GNUNET_break(0); - json_decref(json_instances); - return TALER_MHD_reply_with_error(connection, MHD_HTTP_INTERNAL_SERVER_ERROR, - TALER_EC_GENERIC_DB_FETCH_FAILED, NULL); + json_decref(json_donau_instances); + return TALER_MHD_reply_with_error(connection, + MHD_HTTP_INTERNAL_SERVER_ERROR, + TALER_EC_GENERIC_DB_FETCH_FAILED, + NULL); } /* Return the JSON array as the response */ - return TALER_MHD_REPLY_JSON_PACK(connection, MHD_HTTP_OK, - GNUNET_JSON_pack_array_steal("donau_instances", json_instances)); -} - -/* End of taler-merchant-httpd_get-donau-instances.c */ + return TALER_MHD_REPLY_JSON_PACK(connection, + MHD_HTTP_OK, + GNUNET_JSON_pack_array_steal("donau_instances", + json_donau_instances)); +} +\ No newline at end of file diff --git a/src/backend/taler-merchant-httpd_private-post-donau-instance.c b/src/backend/taler-merchant-httpd_private-post-donau-instance.c @@ -0,0 +1,95 @@ +/* + This file is part of TALER + Copyright (C) 2024 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_post-donau-instance.c + * @brief implementation of POST /donau + * @author Bohdan Potuzhnyi + * @author Vlada Svirsh + */ + +#include "platform.h" +#include <jansson.h> +#include "donau/donau_service.h" +#include <taler/taler_json_lib.h> +#include <taler/taler_dbevents.h> +#include "taler_merchant_service.h" +#include "taler-merchant-httpd_private-post-donau-instance.h" + +/** + * Handle a POST "/donau" 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_post_donau_instance (const struct TMH_RequestHandler *rh, + struct MHD_Connection *connection, + struct TMH_HandlerContext *hc) +{ + struct DONAU_Charity charity; + const char *donau_url = NULL; + uint64_t charity_id = 0; + struct GNUNET_JSON_Specification spec[] = { + GNUNET_JSON_spec_string ("donau_url", &donau_url), + GNUNET_JSON_spec_string ("charity_name", (const char **) &charity.name), + GNUNET_JSON_spec_fixed_auto ("charity_pub_key", &charity.charity_pub), + GNUNET_JSON_spec_uint64 ("charity_id", &charity_id), + TALER_JSON_spec_amount_any ("max_per_year", &charity.max_per_year), + TALER_JSON_spec_amount_any ("receipts_to_date", &charity.receipts_to_date), + GNUNET_JSON_spec_uint64 ("current_year", &charity.current_year), + GNUNET_JSON_spec_end() + }; + + // Parse JSON body of the request + if (GNUNET_OK != TALER_MHD_parse_json_data(connection, hc->request_body, spec)) + { + return MHD_NO; + } + + // Validate the required parameters + if (NULL == donau_url || NULL == charity.name) + { + return TALER_MHD_reply_with_error(connection, + MHD_HTTP_BAD_REQUEST, + TALER_EC_GENERIC_PARAMETER_MALFORMED, + "Missing donau_url or charity_name"); + } + + // Try to insert the new Donau instance into the database + enum GNUNET_DB_QueryStatus qs = TMH_db->insert_donau_instance(TMH_db->cls, + donau_url, + &charity, + charity_id); + switch (qs) + { + case GNUNET_DB_STATUS_SUCCESS_ONE_RESULT: + return TALER_MHD_reply_static(connection, MHD_HTTP_NO_CONTENT, NULL, NULL, 0); + case GNUNET_DB_STATUS_HARD_ERROR: + return TALER_MHD_reply_with_error(connection, + MHD_HTTP_INTERNAL_SERVER_ERROR, + TALER_EC_GENERIC_DB_STORE_FAILED, + "Failed to insert Donau instance"); + case GNUNET_DB_STATUS_SOFT_ERROR: + case GNUNET_DB_STATUS_SUCCESS_NO_RESULTS: + default: + return TALER_MHD_reply_with_error(connection, + MHD_HTTP_INTERNAL_SERVER_ERROR, + TALER_EC_GENERIC_DB_COMMIT_FAILED, + "Database operation failed"); + } +} diff --git a/src/backend/taler-merchant-httpd_private-post-donau-instance.h b/src/backend/taler-merchant-httpd_private-post-donau-instance.h @@ -0,0 +1,41 @@ +/* + This file is part of TALER + Copyright (C) 2024 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_post-donau-instance.h + * @brief implementation of POST /donau + * @author Bohdan Potuzhnyi + * @author Vlada Svirsh + */ + +#ifndef TALER_MERCHANT_HTTPD_POST_DONAU_INSTANCE_H +#define TALER_MERCHANT_HTTPD_POST_DONAU_INSTANCE_H + +#include "taler-merchant-httpd.h" + +/** + * Handle a POST "/donau" 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_post_donau_instance (const struct TMH_RequestHandler *rh, + struct MHD_Connection *connection, + struct TMH_HandlerContext *hc); + +#endif diff --git a/src/backenddb/pg_delete_donau_instance.c b/src/backenddb/pg_delete_donau_instance.c @@ -40,7 +40,7 @@ TMH_PG_delete_donau_instance ( check_connection (pg); PREPARE (pg, "delete_donau_instance", - "DELETE FROM donau_instance WHERE charity_id = $1"); + "DELETE FROM merchant_donau_instances WHERE charity_id = $1"); return GNUNET_PQ_eval_prepared_non_select (pg->conn, "delete_donau_instance", params); diff --git a/src/backenddb/pg_select_donau_instance.c b/src/backenddb/pg_select_donau_instance.c @@ -24,56 +24,156 @@ #include <taler/taler_dbevents.h> #include <taler/taler_pq_lib.h> #include "pg_select_donau_instance.h" +#include "taler_merchant_donau.h" #include "pg_helper.h" +/** + * Context for select_donau_instances(). + */ +struct SelectDonauInstanceContext +{ + /** + * Function to call with the results. + */ + TALER_MERCHANTDB_DonauInstanceCallback cb; + + /** + * Closure for @e cb. + */ + void *cb_cls; + + /** + * Did database result extraction fail? + */ + bool extract_failed; +}; + + +/** + * Function to be called with the results of a SELECT statement + * that has returned @a num_results results about donau instances. + * + * @param[in, out] cls of type `struct SelectDonauInstanceContext *` + * @param result the postgres result + * @param num_results the number of results in @a result + */ +static void +select_donau_instance_cb (void *cls, + PGresult *result, + unsigned int num_results) +{ + struct SelectDonauInstanceContext *sdc = cls; + + for (unsigned int i = 0; i < num_results; i++) + { + char *donau_url; + char *charity_name; + struct DONAU_CharityPublicKeyP charity_pub_key; + uint64_t charity_id; + struct TALER_Amount charity_max_per_year; + struct TALER_Amount charity_receipts_to_date; + int64_t current_year; + json_t *donau_keys_json; + + struct GNUNET_PQ_ResultSpec rs[] = { + GNUNET_PQ_result_spec_string ("donau_url", + &donau_url), + GNUNET_PQ_result_spec_string ("charity_name", + &charity_name), + GNUNET_PQ_result_spec_auto_from_type ("charity_pub_key", + &charity_pub_key), + GNUNET_PQ_result_spec_uint64 ("charity_id", + &charity_id), + TALER_PQ_result_spec_amount_with_currency ("charity_max_per_year", + &charity_max_per_year), + TALER_PQ_result_spec_amount_with_currency ("charity_receipts_to_date", + &charity_receipts_to_date), + GNUNET_PQ_result_spec_int64 ("current_year", + &current_year), + TALER_PQ_result_spec_json ("keys_json", + &donau_keys_json), + GNUNET_PQ_result_spec_end + }; + + // Extract result for each row + if (GNUNET_OK != + GNUNET_PQ_extract_result(result, + rs, + i)) + { + GNUNET_break(0); // Break on failure + sdc->extract_failed = true; + return; + } + + // Call the callback function with the individual values + sdc->cb(sdc->cb_cls, + donau_url, + charity_name, + &charity_pub_key, + charity_id, + &charity_max_per_year, + &charity_receipts_to_date, + current_year, + donau_keys_json); + + // Clean up any dynamically allocated results in the result spec + GNUNET_PQ_cleanup_result(rs); + } +} + + +/** + * Select multiple Donau instances from the database. + * + * @param cls the closure for the database context + * @param cb callback function to call with each result + * @param cb_cls closure for the callback + * @return status of the operation + */ enum GNUNET_DB_QueryStatus TMH_PG_select_donau_instance (void *cls, - struct TALER_MERCHANTDB_DonauInstance *di) + TALER_MERCHANTDB_DonauInstanceCallback cb, + void *cb_cls) { struct PostgresClosure *pg = cls; + struct SelectDonauInstanceContext sdc = { + .cb = cb, + .cb_cls = cb_cls, + /* Can be overwritten by the select_donau_instance_cb */ + .extract_failed = false, + }; + struct GNUNET_PQ_QueryParam params[] = { GNUNET_PQ_query_param_end }; + enum GNUNET_DB_QueryStatus qs; - struct GNUNET_PQ_ResultSpec rs[] = { - GNUNET_PQ_result_spec_string ("donau_url", - &di->donau_url), - GNUNET_PQ_result_spec_string ("charity_name", - &di->charity_name), - GNUNET_PQ_result_spec_auto_from_type ("charity_pub_key", - &di->charity_pub_key), - GNUNET_PQ_result_spec_uint64 ("charity_id", - &di->charity_id), - TALER_PQ_result_spec_amount_with_currency ("charity_max_per_year", - &di->charity_max_per_year), - TALER_PQ_result_spec_amount_with_currency ("charity_receipts_to_date", - &di->charity_receipts_to_date), - GNUNET_PQ_result_spec_int64 ("current_year", - &di->current_year), - TALER_PQ_result_spec_json ("keys_json", - &di->donau_keys_json), - GNUNET_PQ_result_spec_end - }; + check_connection(pg); + PREPARE(pg, + "select_donau_instances", + "SELECT" + " di.donau_url" + ",di.charity_name" + ",di.charity_pub_key" + ",di.charity_id" + ",di.charity_max_per_year" + ",di.charity_receipts_to_date" + ",di.current_year" + ",dk.keys_json" + " FROM merchant_donau_instances di" + " JOIN merchant_donau_keys dk" + " ON di.donau_url = dk.donau_url"); + + qs = GNUNET_PQ_eval_prepared_multi_select(pg->conn, + "select_donau_instances", + params, + &select_donau_instance_cb, + &sdc); + + /* If there was an error inside select_donau_instance_cb, return a hard error. */ + if (sdc.extract_failed) + return GNUNET_DB_STATUS_HARD_ERROR; - check_connection (pg); - - PREPARE (pg, - "select_donau_instance", - "SELECT" - " di.donau_url" - ",di.charity_name" - ",di.charity_pub_key" - ",di.charity_id" - ",di.charity_max_per_year" - ",di.charity_receipts_to_date" - ",di.current_year" - ",dk.keys_json" - " FROM merchant_donau_instances di" - " JOIN merchant_donau_keys dk" - " ON di.donau_url = dk.donau_url"); - - return GNUNET_PQ_eval_prepared_singleton_select (pg->conn, - "select_donau_instance", - params, - rs); + return qs; } \ No newline at end of file diff --git a/src/backenddb/pg_select_donau_instance.h b/src/backenddb/pg_select_donau_instance.h @@ -37,8 +37,8 @@ * @return database result code */ enum GNUNET_DB_QueryStatus -TMH_PG_select_donau_instance ( - void *cls, - struct TALER_MERCHANTDB_DonauInstance *di); +TMH_PG_select_donau_instance (void *cls, + TALER_MERCHANTDB_DonauInstanceCallback cb, + void *cb_cls); #endif diff --git a/src/include/taler_merchant_donau.h b/src/include/taler_merchant_donau.h @@ -26,6 +26,7 @@ #include <taler/taler_error_codes.h> #include <taler/taler_exchange_service.h> #include <donau/donau_util.h> +#include <donau/donaudb_plugin.h> struct TALER_MERCHANT_DONAU_Charity { @@ -117,5 +118,31 @@ struct TALER_MERCHANTDB_DonauInstance json_t *donau_keys_json; }; +/** + * Callback function typically used by `select_donau_instances` to handle + * the details of each Donau instance retrieved from the database. + * + * @param cls Closure to pass additional context or data to the callback function. + * @param donau_url The URL of the Donau instance. + * @param charity_name The name of the charity associated with the Donau instance. + * @param charity_pub_key Pointer to the charity's public key used for cryptographic operations. + * @param charity_id The unique identifier for the charity within the Donau instance. + * @param charity_max_per_year Maximum allowed donations to the charity for the current year. + * @param charity_receipts_to_date Total donations received by the charity so far in the current year. + * @param current_year The year for which the donation data is being tracked. + * @param donau_keys_json JSON object containing additional key-related information for the Donau instance. + */ +typedef void +(*TALER_MERCHANTDB_DonauInstanceCallback)( + void *cls, + const char *donau_url, + const char *charity_name, + const struct DONAU_CharityPublicKeyP *charity_pub_key, + uint64_t charity_id, + const struct TALER_Amount *charity_max_per_year, + const struct TALER_Amount *charity_receipts_to_date, + int64_t current_year, + const json_t *donau_keys_json +); #endif \ No newline at end of file diff --git a/src/include/taler_merchantdb_plugin.h b/src/include/taler_merchantdb_plugin.h @@ -3852,7 +3852,8 @@ struct TALER_MERCHANTDB_Plugin enum GNUNET_DB_QueryStatus (*select_donau_instance)( void *cls, - struct TALER_MERCHANTDB_DonauInstance *di + TALER_MERCHANTDB_DonauInstanceCallback cb, + void *cb_cls ); enum GNUNET_DB_QueryStatus