merchant

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

commit 063140e4872549d4aa348913377ba707a591a878
parent 3a2adbdaa523ddeed48a4f01788b699ef7916c56
Author: Bohdan Potuzhnyi <potub1@bfh.ch>
Date:   Mon,  7 Oct 2024 14:42:47 +0000

few updates

Diffstat:
Msrc/backend/Makefile.am | 4++++
Msrc/backend/taler-merchant-httpd.c | 11+++++++++++
Asrc/backend/taler-merchant-httpd_private-get-donau-instances.c | 93+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/backend/taler-merchant-httpd_private-get-donau-instances.h | 43+++++++++++++++++++++++++++++++++++++++++++
Msrc/backenddb/Makefile.am | 11++++++++---
Msrc/include/taler_merchant_donau.h | 39+++++++++++++++++++++++++++++++++++++++
6 files changed, 198 insertions(+), 3 deletions(-)

diff --git a/src/backend/Makefile.am b/src/backend/Makefile.am @@ -223,6 +223,10 @@ taler_merchant_httpd_LDADD = \ if HAVE_DONAU taler_merchant_httpd_LDADD += \ -ldonau + +taler_merchant_httpd_SOURCES += \ + taler-merchant-httpd_private-get-donau-instances.c \ + taler-merchant-httpd_private-get-donau-instances.h endif taler_merchant_httpd_CFLAGS = \ diff --git a/src/backend/taler-merchant-httpd.c b/src/backend/taler-merchant-httpd.c @@ -97,6 +97,9 @@ #include "taler-merchant-httpd_spa.h" #include "taler-merchant-httpd_statics.h" +#ifdef HAVE_DONAU_DONAU_SERVICE_H +#include "taler-merchant-httpd_private-get-donau-instances.h" +#endif /** * Fixme: document. @@ -1337,6 +1340,14 @@ url_handler (void *cls, .have_id_segment = true, .handler = &TMH_private_patch_token_family_SLUG, }, + #ifdef HAVE_DONAU_DONAU_SERVICE_H + /* GET /donau */ + { + .url_prefix = "/donau", + .method = MHD_HTTP_METHOD_GET, + .handler = &TMH_private_get_donau_instances + }, + #endif { .url_prefix = NULL } diff --git a/src/backend/taler-merchant-httpd_private-get-donau-instances.c b/src/backend/taler-merchant-httpd_private-get-donau-instances.c @@ -0,0 +1,93 @@ +/* + 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_get-donau-instances.c + * @brief implementation of GET /donau + * @author Bohdan Potuzhnyi + * @author Vlada Svirsh + */ +#include "platform.h" +#include <jansson.h> +#include <taler/taler_json_lib.h> +#include <taler/taler_dbevents.h> +#include "taler_merchant_donau.h" +#include "taler_merchant_service.h" +#include "taler-merchant-httpd_private-get-donau-instances.h" + + +/** + * 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 + */ +static void +add_donau_instance_to_json (json_t *json_instances, const struct TALER_MERCHANTDB_DonauInstance *di) +{ + 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->eddsa_pub.q_y), + 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) + ); + + GNUNET_assert (0 == json_array_append_new (json_instances, instance)); +} + +/** + * Handle a GET "/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_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 */ + 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 */ + } + + 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); + } + + /* 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 */ diff --git a/src/backend/taler-merchant-httpd_private-get-donau-instances.h b/src/backend/taler-merchant-httpd_private-get-donau-instances.h @@ -0,0 +1,43 @@ +/* + 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_get-donau-instances.h + * @brief implementation of GET /donau + * @author Bohdan Potuzhnyi + * @author Vlada Svirsh + */ + +#ifndef TALER_MERCHANT_HTTPD_GET_DONAU_INSTANCES_H +#define TALER_MERCHANT_HTTPD_GET_DONAU_INSTANCES_H + +#include <microhttpd.h> +#include "taler-merchant-httpd.h" + +/** + * Handle a GET "/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_get_donau_instances (const struct TMH_RequestHandler *rh, + struct MHD_Connection *connection, + struct TMH_HandlerContext *hc); + +#endif + diff --git a/src/backenddb/Makefile.am b/src/backenddb/Makefile.am @@ -195,13 +195,18 @@ libtaler_plugin_merchantdb_postgres_la_SOURCES = \ pg_insert_spent_token.h pg_insert_spent_token.c \ pg_insert_issued_token.h pg_insert_issued_token.c \ pg_lookup_spent_tokens_by_order.h pg_lookup_spent_tokens_by_order.c \ + plugin_merchantdb_postgres.c \ + pg_helper.h pg_helper.c + +if HAVE_DONAU +libtaler_plugin_merchantdb_postgres_la_SOURCES += \ pg_lookup_donau_keys.h pg_lookup_donau_keys.c \ pg_upsert_donau_keys.h pg_upsert_donau_keys.c \ pg_insert_donau_instance.h pg_insert_donau_instance.c \ pg_select_donau_instance.h pg_select_donau_instance.c \ - pg_delete_donau_instance.h pg_delete_donau_instance.c \ - plugin_merchantdb_postgres.c \ - pg_helper.h pg_helper.c + pg_delete_donau_instance.h pg_delete_donau_instance.c +endif + libtaler_plugin_merchantdb_postgres_la_LIBADD = \ $(LTLIBINTL) libtaler_plugin_merchantdb_postgres_la_LDFLAGS = \ diff --git a/src/include/taler_merchant_donau.h b/src/include/taler_merchant_donau.h @@ -25,6 +25,7 @@ #include <taler/taler_util.h> #include <taler/taler_error_codes.h> #include <taler/taler_exchange_service.h> +#include <donau/donau_util.h> struct TALER_MERCHANT_DONAU_Charity { @@ -64,19 +65,57 @@ struct TALER_MERCHANT_DONAU_Charity uint64_t charity_id; }; + /** * Structure to hold Donau instance details from the database. */ struct TALER_MERCHANTDB_DonauInstance { + /** + * The URL for the Donau instance. + */ char *donau_url; + + /** + * The name of the charity associated with the Donau instance. + */ char *charity_name; + + /** + * Pointer to the public key of the charity, used for cryptographic operations. + * This is represented as an EDDSA public key structure. + */ struct DONAU_CharityPublicKeyP *charity_pub_key; + + /** + * A unique identifier for the charity in the Donau instance. + */ uint64_t charity_id; + + /** + * The maximum allowable amount for donations to this charity in the current year. + * This is tracked for regulatory or internal business constraints. + */ struct TALER_Amount charity_max_per_year; + + /** + * The total amount of donations received by the charity in the current year. + * This field helps track progress toward the yearly donation limit. + */ struct TALER_Amount charity_receipts_to_date; + + /** + * The current year being tracked for donations. + * This is used to differentiate donation data between years. + */ int64_t current_year; + + /** + * A JSON object containing key information specific to the Donau instance, + * such as cryptographic keys or other relevant details. + */ json_t *donau_keys_json; }; + #endif \ No newline at end of file