summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2024-03-09 21:03:39 +0100
committerChristian Grothoff <christian@grothoff.org>2024-03-09 21:03:39 +0100
commit89c8198bbfcba44a37cb124f80a7deb1d98474c1 (patch)
tree03759bb551edbb33d99709df5d07e400ee373eb0 /src
parent72062fbe3ecc401fe74613d88b44f1bbb005f69e (diff)
downloadmerchant-89c8198bbfcba44a37cb124f80a7deb1d98474c1.tar.gz
merchant-89c8198bbfcba44a37cb124f80a7deb1d98474c1.tar.bz2
merchant-89c8198bbfcba44a37cb124f80a7deb1d98474c1.zip
implement #8608
Diffstat (limited to 'src')
-rw-r--r--src/backend/Makefile.am2
-rw-r--r--src/backend/taler-merchant-httpd.c12
-rw-r--r--src/backend/taler-merchant-httpd_config.c2
-rw-r--r--src/backend/taler-merchant-httpd_private-get-templates-ID.c35
-rw-r--r--src/backend/taler-merchant-httpd_private-get-templates-ID.h7
-rw-r--r--src/include/taler_merchant_service.h93
-rw-r--r--src/lib/Makefile.am1
-rw-r--r--src/lib/merchant_api_get_config.c4
8 files changed, 121 insertions, 35 deletions
diff --git a/src/backend/Makefile.am b/src/backend/Makefile.am
index 9ece7912..d521608d 100644
--- a/src/backend/Makefile.am
+++ b/src/backend/Makefile.am
@@ -28,6 +28,8 @@ taler_merchant_httpd_SOURCES = \
taler-merchant-httpd_exchanges.c taler-merchant-httpd_exchanges.h \
taler-merchant-httpd_get-orders-ID.c \
taler-merchant-httpd_get-orders-ID.h \
+ taler-merchant-httpd_get-templates-ID.c \
+ taler-merchant-httpd_get-templates-ID.h \
taler-merchant-httpd_helper.c \
taler-merchant-httpd_helper.h \
taler-merchant-httpd_mhd.c \
diff --git a/src/backend/taler-merchant-httpd.c b/src/backend/taler-merchant-httpd.c
index 8220f84d..7384bfc9 100644
--- a/src/backend/taler-merchant-httpd.c
+++ b/src/backend/taler-merchant-httpd.c
@@ -31,6 +31,7 @@
#include "taler-merchant-httpd_config.h"
#include "taler-merchant-httpd_exchanges.h"
#include "taler-merchant-httpd_get-orders-ID.h"
+#include "taler-merchant-httpd_get-templates-ID.h"
#include "taler-merchant-httpd_mhd.h"
#include "taler-merchant-httpd_private-delete-account-ID.h"
#include "taler-merchant-httpd_private-delete-instances-ID.h"
@@ -1268,7 +1269,6 @@ url_handler (void *cls,
.url_prefix = "/tokenfamilies/",
.method = MHD_HTTP_METHOD_GET,
.have_id_segment = true,
- .allow_deleted_instance = true,
.handler = &TMH_private_get_tokenfamilies_SLUG
},
/* DELETE /tokenfamilies/$SLUG/: */
@@ -1276,7 +1276,6 @@ url_handler (void *cls,
.url_prefix = "/tokenfamilies/",
.method = MHD_HTTP_METHOD_DELETE,
.have_id_segment = true,
- .allow_deleted_instance = true,
.handler = &TMH_private_delete_token_families_SLUG
},
/* PATCH /tokenfamilies/$SLUG/: */
@@ -1284,7 +1283,6 @@ url_handler (void *cls,
.url_prefix = "/tokenfamilies/",
.method = MHD_HTTP_METHOD_PATCH,
.have_id_segment = true,
- .allow_deleted_instance = true,
.handler = &TMH_private_patch_token_family_SLUG,
},
{
@@ -1414,12 +1412,18 @@ url_handler (void *cls,
.have_id_segment = true,
.handler = &TMH_return_static
},
+ /* GET /templates/$ID/: */
+ {
+ .url_prefix = "/templates/",
+ .method = MHD_HTTP_METHOD_GET,
+ .have_id_segment = true,
+ .handler = &TMH_get_templates_ID
+ },
/* POST /templates/$ID: */
{
.url_prefix = "/templates/",
.method = MHD_HTTP_METHOD_POST,
.have_id_segment = true,
- .allow_deleted_instance = true,
.handler = &TMH_post_using_templates_ID,
.max_upload = 1024 * 1024
},
diff --git a/src/backend/taler-merchant-httpd_config.c b/src/backend/taler-merchant-httpd_config.c
index 074c2a7e..d020985b 100644
--- a/src/backend/taler-merchant-httpd_config.c
+++ b/src/backend/taler-merchant-httpd_config.c
@@ -42,7 +42,7 @@
* #MERCHANT_PROTOCOL_CURRENT and #MERCHANT_PROTOCOL_AGE in
* merchant_api_config.c!
*/
-#define MERCHANT_PROTOCOL_VERSION "10:0:6"
+#define MERCHANT_PROTOCOL_VERSION "11:0:7"
/**
diff --git a/src/backend/taler-merchant-httpd_private-get-templates-ID.c b/src/backend/taler-merchant-httpd_private-get-templates-ID.c
index e9dfc00f..a5b05f0c 100644
--- a/src/backend/taler-merchant-httpd_private-get-templates-ID.c
+++ b/src/backend/taler-merchant-httpd_private-get-templates-ID.c
@@ -23,18 +23,11 @@
#include <taler/taler_json_lib.h>
-/**
- * Handle a GET "/templates/$ID" request.
- *
- * @param rh context of the handler
- * @param connection the MHD connection to handle
- * @param[in,out] hc context with further information about the request
- * @return MHD result code
- */
MHD_RESULT
-TMH_private_get_templates_ID (const struct TMH_RequestHandler *rh,
- struct MHD_Connection *connection,
- struct TMH_HandlerContext *hc)
+TMH_private_get_templates_ID (
+ const struct TMH_RequestHandler *rh,
+ struct MHD_Connection *connection,
+ struct TMH_HandlerContext *hc)
{
struct TMH_MerchantInstance *mi = hc->instance;
struct TALER_MERCHANTDB_TemplateDetails tp = { 0 };
@@ -48,17 +41,19 @@ TMH_private_get_templates_ID (const struct TMH_RequestHandler *rh,
if (0 > qs)
{
GNUNET_break (0);
- return TALER_MHD_reply_with_error (connection,
- MHD_HTTP_INTERNAL_SERVER_ERROR,
- TALER_EC_GENERIC_DB_FETCH_FAILED,
- "lookup_template");
+ return TALER_MHD_reply_with_error (
+ connection,
+ MHD_HTTP_INTERNAL_SERVER_ERROR,
+ TALER_EC_GENERIC_DB_FETCH_FAILED,
+ "lookup_template");
}
- if (0 == qs)
+ if (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS == qs)
{
- return TALER_MHD_reply_with_error (connection,
- MHD_HTTP_NOT_FOUND,
- TALER_EC_MERCHANT_GENERIC_TEMPLATE_UNKNOWN,
- hc->infix);
+ return TALER_MHD_reply_with_error (
+ connection,
+ MHD_HTTP_NOT_FOUND,
+ TALER_EC_MERCHANT_GENERIC_TEMPLATE_UNKNOWN,
+ hc->infix);
}
{
MHD_RESULT ret;
diff --git a/src/backend/taler-merchant-httpd_private-get-templates-ID.h b/src/backend/taler-merchant-httpd_private-get-templates-ID.h
index 384ab818..fcdd6a2e 100644
--- a/src/backend/taler-merchant-httpd_private-get-templates-ID.h
+++ b/src/backend/taler-merchant-httpd_private-get-templates-ID.h
@@ -33,9 +33,10 @@
* @return MHD result code
*/
MHD_RESULT
-TMH_private_get_templates_ID (const struct TMH_RequestHandler *rh,
- struct MHD_Connection *connection,
- struct TMH_HandlerContext *hc);
+TMH_private_get_templates_ID (
+ const struct TMH_RequestHandler *rh,
+ struct MHD_Connection *connection,
+ struct TMH_HandlerContext *hc);
/* end of taler-merchant-httpd_private-get-templates-ID.h */
#endif
diff --git a/src/include/taler_merchant_service.h b/src/include/taler_merchant_service.h
index 448b8ba4..2ed51a29 100644
--- a/src/include/taler_merchant_service.h
+++ b/src/include/taler_merchant_service.h
@@ -4598,7 +4598,7 @@ TALER_MERCHANT_templates_get_cancel (
/**
- * Handle for a GET /template/$ID operation. Gets details
+ * Handle for a GET /private/template/$ID operation. Gets details
* about a single template. Do not confused with a
* `struct TALER_MERCHANT_TemplatesGetHandle`, which
* obtains a list of all templates.
@@ -4607,7 +4607,7 @@ struct TALER_MERCHANT_TemplateGetHandle;
/**
- * Details in a response to a GET /templates request.
+ * Details in a response to a GET /private/templates/$ID request.
*/
struct TALER_MERCHANT_TemplateGetResponse
{
@@ -4650,7 +4650,7 @@ struct TALER_MERCHANT_TemplateGetResponse
/**
- * Function called with the result of the GET /template/$ID operation.
+ * Function called with the result of the GET /private/template/$ID operation.
*
* @param cls closure
* @param tgr HTTP response details
@@ -4662,7 +4662,7 @@ typedef void
/**
- * Make a GET /template/$ID request to get details about an
+ * Make a GET /private/template/$ID request to get details about an
* individual template.
*
* @param ctx the context
@@ -4682,7 +4682,7 @@ TALER_MERCHANT_template_get (
/**
- * Cancel GET /templates/$ID operation.
+ * Cancel GET /private/templates/$ID operation.
*
* @param tgh operation to cancel
*/
@@ -4692,6 +4692,89 @@ TALER_MERCHANT_template_get_cancel (
/**
+ * Handle for a (public) GET /template/$ID operation. Gets details about a
+ * single template. Do not confused with a `struct
+ * TALER_MERCHANT_TemplateGetHandle`, which is for the private API.
+ */
+struct TALER_MERCHANT_WalletTemplateGetHandle;
+
+
+/**
+ * Details in a response to a GET /templates request.
+ */
+struct TALER_MERCHANT_WalletTemplateGetResponse
+{
+ /**
+ * HTTP response details.
+ */
+ struct TALER_MERCHANT_HttpResponse hr;
+
+ /**
+ * Response details depending on the HTTP status.
+ */
+ union
+ {
+ /**
+ * Information returned if the status was #MHD_HTTP_OK.
+ */
+ struct
+ {
+
+ /**
+ * Template for the contract.
+ */
+ const json_t *template_contract;
+
+ } ok;
+
+ } details;
+
+};
+
+
+/**
+ * Function called with the result of the GET /template/$ID operation.
+ *
+ * @param cls closure
+ * @param tgr HTTP response details
+ */
+typedef void
+(*TALER_MERCHANT_WalletTemplateGetCallback)(
+ void *cls,
+ const struct TALER_MERCHANT_WalletTemplateGetResponse *tgr);
+
+
+/**
+ * Make a GET /template/$ID request to get details about an
+ * individual template.
+ *
+ * @param ctx the context
+ * @param backend_url HTTP base URL for the backend
+ * @param template_id identifier of the template to inquire about
+ * @param cb function to call with the backend's template information
+ * @param cb_cls closure for @a cb
+ * @return the request handle; NULL upon error
+ */
+struct TALER_MERCHANT_WalletTemplateGetHandle *
+TALER_MERCHANT_wallet_template_get (
+ struct GNUNET_CURL_Context *ctx,
+ const char *backend_url,
+ const char *template_id,
+ TALER_MERCHANT_WalletTemplateGetCallback cb,
+ void *cb_cls);
+
+
+/**
+ * Cancel GET /templates/$ID operation.
+ *
+ * @param tgh operation to cancel
+ */
+void
+TALER_MERCHANT_wallet_template_get_cancel (
+ struct TALER_MERCHANT_WalletTemplateGetHandle *tgh);
+
+
+/**
* Handle for a POST /templates operation.
*/
struct TALER_MERCHANT_TemplatesPostHandle;
diff --git a/src/lib/Makefile.am b/src/lib/Makefile.am
index 641ea717..04b2b089 100644
--- a/src/lib/Makefile.am
+++ b/src/lib/Makefile.am
@@ -65,6 +65,7 @@ libtalermerchant_la_SOURCES = \
merchant_api_post_using_templates.c \
merchant_api_post_webhooks.c \
merchant_api_wallet_get_order.c \
+ merchant_api_wallet_get_template.c \
merchant_api_wallet_post_order_refund.c
libtalermerchant_la_LIBADD = \
diff --git a/src/lib/merchant_api_get_config.c b/src/lib/merchant_api_get_config.c
index b8328f9e..3f1471e3 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 10
+#define MERCHANT_PROTOCOL_CURRENT 11
/**
* How many configs are we backwards-compatible with?
*/
-#define MERCHANT_PROTOCOL_AGE 5
+#define MERCHANT_PROTOCOL_AGE 6
/**