commit 0c13799e32be9f24b3915bca7814a216a6ffb6f5
parent 52605d87b8ee478ebae3c3a1d272e277ca0084b8
Author: bohdan-potuzhnyi <bohdan.potuzhnyi@gmail.com>
Date: Tue, 5 Aug 2025 12:51:01 +0200
update the receipts_amount in proper way
Diffstat:
6 files changed, 180 insertions(+), 16 deletions(-)
diff --git a/src/backend/taler-merchant-httpd_post-orders-ID-pay.c b/src/backend/taler-merchant-httpd_post-orders-ID-pay.c
@@ -1881,22 +1881,6 @@ phase_payment_notification (struct PayContext *pc)
NULL,
0);
}
- if (NULL != pc->donau_receipt.donau_sigs_json)
- {
- struct GNUNET_DB_EventHeaderP es = {
- .size = htons (sizeof (es)),
- .type = htons (TALER_DBEVENT_MERCHANT_DONAU_CHARITY_ID)
- };
- uint64_t serial_net = GNUNET_htonll (
- pc->parse_wallet_data.donau_instance_serial);
-
- TMH_db->event_notify (
- TMH_db->cls,
- &es,
- &serial_net,
- sizeof(serial_net)
- );
- }
pc->phase = PP_SUCCESS_RESPONSE;
}
@@ -2058,6 +2042,35 @@ phase_final_output_token_processing (struct PayContext *pc)
for (retry = 0; retry < MAX_RETRIES; retry++)
{
+#ifdef HAVE_DONAU_DONAU_SERVICE_H
+ if (pc->parse_wallet_data.num_bkps > 0)
+ {
+ qs = TMH_db->update_donau_instance_receipts_amount (
+ TMH_db->cls,
+ &pc->parse_wallet_data.donau_instance_serial,
+ &pc->parse_wallet_data.charity_receipts_to_date);
+
+ if (GNUNET_DB_STATUS_SOFT_ERROR == qs)
+ {
+ TMH_db->rollback (TMH_db->cls);
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Retrying update of Donau instance receipts amount");
+ continue;
+ }
+ if (0 >= qs)
+ {
+ TMH_db->rollback (TMH_db->cls);
+ pay_end (pc,
+ TALER_MHD_reply_with_error (
+ pc->connection,
+ MHD_HTTP_INTERNAL_SERVER_ERROR,
+ TALER_EC_GENERIC_DB_STORE_FAILED,
+ "update donau instance receipts amount"));
+ return;
+ }
+ }
+#endif /* HAVE_DONAU_DONAU_SERVICE_H*/
+
for (unsigned int i = 0;
i < pc->validate_tokens.output_tokens_len;
i++)
@@ -3453,6 +3466,36 @@ handle_output_donation_receipt (
"donation amount mismatch"));
return GNUNET_NO;
}
+ {
+ struct TALER_Amount receipts_to_date;
+ if (0 >
+ TALER_amount_add (&receipts_to_date,
+ &pc->parse_wallet_data.charity_receipts_to_date,
+ wallet_amount))
+ {
+ GNUNET_break (0);
+ pay_end (pc,
+ TALER_MHD_reply_with_error (pc->connection,
+ MHD_HTTP_INTERNAL_SERVER_ERROR,
+ TALER_EC_MERCHANT_POST_ORDERS_ID_PAY_AMOUNT_OVERFLOW,
+ "adding donation amount"));
+ return GNUNET_NO;
+ }
+
+ if (1 ==
+ TALER_amount_cmp (&receipts_to_date,
+ &pc->parse_wallet_data.charity_max_per_year))
+ {
+ GNUNET_break_op (0);
+ pay_end (pc,
+ TALER_MHD_reply_with_error (pc->connection,
+ MHD_HTTP_CONFLICT,
+ TALER_EC_MERCHANT_POST_ORDERS_ID_PAY_DONATION_AMOUNT_MISMATCH,
+ "donation limit exceeded"));
+ return GNUNET_NO;
+ }
+ pc->parse_wallet_data.charity_receipts_to_date = receipts_to_date;
+ }
return GNUNET_OK;
#endif /* HAVE_DONAU_DONAU_SERVICE_H */
}
diff --git a/src/backenddb/Makefile.am b/src/backenddb/Makefile.am
@@ -200,6 +200,7 @@ libtaler_plugin_merchantdb_postgres_la_SOURCES = \
pg_update_category.h pg_update_category.c \
pg_update_contract_terms.h pg_update_contract_terms.c \
pg_update_deposit_confirmation_status.h pg_update_deposit_confirmation_status.c \
+ pg_update_donau_instance_receipts_amount.h pg_update_donau_instance_receipts_amount.c \
pg_update_instance.h pg_update_instance.c \
pg_update_instance_auth.h pg_update_instance_auth.c \
pg_update_otp.h pg_update_otp.c \
diff --git a/src/backenddb/pg_update_donau_instance_receipts_amount.c b/src/backenddb/pg_update_donau_instance_receipts_amount.c
@@ -0,0 +1,56 @@
+/*
+ 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 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 backenddb/pg_update_donau_instance_receipts_amount.c
+ * @brief Implementation of the update_donau_instance_receipts_amount
+ * function for Postgres
+ * @author Bohdan Potuzhnyi
+ * @author Vlada Svirsh
+ */
+#include "platform.h"
+#include <taler/taler_error_codes.h>
+#include <taler/taler_dbevents.h>
+#include <taler/taler_pq_lib.h>
+#include "donau/donau_service.h"
+#include "pg_update_donau_instance_receipts_amount.h"
+#include "pg_helper.h"
+
+enum GNUNET_DB_QueryStatus
+TMH_PG_update_donau_instance_receipts_amount (
+ void *cls,
+ uint64_t *donau_instances_serial,
+ const struct TALER_Amount *new_amount)
+{
+ struct PostgresClosure *pg = cls;
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_uint64 (donau_instances_serial),
+ TALER_PQ_query_param_amount_with_currency (pg->conn,
+ new_amount),
+ GNUNET_PQ_query_param_end
+ };
+
+ check_connection (pg);
+
+ PREPARE (pg,
+ "update_donau_instance_receipts",
+ "UPDATE merchant_donau_instances "
+ "SET charity_receipts_to_date = $2 "
+ "WHERE donau_instances_serial = $1;");
+
+ return GNUNET_PQ_eval_prepared_non_select (pg->conn,
+ "update_donau_instance_receipts",
+ params);
+}
+\ No newline at end of file
diff --git a/src/backenddb/pg_update_donau_instance_receipts_amount.h b/src/backenddb/pg_update_donau_instance_receipts_amount.h
@@ -0,0 +1,44 @@
+/*
+ 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 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 backenddb/pg_update_donau_instance_receipts_amount.h
+ * @brief implementation of the update_donau_instance function for Postgres
+ * @author Bohdan Potuzhnyi
+ * @author Vlada Svirsh
+ */
+#ifndef PG_UPDATE_DONAU_INSTANCE_RECEIPTS_AMOUNT_H
+#define PG_UPDATE_DONAU_INSTANCE_RECEIPTS_AMOUNT_H
+
+#include <taler/taler_util.h>
+#include <taler/taler_json_lib.h>
+#include "taler_merchantdb_plugin.h"
+#include "donau/donau_service.h"
+
+/**
+ * Update information about a Donau charity instance.
+ *
+ * @param cls closure
+ * @param donau_instances_serial serial of the Donau instance to update
+ * @param new_amount new amount to set for the Donau instance receipts to date
+ * @return transaction status code
+ */
+enum GNUNET_DB_QueryStatus
+TMH_PG_update_donau_instance_receipts_amount (
+ void *cls,
+ uint64_t *donau_instances_serial,
+ const struct TALER_Amount *new_amount);
+
+#endif
diff --git a/src/backenddb/plugin_merchantdb_postgres.c b/src/backenddb/plugin_merchantdb_postgres.c
@@ -163,6 +163,7 @@
#include "pg_lookup_statistics_amount_by_interval.h"
#include "pg_lookup_statistics_counter_by_bucket.h"
#include "pg_lookup_statistics_counter_by_interval.h"
+#include "pg_update_donau_instance_receipts_amount.h"
#ifdef HAVE_DONAU_DONAU_SERVICE_H
#include "donau/donau_service.h"
@@ -655,6 +656,8 @@ libtaler_plugin_merchantdb_postgres_init (void *cls)
= &TMH_PG_lookup_token_family_key;
plugin->update_deposit_confirmation_status
= &TMH_PG_update_deposit_confirmation_status;
+ plugin->update_donau_instance_receipts_amount
+ = &TMH_PG_update_donau_instance_receipts_amount;
plugin->insert_spent_token
= &TMH_PG_insert_spent_token;
plugin->insert_issued_token
diff --git a/src/include/taler_merchantdb_plugin.h b/src/include/taler_merchantdb_plugin.h
@@ -4157,6 +4157,22 @@ struct TALER_MERCHANTDB_Plugin
const char *last_detail);
+ /**
+ * Update the amount of receipts for a Donau instance.
+ *
+ * @param cls closure
+ * @param donau_instances_serial serial number of the Donau instance
+ * @param new_amount new receipts_to_date amount
+ * @return database result code
+ */
+ enum GNUNET_DB_QueryStatus
+ (*update_donau_instance_receipts_amount)(
+ void *cls,
+ uint64_t *donau_instances_serial,
+ const struct TALER_Amount *new_amount
+ );
+
+
#ifdef HAVE_DONAU_DONAU_SERVICE_H
/**
* Upsert Donau keys into the database.