gnunet-svn
[Top][All Lists]
Advanced

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

[taler-taler-mdb] branch master updated: enforce payment deadline to be


From: gnunet
Subject: [taler-taler-mdb] branch master updated: enforce payment deadline to be applicable
Date: Wed, 18 May 2022 18:28:53 +0200

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

grothoff pushed a commit to branch master
in repository taler-mdb.

The following commit(s) were added to refs/heads/master by this push:
     new dc35388  enforce payment deadline to be applicable
dc35388 is described below

commit dc35388eaf7b09f3eb069036212137ce70a195d2
Author: Christian Grothoff <christian@grothoff.org>
AuthorDate: Wed May 18 18:28:50 2022 +0200

    enforce payment deadline to be applicable
---
 src/main.c | 69 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 67 insertions(+), 2 deletions(-)

diff --git a/src/main.c b/src/main.c
index 5dee93d..f2e6a2d 100644
--- a/src/main.c
+++ b/src/main.c
@@ -78,6 +78,12 @@ along with
 #define BACKEND_POLL_TIMEOUT GNUNET_TIME_relative_multiply ( \
     GNUNET_TIME_UNIT_MINUTES, 5)
 
+/**
+ * Set payment deadline below what will work with the snack machine.
+ */
+#define PAY_TIMEOUT GNUNET_TIME_relative_multiply ( \
+    GNUNET_TIME_UNIT_MINUTES, 1)
+
 /**
  * How long could it take at most for us to notify the Taler merchant
  * backend to grant a refund to a user if dispensing the product
@@ -410,6 +416,11 @@ struct PaymentActivity
    */
   struct TALER_Amount amount;
 
+  /**
+   * Handle for our attempt to delete an ongoing order.
+   */
+  struct TALER_MERCHANT_OrderDeleteHandle *odh;
+
   /**
    * Member to see if the wallet already received a uri
    * If true, tunneling can be offered to the wallet.
@@ -954,9 +965,57 @@ async_pa_cleanup_job (void *cls)
  *
  * @param pa the payment activity to clean up
  */
+static void
+cleanup_payment (struct PaymentActivity *pa);
+
+
+/**
+ * Function called with the result of the DELETE /orders/$ID operation.
+ *
+ * @param cls closure with the `struct PaymentActivity *`
+ * @param hr HTTP response details
+ */
+static void
+order_delete_cb (
+  void *cls,
+  const struct TALER_MERCHANT_HttpResponse *hr)
+{
+  struct PaymentActivity *pa = cls;
+
+  pa->odh = NULL;
+  if ( (MHD_HTTP_OK != hr->http_status) &&
+       (MHD_HTTP_NO_CONTENT != hr->http_status) )
+  {
+    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                "Failed to delete incomplete order from backend: %d/%u\n",
+                (int) hr->http_status,
+                (unsigned int) hr->ec);
+  }
+  cleanup_payment (pa);
+}
+
+
 static void
 cleanup_payment (struct PaymentActivity *pa)
 {
+  if ( (! pa->paid) &&
+       (NULL != pa->order_id) )
+  {
+    char *oid;
+
+    oid = pa->order_id;
+    pa->order_id = NULL;
+    pa->odh = TALER_MERCHANT_order_delete (
+      pa->ctx,
+      pa->base_url,
+      oid,
+      &order_delete_cb,
+      pa);
+    GNUNET_free (oid);
+    return;
+  }
+  if (NULL != pa->odh)
+    TALER_MERCHANT_order_delete_cancel (pa->odh);
   if (NULL != pa->pnd)
   {
     nfc_abort_command (pa->pnd);
@@ -1589,6 +1648,9 @@ launch_payment (struct Product *product)
     orderReq = GNUNET_JSON_PACK (
       GNUNET_JSON_pack_string ("summary",
                                product->description),
+      GNUNET_JSON_pack_timestamp ("pay_deadline",
+                                  GNUNET_TIME_relative_to_timestamp (
+                                    PAY_TIMEOUT)),
       GNUNET_JSON_pack_object_steal (
         "products",
         GNUNET_JSON_PACK (
@@ -1612,6 +1674,9 @@ launch_payment (struct Product *product)
     orderReq = GNUNET_JSON_PACK (
       GNUNET_JSON_pack_string ("summary",
                                product->description),
+      GNUNET_JSON_pack_timestamp ("pay_deadline",
+                                  GNUNET_TIME_relative_to_timestamp (
+                                    PAY_TIMEOUT)),
       TALER_JSON_pack_amount ("amount",
                               &product->price),
       GNUNET_JSON_pack_string ("fulfillment_message",
@@ -2616,7 +2681,7 @@ read_mdb_command (void *cls)
  * @brief Mdb event loop to start read and write tasks
  */
 static void
-run_mdb_event_loop ()
+run_mdb_event_loop (void)
 {
   struct GNUNET_DISK_FileHandle fh = { mdb.uartfd };
 
@@ -2890,7 +2955,7 @@ read_products (void *cls,
  * @return #GNUNET_OK on success
  */
 static enum GNUNET_GenericReturnValue
-mdb_init ()
+mdb_init (void)
 {
   struct termios uart_opts_raw;
 

-- 
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]