diff options
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.c | 35 |
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 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of TALER | 2 | This file is part of TALER |
3 | (C) 2014-2020 Taler Systems SA | 3 | (C) 2014-2021 Taler Systems SA |
4 | 4 | ||
5 | TALER is free software; you can redistribute it and/or modify it under the | 5 | TALER is free software; you can redistribute it and/or modify it under the |
6 | terms of the GNU Affero General Public License as published by the Free Software | 6 | terms of the GNU Affero General Public License as published by the Free Software |
@@ -21,6 +21,7 @@ | |||
21 | */ | 21 | */ |
22 | #include "platform.h" | 22 | #include "platform.h" |
23 | #include <jansson.h> | 23 | #include <jansson.h> |
24 | #include <taler/taler_dbevents.h> | ||
24 | #include <taler/taler_signatures.h> | 25 | #include <taler/taler_signatures.h> |
25 | #include <taler/taler_json_lib.h> | 26 | #include <taler/taler_json_lib.h> |
26 | #include "taler-merchant-httpd_private-post-orders-ID-refund.h" | 27 | #include "taler-merchant-httpd_private-post-orders-ID-refund.h" |
@@ -35,6 +36,34 @@ | |||
35 | 36 | ||
36 | 37 | ||
37 | /** | 38 | /** |
39 | * Use database to notify other clients about the | ||
40 | * @a order_id being refunded | ||
41 | * | ||
42 | * @param order_id the order receiving a refund | ||
43 | * @param amount the (total) refunded amount | ||
44 | */ | ||
45 | static void | ||
46 | trigger_refund_notification (const char *order_id, | ||
47 | const struct TALER_Amount *amount) | ||
48 | { | ||
49 | const char *as; | ||
50 | struct TMH_OrderRefundEvent refund_eh = { | ||
51 | .header.size = htons (sizeof (refund_eh)), | ||
52 | .header.type = htons (TALER_DBEVENT_MERCHANT_ORDER_REFUND) | ||
53 | }; | ||
54 | |||
55 | as = TALER_amount2s (amount); | ||
56 | GNUNET_CRYPTO_hash (order_id, | ||
57 | strlen (order_id), | ||
58 | &refund_eh.h_order_id); | ||
59 | TMH_db->event_notify (TMH_db->cls, | ||
60 | &refund_eh.header, | ||
61 | as, | ||
62 | strlen (as)); | ||
63 | } | ||
64 | |||
65 | |||
66 | /** | ||
38 | * Make a taler://refund URI | 67 | * Make a taler://refund URI |
39 | * | 68 | * |
40 | * @param connection MHD connection to take host and path from | 69 | * @param connection MHD connection to take host and path from |
@@ -86,7 +115,7 @@ make_taler_refund_uri (struct MHD_Connection *connection, | |||
86 | } | 115 | } |
87 | GNUNET_buffer_write_path (&buf, order_id); | 116 | GNUNET_buffer_write_path (&buf, order_id); |
88 | GNUNET_buffer_write_path (&buf, | 117 | GNUNET_buffer_write_path (&buf, |
89 | ""); // Trailing slash | 118 | ""); /* Trailing slash */ |
90 | return GNUNET_buffer_reap_str (&buf); | 119 | return GNUNET_buffer_reap_str (&buf); |
91 | } | 120 | } |
92 | 121 | ||
@@ -222,6 +251,8 @@ TMH_private_post_orders_ID_refund (const struct TMH_RequestHandler *rh, | |||
222 | { | 251 | { |
223 | enum GNUNET_DB_QueryStatus qs; | 252 | enum GNUNET_DB_QueryStatus qs; |
224 | 253 | ||
254 | trigger_refund_notification (hc->infix, | ||
255 | &refund); | ||
225 | qs = TMH_db->commit (TMH_db->cls); | 256 | qs = TMH_db->commit (TMH_db->cls); |
226 | if (GNUNET_DB_STATUS_HARD_ERROR == qs) | 257 | if (GNUNET_DB_STATUS_HARD_ERROR == qs) |
227 | { | 258 | { |