summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2021-08-25 07:58:27 +0200
committerChristian Grothoff <christian@grothoff.org>2021-08-25 07:58:27 +0200
commit5672080efcaca68ed2d301adf1673d45f7638a16 (patch)
tree12767bfb5996765f70f6b421c1179c0e56e8bc3c
parent0c78255cba8bc6ed6c8042995292f02d4980e714 (diff)
downloadmerchant-5672080efcaca68ed2d301adf1673d45f7638a16.tar.gz
merchant-5672080efcaca68ed2d301adf1673d45f7638a16.tar.bz2
merchant-5672080efcaca68ed2d301adf1673d45f7638a16.zip
-add more events
-rw-r--r--src/backend/taler-merchant-httpd.h28
-rw-r--r--src/backend/taler-merchant-httpd_post-orders-ID-paid.c48
-rw-r--r--src/backend/taler-merchant-httpd_post-orders-ID-pay.c50
-rw-r--r--src/backend/taler-merchant-httpd_private-get-orders-ID.c37
-rw-r--r--src/backend/taler-merchant-httpd_private-post-orders-ID-refund.c35
5 files changed, 190 insertions, 8 deletions
diff --git a/src/backend/taler-merchant-httpd.h b/src/backend/taler-merchant-httpd.h
index 06f29e7a..6e8362a4 100644
--- a/src/backend/taler-merchant-httpd.h
+++ b/src/backend/taler-merchant-httpd.h
@@ -178,6 +178,34 @@ struct TMH_OrderPayEvent
/**
+ * Event triggered when a fulfillment URL is
+ * bound to a session (as paid).
+ */
+struct TMH_SessionEvent
+{
+ /**
+ * Type is #TALER_DBEVENT_MERCHANT_SESSION_CAPTURED
+ */
+ struct GNUNET_DB_EventHeaderP header;
+
+ /**
+ * Always zero (for alignment).
+ */
+ uint32_t reserved;
+
+ /**
+ * Hash of the fulfillment URL.
+ */
+ struct GNUNET_HashCode h_fulfillment_url;
+
+ /**
+ * Hash of the session ID
+ */
+ struct GNUNET_HashCode h_session_id;
+};
+
+
+/**
* Event triggered when an order's refund is increased.
*/
struct TMH_OrderRefundEvent
diff --git a/src/backend/taler-merchant-httpd_post-orders-ID-paid.c b/src/backend/taler-merchant-httpd_post-orders-ID-paid.c
index c821ed32..d274c1f6 100644
--- a/src/backend/taler-merchant-httpd_post-orders-ID-paid.c
+++ b/src/backend/taler-merchant-httpd_post-orders-ID-paid.c
@@ -1,6 +1,6 @@
/*
This file is part of TALER
- (C) 2014-2020 Taler Systems SA
+ (C) 2014-2021 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
@@ -29,6 +29,38 @@
#include "taler-merchant-httpd_post-orders-ID-paid.h"
+/**
+ * Use database to notify other clients about the
+ * session being captured.
+ *
+ * @param session_id the captured session
+ * @param fulfillment_url the URL that is now paid for by @a session_id
+ */
+static void
+trigger_session_notification (const char *session_id,
+ const char *fulfillment_url)
+{
+#ifndef TALER_API_VERSION
+#define TALER_DBEVENT_MERCHANT_SESSION_CAPTURED 1103
+#endif
+ struct TMH_SessionEvent session_eh = {
+ .header.size = htons (sizeof (session_eh)),
+ .header.type = htons (TALER_DBEVENT_MERCHANT_SESSION_CAPTURED)
+ };
+
+ GNUNET_CRYPTO_hash (session_id,
+ strlen (session_id),
+ &session_eh.h_session_id);
+ GNUNET_CRYPTO_hash (fulfillment_url,
+ strlen (fulfillment_url),
+ &session_eh.h_fulfillment_url);
+ TMH_db->event_notify (TMH_db->cls,
+ &session_eh.header,
+ NULL,
+ 0);
+}
+
+
MHD_RESULT
TMH_post_orders_ID_paid (const struct TMH_RequestHandler *rh,
struct MHD_Connection *connection,
@@ -145,7 +177,7 @@ TMH_post_orders_ID_paid (const struct TMH_RequestHandler *rh,
fulfillment_url
= json_string_value (json_object_get (contract_terms,
- "fulfillment_url"));
+ "fulfillment_url"));
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Marking contract %s with %s/%s as paid\n",
order_id,
@@ -165,15 +197,21 @@ TMH_post_orders_ID_paid (const struct TMH_RequestHandler *rh,
TALER_EC_GENERIC_DB_STORE_FAILED,
"mark_contract_paid");
}
-
- /* Wake everybody up who waits for this fulfillment_url and session_id */
+
+ /* Wake everybody up who waits for this fulfillment_url and session_id */
+ if ( (NULL != fulfillment_url) &&
+ (NULL != session_id) )
+ trigger_session_notification (session_id,
+ fulfillment_url);
if (NULL != fulfillment_url)
TMH_long_poll_resume2 (session_id,
fulfillment_url);
/* fulfillment_url is part of the contract_terms */
json_decref (contract_terms);
- /* Resume clients waiting on the order */
+ /* Resume clients waiting on the order
+ (NOTE: should never be needed, as /pay
+ would have triggered those, right?) */
TMH_long_poll_resume (order_id,
hc->instance,
NULL,
diff --git a/src/backend/taler-merchant-httpd_post-orders-ID-pay.c b/src/backend/taler-merchant-httpd_post-orders-ID-pay.c
index f4e7f6ee..ea8dd200 100644
--- a/src/backend/taler-merchant-httpd_post-orders-ID-pay.c
+++ b/src/backend/taler-merchant-httpd_post-orders-ID-pay.c
@@ -25,6 +25,7 @@
* @author Florian Dold
*/
#include "platform.h"
+#include <taler/taler_dbevents.h>
#include <taler/taler_signatures.h>
#include <taler/taler_json_lib.h>
#include <taler/taler_exchange_service.h>
@@ -1290,6 +1291,54 @@ check_payment_sufficient (struct PayContext *pc)
/**
+ * Use database to notify other clients about the
+ * payment being completed.
+ *
+ * @param pc context to trigger notification for
+ */
+static void
+trigger_payment_notification (struct PayContext *pc)
+{
+ {
+ struct TMH_OrderPayEvent pay_eh = {
+ .header.size = htons (sizeof (pay_eh)),
+ .header.type = htons (TALER_DBEVENT_MERCHANT_ORDER_PAID)
+ };
+
+ GNUNET_CRYPTO_hash (pc->order_id,
+ strlen (pc->order_id),
+ &pay_eh.h_order_id);
+ TMH_db->event_notify (TMH_db->cls,
+ &pay_eh.header,
+ NULL,
+ 0);
+ }
+ if ( (NULL != pc->session_id) &&
+ (NULL != pc->fulfillment_url) )
+ {
+#ifndef TALER_API_VERSION
+#define TALER_DBEVENT_MERCHANT_SESSION_CAPTURED 1103
+#endif
+ struct TMH_SessionEvent session_eh = {
+ .header.size = htons (sizeof (session_eh)),
+ .header.type = htons (TALER_DBEVENT_MERCHANT_SESSION_CAPTURED)
+ };
+
+ GNUNET_CRYPTO_hash (pc->session_id,
+ strlen (pc->session_id),
+ &session_eh.h_session_id);
+ GNUNET_CRYPTO_hash (pc->fulfillment_url,
+ strlen (pc->fulfillment_url),
+ &session_eh.h_fulfillment_url);
+ TMH_db->event_notify (TMH_db->cls,
+ &session_eh.header,
+ NULL,
+ 0);
+ }
+}
+
+
+/**
*
*
*/
@@ -1445,6 +1494,7 @@ execute_pay_transaction (struct PayContext *pc)
"mark contract paid");
return;
}
+ trigger_payment_notification (pc);
}
{
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 6bba091b..3688bb87 100644
--- a/src/backend/taler-merchant-httpd_private-get-orders-ID.c
+++ b/src/backend/taler-merchant-httpd_private-get-orders-ID.c
@@ -158,11 +158,18 @@ struct GetOrderRequestContext
struct GNUNET_SCHEDULER_Task *tt;
/**
- * Database event we are waiting on to be resuming.
+ * Database event we are waiting on to be resuming
+ * for payment or refunds.
*/
struct GNUNET_DB_EventHandler *eh;
/**
+ * Database event we are waiting on to be resuming
+ * for session capture.
+ */
+ struct GNUNET_DB_EventHandler *seh;
+
+ /**
* Contract terms of the payment we are checking. NULL when they
* are not (yet) known.
*/
@@ -656,6 +663,11 @@ gorc_cleanup (void *cls)
TMH_db->event_listen_cancel (gorc->eh);
gorc->eh = NULL;
}
+ if (NULL != gorc->seh)
+ {
+ TMH_db->event_listen_cancel (gorc->seh);
+ gorc->seh = NULL;
+ }
GNUNET_free (gorc);
}
@@ -870,6 +882,29 @@ TMH_private_get_orders_ID (const struct TMH_RequestHandler *rh,
timeout,
&resume_by_event,
gorc);
+ if ( (NULL != gorc->session_id) &&
+ (NULL != gorc->fulfillment_url) )
+ {
+#ifndef TALER_API_VERSION
+#define TALER_DBEVENT_MERCHANT_SESSION_CAPTURED 1103
+#endif
+ struct TMH_SessionEvent session_eh = {
+ .header.size = htons (sizeof (session_eh)),
+ .header.type = htons (TALER_DBEVENT_MERCHANT_SESSION_CAPTURED)
+ };
+
+ GNUNET_CRYPTO_hash (gorc->session_id,
+ strlen (gorc->session_id),
+ &session_eh.h_session_id);
+ GNUNET_CRYPTO_hash (gorc->fulfillment_url,
+ strlen (gorc->fulfillment_url),
+ &session_eh.h_fulfillment_url);
+ gorc->seh = TMH_db->event_listen (TMH_db->cls,
+ &session_eh.header,
+ timeout,
+ &resume_by_event,
+ gorc);
+ }
}
}
else
diff --git a/src/backend/taler-merchant-httpd_private-post-orders-ID-refund.c b/src/backend/taler-merchant-httpd_private-post-orders-ID-refund.c
index 903b542d..46f30668 100644
--- a/src/backend/taler-merchant-httpd_private-post-orders-ID-refund.c
+++ b/src/backend/taler-merchant-httpd_private-post-orders-ID-refund.c
@@ -1,6 +1,6 @@
/*
This file is part of TALER
- (C) 2014-2020 Taler Systems SA
+ (C) 2014-2021 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
@@ -21,6 +21,7 @@
*/
#include "platform.h"
#include <jansson.h>
+#include <taler/taler_dbevents.h>
#include <taler/taler_signatures.h>
#include <taler/taler_json_lib.h>
#include "taler-merchant-httpd_private-post-orders-ID-refund.h"
@@ -35,6 +36,34 @@
/**
+ * Use database to notify other clients about the
+ * @a order_id being refunded
+ *
+ * @param order_id the order receiving a refund
+ * @param amount the (total) refunded amount
+ */
+static void
+trigger_refund_notification (const char *order_id,
+ const struct TALER_Amount *amount)
+{
+ const char *as;
+ struct TMH_OrderRefundEvent refund_eh = {
+ .header.size = htons (sizeof (refund_eh)),
+ .header.type = htons (TALER_DBEVENT_MERCHANT_ORDER_REFUND)
+ };
+
+ as = TALER_amount2s (amount);
+ GNUNET_CRYPTO_hash (order_id,
+ strlen (order_id),
+ &refund_eh.h_order_id);
+ TMH_db->event_notify (TMH_db->cls,
+ &refund_eh.header,
+ as,
+ strlen (as));
+}
+
+
+/**
* Make a taler://refund URI
*
* @param connection MHD connection to take host and path from
@@ -86,7 +115,7 @@ make_taler_refund_uri (struct MHD_Connection *connection,
}
GNUNET_buffer_write_path (&buf, order_id);
GNUNET_buffer_write_path (&buf,
- ""); // Trailing slash
+ ""); /* Trailing slash */
return GNUNET_buffer_reap_str (&buf);
}
@@ -222,6 +251,8 @@ TMH_private_post_orders_ID_refund (const struct TMH_RequestHandler *rh,
{
enum GNUNET_DB_QueryStatus qs;
+ trigger_refund_notification (hc->infix,
+ &refund);
qs = TMH_db->commit (TMH_db->cls);
if (GNUNET_DB_STATUS_HARD_ERROR == qs)
{