aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Grothoff <grothoff@gnunet.org>2024-02-10 13:15:09 +0100
committerChristian Grothoff <grothoff@gnunet.org>2024-02-10 13:16:05 +0100
commita63ae8bba773b5e2371ee82c23ba1172d9465bfe (patch)
tree0516e1494fa5a0d7aeb3bcdfa5e9f57b992f2691
parent935f9b571d2b47f10a552980feecee76ebcc3593 (diff)
try to fix #8353
-rw-r--r--src/backend/taler-merchant-httpd_config.c4
-rw-r--r--src/backend/taler-merchant-httpd_get-orders-ID.c17
-rw-r--r--src/backend/taler-merchant-httpd_private-get-orders-ID.c18
-rw-r--r--src/backenddb/pg_lookup_order_by_fulfillment.c12
-rw-r--r--src/backenddb/pg_lookup_order_by_fulfillment.h2
-rw-r--r--src/backenddb/test_merchantdb.c2
-rw-r--r--src/include/taler_merchantdb_plugin.h2
-rw-r--r--src/lib/Makefile.am2
-rw-r--r--src/lib/merchant_api_get_config.c4
9 files changed, 54 insertions, 9 deletions
diff --git a/src/backend/taler-merchant-httpd_config.c b/src/backend/taler-merchant-httpd_config.c
index 784bdcf9..7a9d2324 100644
--- a/src/backend/taler-merchant-httpd_config.c
+++ b/src/backend/taler-merchant-httpd_config.c
@@ -1,6 +1,6 @@
/*
This file is part of TALER
- (C) 2019, 2020, 2021, 2023 Taler Systems SA
+ (C) 2019, 2020, 2021, 2023, 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
@@ -42,7 +42,7 @@
* #MERCHANT_PROTOCOL_CURRENT and #MERCHANT_PROTOCOL_AGE in
* merchant_api_config.c!
*/
-#define MERCHANT_PROTOCOL_VERSION "8:2:0"
+#define MERCHANT_PROTOCOL_VERSION "9:0:5"
/**
diff --git a/src/backend/taler-merchant-httpd_get-orders-ID.c b/src/backend/taler-merchant-httpd_get-orders-ID.c
index 02f2997f..13ff3fc9 100644
--- a/src/backend/taler-merchant-httpd_get-orders-ID.c
+++ b/src/backend/taler-merchant-httpd_get-orders-ID.c
@@ -162,6 +162,12 @@ struct GetOrderData
enum GNUNET_GenericReturnValue suspended;
/**
+ * Set to YES if refunded orders should be included when
+ * doing repurchase detection.
+ */
+ enum TALER_EXCHANGE_YesNoAll allow_refunded_for_repurchase;
+
+ /**
* Set to true if the client passed 'h_contract'.
*/
bool h_contract_provided;
@@ -795,6 +801,7 @@ god_cleanup (void *cls)
}
+// FIXME: this function should probably be refactored...
MHD_RESULT
TMH_get_orders_ID (const struct TMH_RequestHandler *rh,
struct MHD_Connection *connection,
@@ -827,6 +834,14 @@ TMH_get_orders_ID (const struct TMH_RequestHandler *rh,
"token",
&god->claim_token,
god->claim_token_provided);
+ if (! (TALER_arg_to_yna (connection,
+ "allow_refunded_for_repurchase",
+ TALER_EXCHANGE_YNA_NO,
+ &god->allow_refunded_for_repurchase)) )
+ return TALER_MHD_reply_with_error (connection,
+ MHD_HTTP_BAD_REQUEST,
+ TALER_EC_GENERIC_PARAMETER_MALFORMED,
+ "allow_refunded_for_repurchase");
god->session_id = MHD_lookup_connection_value (connection,
MHD_GET_ARGUMENT_KIND,
"session_id");
@@ -1227,6 +1242,8 @@ TMH_get_orders_ID (const struct TMH_RequestHandler *rh,
hc->instance->settings.id,
god->fulfillment_url,
god->session_id,
+ TALER_EXCHANGE_YNA_NO !=
+ god->allow_refunded_for_repurchase,
&already_paid_order_id);
if (qs < 0)
{
diff --git a/src/backend/taler-merchant-httpd_private-get-orders-ID.c b/src/backend/taler-merchant-httpd_private-get-orders-ID.c
index b5810174..1c850990 100644
--- a/src/backend/taler-merchant-httpd_private-get-orders-ID.c
+++ b/src/backend/taler-merchant-httpd_private-get-orders-ID.c
@@ -1,6 +1,6 @@
/*
This file is part of TALER
- (C) 2017-2023 Taler Systems SA
+ (C) 2017-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
@@ -335,6 +335,12 @@ struct GetOrderRequestContext
enum TALER_ErrorCode wire_ec;
/**
+ * Set to YES if refunded orders should be included when
+ * doing repurchase detection.
+ */
+ enum TALER_EXCHANGE_YesNoAll allow_refunded_for_repurchase;
+
+ /**
* HTTP status to return with @e wire_ec, 0 if @e wire_ec is #TALER_EC_NONE.
*/
unsigned int wire_hc;
@@ -813,6 +819,8 @@ phase_check_repurchase (struct GetOrderRequestContext *gorc)
hc->instance->settings.id,
gorc->fulfillment_url,
gorc->session_id,
+ TALER_EXCHANGE_YNA_NO !=
+ gorc->allow_refunded_for_repurchase,
&already_paid_order_id);
if (0 > qs)
{
@@ -1457,6 +1465,14 @@ TMH_private_get_orders_ID (const struct TMH_RequestHandler *rh,
gorc->session_id = MHD_lookup_connection_value (connection,
MHD_GET_ARGUMENT_KIND,
"session_id");
+ if (! (TALER_arg_to_yna (connection,
+ "allow_refunded_for_repurchase",
+ TALER_EXCHANGE_YNA_NO,
+ &gorc->allow_refunded_for_repurchase)) )
+ return TALER_MHD_reply_with_error (connection,
+ MHD_HTTP_BAD_REQUEST,
+ TALER_EC_GENERIC_PARAMETER_MALFORMED,
+ "allow_refunded_for_repurchase");
TALER_MHD_parse_request_timeout (connection,
&gorc->sc.long_poll_timeout);
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
diff --git a/src/backenddb/pg_lookup_order_by_fulfillment.c b/src/backenddb/pg_lookup_order_by_fulfillment.c
index 0e9eba4a..291bd857 100644
--- a/src/backenddb/pg_lookup_order_by_fulfillment.c
+++ b/src/backenddb/pg_lookup_order_by_fulfillment.c
@@ -30,6 +30,7 @@ TMH_PG_lookup_order_by_fulfillment (void *cls,
const char *instance_id,
const char *fulfillment_url,
const char *session_id,
+ bool allow_refunded_for_repurchase,
char **order_id)
{
struct PostgresClosure *pg = cls;
@@ -37,6 +38,7 @@ TMH_PG_lookup_order_by_fulfillment (void *cls,
GNUNET_PQ_query_param_string (instance_id),
GNUNET_PQ_query_param_string (fulfillment_url),
GNUNET_PQ_query_param_string (session_id),
+ GNUNET_PQ_query_param_bool (allow_refunded_for_repurchase),
GNUNET_PQ_query_param_end
};
struct GNUNET_PQ_ResultSpec rs[] = {
@@ -49,14 +51,18 @@ TMH_PG_lookup_order_by_fulfillment (void *cls,
PREPARE (pg,
"lookup_order_by_fulfillment",
"SELECT"
- " order_id"
- " FROM merchant_contract_terms"
+ " mct.order_id"
+ " FROM merchant_contract_terms mct"
+ " LEFT JOIN merchant_refunds mref"
+ " USING (order_serial)"
" WHERE fulfillment_url=$2"
" AND session_id=$3"
" AND merchant_serial="
" (SELECT merchant_serial"
" FROM merchant_instances"
- " WHERE merchant_id=$1)");
+ " WHERE merchant_id=$1)"
+ " AND ((CAST($4 AS BOOL)) OR"
+ " mref.refund_serial IS NULL)");
return GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
"lookup_order_by_fulfillment",
diff --git a/src/backenddb/pg_lookup_order_by_fulfillment.h b/src/backenddb/pg_lookup_order_by_fulfillment.h
index 883ff4b9..44e96756 100644
--- a/src/backenddb/pg_lookup_order_by_fulfillment.h
+++ b/src/backenddb/pg_lookup_order_by_fulfillment.h
@@ -33,6 +33,7 @@
* @param fulfillment_url URL that canonically identifies the resource
* being paid for
* @param session_id session id
+ * @param allow_refunded_for_repurchase true to include refunded orders in repurchase detection
* @param[out] order_id where to store the order ID that was used when
* paying for the resource URL
* @return transaction status
@@ -42,6 +43,7 @@ TMH_PG_lookup_order_by_fulfillment (void *cls,
const char *instance_id,
const char *fulfillment_url,
const char *session_id,
+ bool allow_refunded_for_repurchase,
char **order_id);
#endif
diff --git a/src/backenddb/test_merchantdb.c b/src/backenddb/test_merchantdb.c
index 2b9368f1..53902b3d 100644
--- a/src/backenddb/test_merchantdb.c
+++ b/src/backenddb/test_merchantdb.c
@@ -1811,6 +1811,7 @@ test_lookup_order_by_fulfillment (const struct InstanceData *instance,
instance->instance.id,
fulfillment_url,
session_id,
+ false,
&order_id))
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
@@ -2165,6 +2166,7 @@ run_test_orders (struct TestOrders_Closure *cls)
cls->instance.instance.id,
"fulfillment_url",
"test_orders_session",
+ false,
&order_id))
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
diff --git a/src/include/taler_merchantdb_plugin.h b/src/include/taler_merchantdb_plugin.h
index 1983f732..316b8678 100644
--- a/src/include/taler_merchantdb_plugin.h
+++ b/src/include/taler_merchantdb_plugin.h
@@ -2367,6 +2367,7 @@ struct TALER_MERCHANTDB_Plugin
* @param fulfillment_url URL that canonically identifies the resource
* being paid for
* @param session_id session id
+ * @param allow_refunded_for_repurchase true to include refunded orders in repurchase detection
* @param[out] order_id location to store the order ID that was used when
* paying for the resource URL
* @return transaction status
@@ -2376,6 +2377,7 @@ struct TALER_MERCHANTDB_Plugin
const char *instance_id,
const char *fulfillment_url,
const char *session_id,
+ bool allow_refunded_for_repurchase,
char **order_id);
/**
diff --git a/src/lib/Makefile.am b/src/lib/Makefile.am
index d5a8376f..dc1ea4db 100644
--- a/src/lib/Makefile.am
+++ b/src/lib/Makefile.am
@@ -10,7 +10,7 @@ lib_LTLIBRARIES = \
libtalermerchant.la
libtalermerchant_la_LDFLAGS = \
- -version-info 5:0:0 \
+ -version-info 5:1:0 \
-no-undefined
libtalermerchant_la_SOURCES = \
diff --git a/src/lib/merchant_api_get_config.c b/src/lib/merchant_api_get_config.c
index 153bca28..f2f6ab39 100644
--- a/src/lib/merchant_api_get_config.c
+++ b/src/lib/merchant_api_get_config.c
@@ -34,12 +34,12 @@
* Which version of the Taler protocol is implemented
* by this library? Used to determine compatibility.
*/
-#define MERCHANT_PROTOCOL_CURRENT 8
+#define MERCHANT_PROTOCOL_CURRENT 9
/**
* How many configs are we backwards-compatible with?
*/
-#define MERCHANT_PROTOCOL_AGE 3
+#define MERCHANT_PROTOCOL_AGE 4
/**