gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[taler-merchant] branch master updated: -add more events


From: gnunet
Subject: [taler-merchant] branch master updated: -add more events
Date: Wed, 25 Aug 2021 07:58:30 +0200

This is an automated email from the git hooks/post-receive script.

grothoff pushed a commit to branch master
in repository merchant.

The following commit(s) were added to refs/heads/master by this push:
     new 5672080e -add more events
5672080e is described below

commit 5672080efcaca68ed2d301adf1673d45f7638a16
Author: Christian Grothoff <christian@grothoff.org>
AuthorDate: Wed Aug 25 07:58:27 2021 +0200

    -add more events
---
 src/backend/taler-merchant-httpd.h                 | 28 ++++++++++++
 .../taler-merchant-httpd_post-orders-ID-paid.c     | 48 ++++++++++++++++++---
 .../taler-merchant-httpd_post-orders-ID-pay.c      | 50 ++++++++++++++++++++++
 .../taler-merchant-httpd_private-get-orders-ID.c   | 37 +++++++++++++++-
 ...-merchant-httpd_private-post-orders-ID-refund.c | 35 ++++++++++++++-
 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
@@ -177,6 +177,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.
  */
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>
@@ -1289,6 +1290,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,10 +158,17 @@ 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"
@@ -34,6 +35,34 @@
 #define MAX_RETRIES 5
 
 
+/**
+ * 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
  *
@@ -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)
       {

-- 
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]