commit 00e974f6aeee3373c7b39d3ebc68f45fc1349d85
parent a951899df7ccf5c55753cb1e9a80648d4a1426be
Author: bohdan-potuzhnyi <bohdan.potuzhnyi@gmail.com>
Date: Thu, 13 Feb 2025 18:31:46 +0100
theoretically it needs to work
Diffstat:
2 files changed, 78 insertions(+), 28 deletions(-)
diff --git a/src/backend/taler-merchant-httpd_private-post-orders.c b/src/backend/taler-merchant-httpd_private-post-orders.c
@@ -635,14 +635,10 @@ struct OrderContext
ORDER_PHASE_PARSE_REQUEST,
ORDER_PHASE_PARSE_ORDER,
ORDER_PHASE_PARSE_CHOICES,
-#ifdef HAVE_DONAU_DONAU_SERVICE_H
- ORDER_PHASE_PARSE_DONAU,
-#endif
ORDER_PHASE_MERGE_INVENTORY,
ORDER_PHASE_ADD_PAYMENT_DETAILS,
ORDER_PHASE_SET_EXCHANGES,
ORDER_PHASE_SET_MAX_FEE,
- ORDER_PHASE_ADD_DONAU,
ORDER_PHASE_SERIALIZE_ORDER,
ORDER_PHASE_SALT_FORGETTABLE,
ORDER_PHASE_CHECK_CONTRACT,
@@ -2212,12 +2208,6 @@ set_max_fee (struct OrderContext *oc)
oc->phase++;
}
-static void
-add_donau_urls (struct OrderContext *oc)
-{
- oc->phase++;
-}
-
/**
* Exchange `/keys` processing is done, resume handling
* the order.
@@ -3346,13 +3336,79 @@ parse_order (struct OrderContext *oc)
#ifdef HAVE_DONAU_DONAU_SERVICE_H
+/*
+ * Callback function that is called for each donau instance.
+ * It simply adds the provided donau_url to the json.
+ */
static void
-parse_donau_instances (struct OrderContext *oc)
+add_donau_url (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)
{
- /* FIXME-#9059: not yet implemented! */
- return;
+ json_t *json_instances = cls;
+ GNUNET_assert(0 == json_array_append_new(json_instances, json_string(donau_url)));
}
+static void
+parse_donau_instances (struct OrderContext *oc,
+ struct TALER_MERCHANT_ContractOutput *output)
+{
+ json_t *json_donau_instances = json_array();
+ enum GNUNET_DB_QueryStatus qs;
+
+ /* Initialize the donation_receipt URL fields */
+ output->details.donation_receipt.donau_urls = NULL;
+ output->details.donation_receipt.donau_urls_len = 0;
+
+ /* Invoke the database call, accumulating URLs in a JSON array */
+ qs = TMH_db->select_donau_instance(TMH_db->cls,
+ &add_donau_url,
+ json_donau_instances);
+
+ if (qs < 0)
+ {
+ json_decref(json_donau_instances);
+ GNUNET_break_op (0);
+ reply_with_error (oc,
+ MHD_HTTP_INTERNAL_SERVER_ERROR,
+ TALER_EC_GENERIC_CLIENT_INTERNAL_ERROR,
+ "donau url parsing db call");
+ return;
+ }
+
+ /* Convert the JSON array of strings into a C array of URLs */
+ size_t num_instances = json_array_size(json_donau_instances);
+ if (num_instances > 0)
+ {
+ output->details.donation_receipt.donau_urls = malloc(num_instances * sizeof(char *));
+ if (!output->details.donation_receipt.donau_urls)
+ {
+ json_decref(json_donau_instances);
+ GNUNET_break_op (0);
+ reply_with_error (oc,
+ MHD_HTTP_INTERNAL_SERVER_ERROR,
+ TALER_EC_GENERIC_CLIENT_INTERNAL_ERROR,
+ "donau url parsing allocating memory");
+ return;
+ }
+ output->details.donation_receipt.donau_urls_len = num_instances;
+
+ for (size_t i = 0; i < num_instances; i++)
+ {
+ json_t *url_json = json_array_get(json_donau_instances, i);
+ const char *url_str = json_string_value(url_json);
+ output->details.donation_receipt.donau_urls[i] = strdup(url_str);
+ }
+ }
+
+ json_decref(json_donau_instances);
+}
#endif
@@ -3545,7 +3601,15 @@ parse_choices (struct OrderContext *oc)
GNUNET_assert (0);
break;
case TALER_MERCHANT_CONTRACT_OUTPUT_TYPE_DONATION_RECEIPT:
- GNUNET_break (0); /* FIXME-#9059: not yet implemented! */
+ /* FIXME-#9059: not yet implemented! */
+ #ifdef HAVE_DONAU_DONAU_SERVICE_H
+ parse_donau_instances (oc, &output);
+ #else
+ //TODO: Is this all that needs to be done?
+ /* This is the case when the DONAU was not configured, yet DONAU order is made*/
+ output.details.donation_receipt.donau_urls = NULL;
+ output.details.donation_receipt.donau_urls_len = 0;
+ #endif
break;
case TALER_MERCHANT_CONTRACT_OUTPUT_TYPE_TOKEN:
/* Ignore inputs tokens with 'count' field set to 0 */
@@ -3986,11 +4050,6 @@ TMH_private_post_orders (
case ORDER_PHASE_PARSE_CHOICES:
parse_choices (oc);
break;
-#ifdef HAVE_DONAU_DONAU_SERVICE_H
- case ORDER_PHASE_PARSE_DONAU:
- parse_donau_instances (oc);
- break;
-#endif
case ORDER_PHASE_MERGE_INVENTORY:
merge_inventory (oc);
break;
@@ -4004,9 +4063,6 @@ TMH_private_post_orders (
case ORDER_PHASE_SET_MAX_FEE:
set_max_fee (oc);
break;
- case ORDER_PHASE_ADD_DONAU:
- add_donau_urls (oc);
- break;
case ORDER_PHASE_SERIALIZE_ORDER:
serialize_order (oc);
break;
diff --git a/src/include/taler_merchant_util.h b/src/include/taler_merchant_util.h
@@ -213,12 +213,6 @@ struct TALER_MERCHANT_ContractOutput
struct TALER_Amount amount;
/**
- * TODO: Check if this block is possible to operate without default placeholder...
- * Is the donation receipt required?
- */
- bool receipt_required;
-
- /**
* Base URLs of the donation authorities that will issue the tax receipt.
*/
const char **donau_urls;