aboutsummaryrefslogtreecommitdiff
path: root/src/backend/taler-merchant-httpd_private-post-orders-ID-refund.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/backend/taler-merchant-httpd_private-post-orders-ID-refund.c')
-rw-r--r--src/backend/taler-merchant-httpd_private-post-orders-ID-refund.c35
1 files changed, 33 insertions, 2 deletions
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)
{