aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorpriscilla <priscilla.huang@efrei.net>2023-01-12 06:41:58 -0500
committerpriscilla <priscilla.huang@efrei.net>2023-01-12 06:41:58 -0500
commit71c2621fbd1077c8664c04cacd1b1a1502c5c90f (patch)
treeca66e6ecbcf43b94bf97584eadcbe8a320cfe451 /src
parentf129942b7c58058c495f99491fc34f85c5ba05a7 (diff)
update
Diffstat (limited to 'src')
-rw-r--r--src/backend/taler-merchant-httpd_private-delete-pending-webhooks-ID.c78
-rw-r--r--src/backend/taler-merchant-httpd_private-delete-pending-webhooks-ID.h41
-rw-r--r--src/backend/taler-merchant-httpd_private-get-pending-webhooks-ID.c91
-rw-r--r--src/backend/taler-merchant-httpd_private-get-pending-webhooks-ID.h41
-rw-r--r--src/backend/taler-merchant-httpd_private-get-pending-webhooks.c78
-rw-r--r--src/backend/taler-merchant-httpd_private-get-templates.c4
-rw-r--r--src/backend/taler-merchant-httpd_private-get-webhooks.c8
-rw-r--r--src/backend/taler-merchant-httpd_private-patch-pending-webhooks-ID.h43
-rw-r--r--src/backenddb/plugin_merchantdb_postgres.c12
9 files changed, 386 insertions, 10 deletions
diff --git a/src/backend/taler-merchant-httpd_private-delete-pending-webhooks-ID.c b/src/backend/taler-merchant-httpd_private-delete-pending-webhooks-ID.c
new file mode 100644
index 00000000..0e6a3bfb
--- /dev/null
+++ b/src/backend/taler-merchant-httpd_private-delete-pending-webhooks-ID.c
@@ -0,0 +1,78 @@
+/*
+ This file is part of TALER
+ (C) 2023 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
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+*/
+/**
+ * @file taler-merchant-httpd_private-delete-pending-webhooks-ID.c
+ * @brief implement DELETE /pending webhooks/$ID
+ * @author Priscilla HUANG
+ */
+#include "platform.h"
+#include "taler-merchant-httpd_private-delete-pending-webhooks-ID.h"
+#include <taler/taler_json_lib.h>
+
+
+/**
+ * Handle a DELETE "/pending-webhooks/$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_delete_pending_webhooks_ID (const struct TMH_RequestHandler *rh,
+ struct MHD_Connection *connection,
+ struct TMH_HandlerContext *hc)
+{
+ struct TMH_MerchantInstance *mi = hc->instance;
+ enum GNUNET_DB_QueryStatus qs;
+
+ (void) rh;
+ GNUNET_assert (NULL != mi);
+ GNUNET_assert (NULL != hc->infix);
+ qs = TMH_db->delete_pending_webhook (TMH_db->cls,
+ mi->settings.id,
+ hc->infix);
+ switch (qs)
+ {
+ case GNUNET_DB_STATUS_HARD_ERROR:
+ return TALER_MHD_reply_with_error (connection,
+ MHD_HTTP_INTERNAL_SERVER_ERROR,
+ TALER_EC_GENERIC_DB_STORE_FAILED,
+ "delete_pending_webhook");
+ case GNUNET_DB_STATUS_SOFT_ERROR:
+ GNUNET_break (0);
+ return TALER_MHD_reply_with_error (connection,
+ MHD_HTTP_INTERNAL_SERVER_ERROR,
+ TALER_EC_GENERIC_INTERNAL_INVARIANT_FAILURE,
+ "delete_pending_webhook (soft)");
+ case GNUNET_DB_STATUS_SUCCESS_NO_RESULTS:
+ return TALER_MHD_reply_with_error (connection,
+ MHD_HTTP_NOT_FOUND,
+ TALER_EC_MERCHANT_GENERIC_PENDING_WEBHOOK_UNKNOWN,
+ hc->infix);
+ case GNUNET_DB_STATUS_SUCCESS_ONE_RESULT:
+ return TALER_MHD_reply_static (connection,
+ MHD_HTTP_NO_CONTENT,
+ NULL,
+ NULL,
+ 0);
+ }
+ GNUNET_assert (0);
+ return MHD_NO;
+}
+
+
+/* end of taler-merchant-httpd_private-delete-pending-webhooks-ID.c */
diff --git a/src/backend/taler-merchant-httpd_private-delete-pending-webhooks-ID.h b/src/backend/taler-merchant-httpd_private-delete-pending-webhooks-ID.h
new file mode 100644
index 00000000..f558ce4d
--- /dev/null
+++ b/src/backend/taler-merchant-httpd_private-delete-pending-webhooks-ID.h
@@ -0,0 +1,41 @@
+/*
+ This file is part of TALER
+ (C) 2023 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
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+*/
+/**
+ * @file taler-merchant-httpd_private-delete-pending-webhooks-ID.h
+ * @brief implement DELETE /pending webhooks/$ID/
+ * @author Priscilla HUANG
+ */
+#ifndef TALER_MERCHANT_HTTPD_PRIVATE_DELETE_PENDING_WEBHOOKS_ID_H
+#define TALER_MERCHANT_HTTPD_PRIVATE_DELETE_PENDING_WEBHOOKS_ID_H
+
+#include "taler-merchant-httpd.h"
+
+
+/**
+ * Handle a DELETE "/pending webhooks/$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_delete_pending_webhooks_ID (const struct TMH_RequestHandler *rh,
+ struct MHD_Connection *connection,
+ struct TMH_HandlerContext *hc);
+
+/* end of taler-merchant-httpd_private-delete-pending-webhooks-ID.h */
+#endif
diff --git a/src/backend/taler-merchant-httpd_private-get-pending-webhooks-ID.c b/src/backend/taler-merchant-httpd_private-get-pending-webhooks-ID.c
new file mode 100644
index 00000000..7536b2f2
--- /dev/null
+++ b/src/backend/taler-merchant-httpd_private-get-pending-webhooks-ID.c
@@ -0,0 +1,91 @@
+/*
+ This file is part of TALER
+ (C) 2023 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
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+*/
+/**
+ * @file taler-merchant-httpd_private-get-pending-webhooks-ID.c
+ * @brief implement GET /pending webhooks/$ID
+ * @author Priscilla HUANG
+ */
+#include "platform.h"
+#include "taler-merchant-httpd_private-get-pending-webhooks-ID.h"
+#include <taler/taler_json_lib.h>
+
+
+/**
+ * Handle a GET "/pending webhooks/$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_pending_webhooks_ID (const struct TMH_RequestHandler *rh,
+ struct MHD_Connection *connection,
+ struct TMH_HandlerContext *hc)
+{
+ struct TMH_MerchantInstance *mi = hc->instance;
+ struct TALER_MERCHANTDB_PendingWebhookDetails pwb = { 0 };
+ enum GNUNET_DB_QueryStatus qs;
+
+ GNUNET_assert (NULL != mi);
+ qs = TMH_db->lookup_pending_webhook (TMH_db->cls,
+ mi->settings.id,
+ hc->infix,
+ &pwb);
+ 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_pending_webhook");
+ }
+ if (0 == qs)
+ {
+ return TALER_MHD_reply_with_error (connection,
+ MHD_HTTP_NOT_FOUND,
+ TALER_EC_MERCHANT_GENERIC_PENDING_WEBHOOK_UNKNOWN,
+ hc->infix);
+ }
+ {
+ MHD_RESULT ret;
+
+ ret = TALER_MHD_REPLY_JSON_PACK (
+ connection,
+ MHD_HTTP_OK,
+ GNUNET_JSON_pack_absolute ("next_attempt",
+ pwb.next_attempt),
+ GNUNET_JSON_pack_uint32 ("retries",
+ pwb.retries),
+ GNUNET_JSON_pack_string ("url",
+ pwb.url),
+ GNUNET_JSON_pack_string ("http_method",
+ pwb.http_method),
+ GNUNET_JSON_pack_string ("header",
+ pwb.header),
+ GNUNET_JSON_pack_string ("body"
+ pwb.body));
+ GNUNET_free (pwb.url);
+ GNUNET_free (pwb.http_method);
+ GNUNET_free (pwb.header_template);
+ GNUNET_free (pwb.body_template);
+
+ return ret;
+ }
+}
+
+
+/* end of taler-merchant-httpd_private-get-webhooks-ID.c */
diff --git a/src/backend/taler-merchant-httpd_private-get-pending-webhooks-ID.h b/src/backend/taler-merchant-httpd_private-get-pending-webhooks-ID.h
new file mode 100644
index 00000000..6edd709e
--- /dev/null
+++ b/src/backend/taler-merchant-httpd_private-get-pending-webhooks-ID.h
@@ -0,0 +1,41 @@
+/*
+ This file is part of TALER
+ (C) 2023 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
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+*/
+/**
+ * @file taler-merchant-httpd_private-get-pending-webhooks-ID.h
+ * @brief implement GET /pending webhooks/$ID/
+ * @author Priscilla HUANG
+ */
+#ifndef TALER_MERCHANT_HTTPD_PRIVATE_GET_PENDING_WEBHOOKS_ID_H
+#define TALER_MERCHANT_HTTPD_PRIVATE_GET_PENDING_WEBHOOKS_ID_H
+
+#include "taler-merchant-httpd.h"
+
+
+/**
+ * Handle a GET "/pending webhooks/$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_pending_webhooks_ID (const struct TMH_RequestHandler *rh,
+ struct MHD_Connection *connection,
+ struct TMH_HandlerContext *hc);
+
+/* end of taler-merchant-httpd_private-get-pending-webhooks-ID.h */
+#endif
diff --git a/src/backend/taler-merchant-httpd_private-get-pending-webhooks.c b/src/backend/taler-merchant-httpd_private-get-pending-webhooks.c
new file mode 100644
index 00000000..c6cd53e5
--- /dev/null
+++ b/src/backend/taler-merchant-httpd_private-get-pending-webhooks.c
@@ -0,0 +1,78 @@
+/*
+ This file is part of TALER
+ (C) 2023 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
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+*/
+/**
+ * @file taler-merchant-httpd_private-get-pending-webhooks.c
+ * @brief implement GET /pending webhooks
+ * @author Priscilla HUANG
+ */
+#include "platform.h"
+#include "taler-merchant-httpd_private-get-pending-webhooks.h"
+
+/**
+ * Add pending webhook details to our JSON array.
+ *
+ * @param cls a `json_t *` JSON array to build
+ * @param webhook_serial reference of the webhook
+ */
+static voidX
+add_pending_webhook (void *cls,
+ uint64_t *webhook_serial,
+ struct GNUNET_TIME_Absolute *next_attempt)
+{
+ json_t *pa = cls;
+
+ GNUNET_assert (0 ==
+ json_array_append_new (
+ pa,
+ GNUNET_JSON_PACK (
+ GNUNET_JSON_pack_uint64 ("webhook_serial",
+ webhook_serial),
+ GNUNET_JSON_pack_string ("next_attempt",
+ next_attempt))));
+}
+
+
+MHD_RESULT
+TMH_private_get_pending_webhooks (const struct TMH_RequestHandler *rh,
+ struct MHD_Connection *connection,
+ struct TMH_HandlerContext *hc)
+{
+ json_t *pa;
+ enum GNUNET_DB_QueryStatus qs;
+
+ pa = json_array ();
+ GNUNET_assert (NULL != pa);
+ qs = TMH_db->lookup_pending_webhooks (TMH_db->cls,
+ hc->instance->settings.id,
+ &add_pending_webhook,
+ pa);
+ if (0 > qs)
+ {
+ GNUNET_break (0);
+ json_decref (pa);
+ return TALER_MHD_reply_with_error (connection,
+ MHD_HTTP_INTERNAL_SERVER_ERROR,
+ TALER_EC_GENERIC_DB_FETCH_FAILED,
+ NULL);
+ }
+ return TALER_MHD_REPLY_JSON_PACK (connection,
+ MHD_HTTP_OK,
+ GNUNET_JSON_pack_array_steal ("webhooks",
+ pa));
+}
+
+
+/* end of taler-merchant-httpd_private-get-webhooks.c */
diff --git a/src/backend/taler-merchant-httpd_private-get-templates.c b/src/backend/taler-merchant-httpd_private-get-templates.c
index 43af09a2..c1d72a55 100644
--- a/src/backend/taler-merchant-httpd_private-get-templates.c
+++ b/src/backend/taler-merchant-httpd_private-get-templates.c
@@ -40,7 +40,9 @@ add_template (void *cls,
pa,
GNUNET_JSON_PACK (
GNUNET_JSON_pack_string ("template_id",
- template_id))));
+ template_id),
+ GNUNET_JSON_pack_string ("template_description",
+ template_description))));
}
diff --git a/src/backend/taler-merchant-httpd_private-get-webhooks.c b/src/backend/taler-merchant-httpd_private-get-webhooks.c
index dad39efb..2436c197 100644
--- a/src/backend/taler-merchant-httpd_private-get-webhooks.c
+++ b/src/backend/taler-merchant-httpd_private-get-webhooks.c
@@ -30,8 +30,8 @@
*/
static void
add_webhook (void *cls,
- const char *webhook_id,
- const char *event_type)
+ const char *webhook_id,
+ const char *event_type)
{
json_t *pa = cls;
@@ -40,7 +40,9 @@ add_webhook (void *cls,
pa,
GNUNET_JSON_PACK (
GNUNET_JSON_pack_string ("webhook_id",
- webhook_id))));
+ webhook_id),
+ GNUNET_JSON_pack_string ("event_type",
+ event_type))));
}
diff --git a/src/backend/taler-merchant-httpd_private-patch-pending-webhooks-ID.h b/src/backend/taler-merchant-httpd_private-patch-pending-webhooks-ID.h
new file mode 100644
index 00000000..409fec9b
--- /dev/null
+++ b/src/backend/taler-merchant-httpd_private-patch-pending-webhooks-ID.h
@@ -0,0 +1,43 @@
+/*
+ This file is part of TALER
+ (C) 2023 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 Foundation; either version 3,
+ or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public
+ License along with TALER; see the file COPYING. If not,
+ see <http://www.gnu.org/licenses/>
+*/
+
+/**
+ * @file taler-merchant-httpd_private-patch-pending-webhooks-ID.h
+ * @brief implementing PATCH /pending webhooks request handling
+ * @author Priscilla HUANG
+ */
+#ifndef TALER_MERCHANT_HTTPD_PRIVATE_PATCH_PENDING_WEBHOOKS_ID_H
+#define TALER_MERCHANT_HTTPD_PRIVATE_PATCH_PENDING_WEBHOOKS_ID_H
+#include "taler-merchant-httpd.h"
+
+
+/**
+ * PATCH configuration of an existing instance, given its configuration.
+ *
+ * @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_patch_pending_webhooks_ID (const struct TMH_RequestHandler *rh,
+ struct MHD_Connection *connection,
+ struct TMH_HandlerContext *hc);
+
+#endif
diff --git a/src/backenddb/plugin_merchantdb_postgres.c b/src/backenddb/plugin_merchantdb_postgres.c
index 312f22ee..e252c8db 100644
--- a/src/backenddb/plugin_merchantdb_postgres.c
+++ b/src/backenddb/plugin_merchantdb_postgres.c
@@ -7543,7 +7543,7 @@ postgres_lookup_pending_webhook (void *cls,
check_connection (pg);
return GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
- "lookup_webhook",
+ "lookup_pending_webhook",
params,
rs_null);
}
@@ -7567,7 +7567,7 @@ postgres_lookup_pending_webhook (void *cls,
check_connection (pg);
return GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
- "lookup_webhook",
+ "lookup_pending_webhook",
params,
rs);
}
@@ -7687,7 +7687,7 @@ postgres_lookup_pending_webhooks(void *cls,
check_connection (pg);
qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn,
- "lookup_pending_webhook",
+ "lookup_pending_webhooks",
params_null,
&lookup_pending_webhooks_cb,
&pwlc);
@@ -10447,13 +10447,13 @@ postgres_connect (void *cls)
",http_method"
",header"
",body"
- " FROM merchant_webhook"
+ " FROM merchant_pending_webhook"
" JOIN merchant_instances"
" USING (merchant_serial)"
" WHERE merchant_instances.merchant_id=$1"
" AND merchant_pending_webhook.webhook_serial=$2"),
- /* for postgres_lookup_pending_webhook() */
- GNUNET_PQ_make_prepare ("lookup_pending_webhook",
+ /* for postgres_lookup_pending_webhooks() */
+ GNUNET_PQ_make_prepare ("lookup_pending_webhooks",
"SELECT"
" webhook_serial"
",next_attempt"