merchant

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

commit 782ba61b4009e80fa1b6603d89c1578797ae8a22
parent af85f31619b4be1eed5f0575f13d26d81db37e1f
Author: Christian Grothoff <grothoff@gnunet.org>
Date:   Wed, 23 Jul 2025 17:44:33 +0200

edits with Bohdan

Diffstat:
Msrc/backend/taler-merchant-httpd_post-orders-ID-pay.c | 9+++++----
Msrc/backend/taler-merchant-httpd_private-post-orders.c | 33++++++++++++++++-----------------
Msrc/backenddb/pg_select_donau_instances_filtered.c | 18+++++++-----------
Msrc/backenddb/pg_select_donau_instances_filtered.h | 2++
4 files changed, 30 insertions(+), 32 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 @@ -749,7 +749,7 @@ struct PayContext struct DONAU_BlindedDonationUnitSignature *sigs; /** - * Number of receipts for the donations from the Donau. + * Number of receipts in @e sigs for the donations from the Donau. */ unsigned int num_sigs; @@ -1886,13 +1886,14 @@ phase_payment_notification (struct PayContext *pc) * is malformed. */ static void -signature_to_json (const size_t num_sig, - struct DONAU_BlindedDonationUnitSignature *signatures, +signature_to_json (size_t num_sig, + const struct DONAU_BlindedDonationUnitSignature *signatures, json_t *j_signatures) { for (size_t i = 0; i < num_sig; i++) { - struct DONAU_BlindedDonationUnitSignature *signature = &signatures[i]; + const struct DONAU_BlindedDonationUnitSignature *signature = &signatures[i]; + GNUNET_assert ( 0 == json_array_append ( j_signatures, diff --git a/src/backend/taler-merchant-httpd_private-post-orders.c b/src/backend/taler-merchant-httpd_private-post-orders.c @@ -78,7 +78,7 @@ * refuses a forced download. */ #define MAX_KEYS_WAIT \ - GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, 2500) + GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, 2500) /** * Generate the base URL for the given merchant instance. @@ -3225,27 +3225,22 @@ phase_merge_inventory (struct OrderContext *oc) /** * Callback function that is called for each donau instance. * It simply adds the provided donau_url to the json. + * + * @param ... */ static void add_donau_url (void *cls, - const char *donau_url, - const struct TALER_Amount *charity_max_per_year) + const char *donau_url) { struct TALER_MERCHANT_ContractOutput *output = cls; - if ( (NULL == charity_max_per_year) || - (GNUNET_OK != - TALER_amount_cmp_currency (&output->details.donation_receipt.amount, - charity_max_per_year)) ) - return; - GNUNET_array_append (output->details.donation_receipt.donau_urls, output->details.donation_receipt.donau_urls_len, GNUNET_strdup (donau_url)); } -static void +static bool add_donau_output (struct OrderContext *oc, struct TALER_MERCHANT_ContractOutput *output) { @@ -3254,19 +3249,19 @@ add_donau_output (struct OrderContext *oc, /* Invoke the database call, accumulating URLs in a JSON array */ qs = TMH_db->select_donau_instances_filtered ( TMH_db->cls, + output->details.donation_receipt.amount.currency, &add_donau_url, output); - - /* REVIEW: If no switch */ if (qs < 0) { - GNUNET_break_op (0); + GNUNET_break (0); reply_with_error (oc, MHD_HTTP_INTERNAL_SERVER_ERROR, - TALER_EC_GENERIC_CLIENT_INTERNAL_ERROR, + TALER_EC_GENERIC_DB_FETCH_FAILED, "donau url parsing db call"); - return; + return false; } + return true; } @@ -3472,8 +3467,12 @@ phase_parse_choices (struct OrderContext *oc) case TALER_MERCHANT_CONTRACT_OUTPUT_TYPE_DONATION_RECEIPT: output.details.donation_receipt.amount = choice->amount; #ifdef HAVE_DONAU_DONAU_SERVICE_H - add_donau_output (oc, - &output); + if (! add_donau_output (oc, + &output)) + { + GNUNET_break (0); + return; + } #endif GNUNET_array_append (choice->outputs, diff --git a/src/backenddb/pg_select_donau_instances_filtered.c b/src/backenddb/pg_select_donau_instances_filtered.c @@ -67,13 +67,9 @@ select_donau_instance_cb (void *cls, for (unsigned int i = 0; i < num_results; i++) { char *donau_url; - struct TALER_Amount charity_max_per_year; - struct GNUNET_PQ_ResultSpec rs[] = { GNUNET_PQ_result_spec_string ("donau_url", &donau_url), - TALER_PQ_result_spec_amount_with_currency ("charity_max_per_year", - &charity_max_per_year), GNUNET_PQ_result_spec_end }; @@ -87,8 +83,7 @@ select_donau_instance_cb (void *cls, return; } sdc->cb (sdc->cb_cls, - donau_url, - &charity_max_per_year); + donau_url); GNUNET_PQ_cleanup_result (rs); } } @@ -97,6 +92,7 @@ select_donau_instance_cb (void *cls, enum GNUNET_DB_QueryStatus TMH_PG_select_donau_instances_filtered ( void *cls, + const char *currency, TALER_MERCHANTDB_DonauInstanceFilteredCallback cb, void *cb_cls) { @@ -109,6 +105,7 @@ TMH_PG_select_donau_instances_filtered ( }; struct GNUNET_PQ_QueryParam params[] = { + GNUNET_PQ_query_param_string (currency), GNUNET_PQ_query_param_end }; enum GNUNET_DB_QueryStatus qs; @@ -117,9 +114,9 @@ TMH_PG_select_donau_instances_filtered ( PREPARE (pg, "select_donau_instances_filtered", "SELECT" - " di.donau_url" - ",di.charity_max_per_year" - " FROM merchant_donau_instances di"); + " donau_url" + " FROM merchant_donau_instances" + " WHERE (charity_max_per_year.curr)=$1"); qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn, "select_donau_instances_filtered", @@ -132,4 +129,4 @@ TMH_PG_select_donau_instances_filtered ( return GNUNET_DB_STATUS_HARD_ERROR; return qs; -} -\ No newline at end of file +} diff --git a/src/backenddb/pg_select_donau_instances_filtered.h b/src/backenddb/pg_select_donau_instances_filtered.h @@ -32,6 +32,7 @@ * Select multiple Donau instances from the database. * * @param cls the closure for the database context + * @param currency currency to filter donau instances by * @param cb callback function to call with each result * @param cb_cls closure for the callback * @return status of the PG @@ -39,6 +40,7 @@ enum GNUNET_DB_QueryStatus TMH_PG_select_donau_instances_filtered ( void *cls, + const char *currency, TALER_MERCHANTDB_DonauInstanceFilteredCallback cb, void *cb_cls);