aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2024-03-03 11:53:52 +0100
committerChristian Grothoff <christian@grothoff.org>2024-03-03 11:53:52 +0100
commit3c9d0e7b78014d448d7be0bbee3c1e83e9baa473 (patch)
treecbbac337ab7ba01858c04c5b9dbb2e62c09f5073
parented0a15461984c963d25478d820feb2827f7886a1 (diff)
implement #8357
-rw-r--r--configure.ac25
m---------contrib/wallet-core0
m---------doc/prebuilt0
-rw-r--r--src/backend/taler-merchant-httpd_get-orders-ID.c32
-rw-r--r--src/backend/taler-merchant-httpd_private-get-otp-devices-ID.c29
-rw-r--r--src/include/taler_merchant_service.h17
-rw-r--r--src/lib/Makefile.am2
-rw-r--r--src/lib/merchant_api_get_otp_device.c14
-rw-r--r--src/testing/testing_api_cmd_get_otp_device.c23
9 files changed, 87 insertions, 55 deletions
diff --git a/configure.ac b/configure.ac
index c5cc912a..fda84abf 100644
--- a/configure.ac
+++ b/configure.ac
@@ -253,6 +253,31 @@ AS_IF([test $libtalerutil != 1],
*** https://taler.net
*** ]])])
+
+libtalermhd=0
+AC_MSG_CHECKING([for libtalermhd])
+AC_ARG_WITH(exchange,
+ [AS_HELP_STRING([--with-exchange=PFX], [base of Taler EXCHANGE installation])],
+ [AC_MSG_RESULT([given as $with_exchange])],
+ [AC_MSG_RESULT(not given)
+ with_exchange=yes])
+AS_CASE([$with_exchange],
+ [yes], [],
+ [no], [AC_MSG_ERROR([--with-exchange is required])],
+ [LDFLAGS="-L$with_exchange/lib $LDFLAGS"
+ CPPFLAGS="-I$with_exchange/include $CPPFLAGS $POSTGRESQL_CPPFLAGS"])
+
+AC_CHECK_HEADERS([taler/taler_mhd_lib.h],
+ [AC_CHECK_LIB([talermhd], [TALER_MHD_parse_request_arg_amount], libtalermhd=1)])
+AM_CONDITIONAL(HAVE_TALERMHD, test x$libtalermhd = x1)
+AS_IF([test $libtalermhd != 1],
+ [AC_MSG_ERROR([[
+***
+*** You need libtalermhd >= 0.9.4a to build this program.
+*** This library is part of the GNU Taler exchange, available at
+*** https://taler.net
+*** ]])])
+
libtalerjson=0
AC_CHECK_HEADERS([taler/taler_json_lib.h],
[AC_CHECK_LIB([talerjson], [TALER_JSON_spec_otp_type], libtalerjson=1)])
diff --git a/contrib/wallet-core b/contrib/wallet-core
-Subproject ae088de54c086613a52cd6dd8d88f6535634c42
+Subproject 286b4a1ade68c0cc0dfbb2ff876364538020fd0
diff --git a/doc/prebuilt b/doc/prebuilt
-Subproject 300a469342ba879b16ff93aaaf170fa1b88e75f
+Subproject 60ccf04bb3579c249a899c4ae88e120acda13c8
diff --git a/src/backend/taler-merchant-httpd_get-orders-ID.c b/src/backend/taler-merchant-httpd_get-orders-ID.c
index 6b7bbb9f..53136628 100644
--- a/src/backend/taler-merchant-httpd_get-orders-ID.c
+++ b/src/backend/taler-merchant-httpd_get-orders-ID.c
@@ -1588,31 +1588,15 @@ TMH_get_orders_ID (const struct TMH_RequestHandler *rh,
"Awaiting refund obtained\n");
}
+ TALER_MHD_parse_request_amount (connection,
+ "refund",
+ &god->sc.refund_expected);
+ if (TALER_amount_is_valid (&god->sc.refund_expected))
{
- const char *min_refund;
-
- min_refund = MHD_lookup_connection_value (connection,
- MHD_GET_ARGUMENT_KIND,
- "refund");
- if (NULL != min_refund)
- {
- if ( (GNUNET_OK !=
- TALER_string_to_amount (min_refund,
- &god->sc.refund_expected)) ||
- (0 != strcasecmp (god->sc.refund_expected.currency,
- TMH_currency) ) )
- {
- GNUNET_break_op (0);
- return TALER_MHD_reply_with_error (connection,
- MHD_HTTP_BAD_REQUEST,
- TALER_EC_GENERIC_PARAMETER_MALFORMED,
- "refund");
- }
- god->sc.awaiting_refund = true;
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Awaiting minimum refund of %s\n",
- min_refund);
- }
+ god->sc.awaiting_refund = true;
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Awaiting minimum refund of %s\n",
+ TALER_amount2s (&god->sc.refund_expected));
}
TALER_MHD_parse_request_timeout (connection,
&god->sc.long_poll_timeout);
diff --git a/src/backend/taler-merchant-httpd_private-get-otp-devices-ID.c b/src/backend/taler-merchant-httpd_private-get-otp-devices-ID.c
index e109f01f..63f3f43d 100644
--- a/src/backend/taler-merchant-httpd_private-get-otp-devices-ID.c
+++ b/src/backend/taler-merchant-httpd_private-get-otp-devices-ID.c
@@ -1,6 +1,6 @@
/*
This file is part of TALER
- (C) 2022 Taler Systems SA
+ (C) 2022-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
@@ -39,7 +39,21 @@ TMH_private_get_otp_devices_ID (const struct TMH_RequestHandler *rh,
struct TMH_MerchantInstance *mi = hc->instance;
struct TALER_MERCHANTDB_OtpDeviceDetails tp = { 0 };
enum GNUNET_DB_QueryStatus qs;
+ uint64_t faketime_s
+ = GNUNET_TIME_timestamp_to_s (GNUNET_TIME_timestamp_get ());
+ struct GNUNET_TIME_Timestamp my_time;
+ struct TALER_Amount price;
+ TALER_MHD_parse_request_number (connection,
+ "faketime",
+ &faketime_s);
+ memset (&price,
+ 0,
+ sizeof (price));
+ TALER_MHD_parse_request_amount (connection,
+ "price",
+ &price);
+ my_time = GNUNET_TIME_timestamp_from_s (faketime_s);
GNUNET_assert (NULL != mi);
qs = TMH_db->select_otp (TMH_db->cls,
mi->settings.id,
@@ -62,17 +76,30 @@ TMH_private_get_otp_devices_ID (const struct TMH_RequestHandler *rh,
}
{
MHD_RESULT ret;
+ char *pos_confirmation;
+ pos_confirmation = (NULL == tp.otp_key)
+ ? NULL
+ : TALER_build_pos_confirmation (tp.otp_key,
+ tp.otp_algorithm,
+ &price,
+ my_time);
/* Note: we deliberately (by design) do not return the otp_key */
ret = TALER_MHD_REPLY_JSON_PACK (
connection,
MHD_HTTP_OK,
GNUNET_JSON_pack_string ("device_description",
tp.otp_description),
+ GNUNET_JSON_pack_allow_null (
+ GNUNET_JSON_pack_string ("otp_code",
+ pos_confirmation)),
+ GNUNET_JSON_pack_uint64 ("otp_timestamp",
+ faketime_s),
GNUNET_JSON_pack_uint64 ("otp_algorithm",
tp.otp_algorithm),
GNUNET_JSON_pack_uint64 ("otp_ctr",
tp.otp_ctr));
+ GNUNET_free (pos_confirmation);
GNUNET_free (tp.otp_description);
GNUNET_free (tp.otp_key);
return ret;
diff --git a/src/include/taler_merchant_service.h b/src/include/taler_merchant_service.h
index 78212d86..448b8ba4 100644
--- a/src/include/taler_merchant_service.h
+++ b/src/include/taler_merchant_service.h
@@ -34,7 +34,7 @@
/**
* Library version (in hex) for compatibility tests.
*/
-#define TALER_MERCHANT_SERVICE_VERSION 0x00090402
+#define TALER_MERCHANT_SERVICE_VERSION 0x00090403
/**
@@ -4269,9 +4269,14 @@ struct TALER_MERCHANT_OtpDeviceGetResponse
const char *otp_device_description;
/**
- * OTP device key.
+ * POS confirmation text with OTP codes that
+ * would be returned for a purchase over the
+ * amount given in the query for the respective
+ * time and algorithm. NULL if the confirmation
+ * could not be computed based on the query and
+ * OTP algorithm.
*/
- const char *otp_key;
+ const char *otp_code;
/**
* current counter.
@@ -4283,6 +4288,12 @@ struct TALER_MERCHANT_OtpDeviceGetResponse
*/
enum TALER_MerchantConfirmationAlgorithm otp_alg;
+ /**
+ * Timestamp in second used to compute
+ * @e otp_code.
+ */
+ uint64_t otp_timestamp_s;
+
} ok;
} details;
diff --git a/src/lib/Makefile.am b/src/lib/Makefile.am
index dc1ea4db..641ea717 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:1:0 \
+ -version-info 5:2:0 \
-no-undefined
libtalermerchant_la_SOURCES = \
diff --git a/src/lib/merchant_api_get_otp_device.c b/src/lib/merchant_api_get_otp_device.c
index 93e065af..65950af8 100644
--- a/src/lib/merchant_api_get_otp_device.c
+++ b/src/lib/merchant_api_get_otp_device.c
@@ -74,8 +74,8 @@ struct TALER_MERCHANT_OtpDeviceGetHandle
*/
static void
handle_get_otp_device_finished (void *cls,
- long response_code,
- const void *response)
+ long response_code,
+ const void *response)
{
struct TALER_MERCHANT_OtpDeviceGetHandle *tgh = cls;
const json_t *json = response;
@@ -98,12 +98,18 @@ handle_get_otp_device_finished (void *cls,
&tgr.details.ok.otp_device_description),
GNUNET_JSON_spec_uint32 ("otp_algorithm",
&alg32),
- GNUNET_JSON_spec_string ("otp_key",
- &tgr.details.ok.otp_key),
GNUNET_JSON_spec_mark_optional (
GNUNET_JSON_spec_uint64 ("otp_ctr",
&tgr.details.ok.otp_ctr),
NULL),
+ GNUNET_JSON_spec_mark_optional (
+ GNUNET_JSON_spec_uint64 ("otp_timestamp",
+ &tgr.details.ok.otp_timestamp_s),
+ NULL),
+ GNUNET_JSON_spec_mark_optional (
+ GNUNET_JSON_spec_string ("otp_code",
+ &tgr.details.ok.otp_code),
+ NULL),
GNUNET_JSON_spec_end ()
};
diff --git a/src/testing/testing_api_cmd_get_otp_device.c b/src/testing/testing_api_cmd_get_otp_device.c
index 272039af..3f086529 100644
--- a/src/testing/testing_api_cmd_get_otp_device.c
+++ b/src/testing/testing_api_cmd_get_otp_device.c
@@ -102,7 +102,7 @@ get_otp_device_cb (void *cls,
gis->otp_device_reference);
if (GNUNET_OK !=
TALER_TESTING_get_trait_otp_device_description (otp_device_cmd,
- &expected_description))
+ &expected_description))
TALER_TESTING_interpreter_fail (gis->is);
if (0 != strcmp (tgr->details.ok.otp_device_description,
expected_description))
@@ -113,27 +113,6 @@ get_otp_device_cb (void *cls,
return;
}
}
- {
- const char *expected_otp_key;
-
- if (GNUNET_OK !=
- TALER_TESTING_get_trait_otp_key (otp_device_cmd,
- &expected_otp_key))
- TALER_TESTING_interpreter_fail (gis->is);
- if ( ( (NULL == tgr->details.ok.otp_key) && (NULL != expected_otp_key)) ||
- ( (NULL != tgr->details.ok.otp_key) && (NULL == expected_otp_key)) ||
- ( (NULL != tgr->details.ok.otp_key) &&
- (0 != strcmp (tgr->details.ok.otp_key,
- expected_otp_key)) ) )
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "OtpDevice otp_key `%s' does not match `%s'\n",
- tgr->details.ok.otp_key,
- expected_otp_key);
- TALER_TESTING_interpreter_fail (gis->is);
- return;
- }
- }
break;
case MHD_HTTP_UNAUTHORIZED:
break;