gnunet-svn
[Top][All Lists]
Advanced

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

[taler-taler-mdb] branch master updated: add option to enable sold-out d


From: gnunet
Subject: [taler-taler-mdb] branch master updated: add option to enable sold-out detection
Date: Tue, 10 Dec 2019 15:03:09 +0100

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 8841dfe  add option to enable sold-out detection
8841dfe is described below

commit 8841dfec1ad670fc584fd5d47c1f157108888976
Author: Christian Grothoff <address@hidden>
AuthorDate: Tue Dec 10 15:02:55 2019 +0100

    add option to enable sold-out detection
---
 src/main.c | 53 ++++++++++++++++++++++++++++++++++++++++++++++++++---
 1 file changed, 50 insertions(+), 3 deletions(-)

diff --git a/src/main.c b/src/main.c
index e9ddb5a..8ac2911 100644
--- a/src/main.c
+++ b/src/main.c
@@ -248,10 +248,17 @@ struct Product
    */
   unsigned long long number;
 
+  /**
+   * Set to #GNUNET_YES if this product was found
+   * to have been sold out (VEND failure).
+   */
+  int sold_out;
+
   /**
    * Key for the product (optional, needed to test the application without 
vending machine)
    */
   char key;
+
 };
 
 
@@ -270,6 +277,11 @@ struct PaymentActivity
    */
   struct TALER_MERCHANT_CheckPaymentOperation *cpo;
 
+  /**
+   * The product being sold.
+   */
+  struct Product *product;
+
   /**
    * Order ID for pending order
    */
@@ -571,6 +583,11 @@ static int disable_mdb;
  */
 static int disable_tty;
 
+/**
+ * Global option '-s' to enable sold-out detection.
+ */
+static int sold_out_enabled;
+
 /**
  * Taler wallet application identifier
  */
@@ -1278,7 +1295,7 @@ proposal_cb (void *cls,
  * @return payment activity for the order, NULL on failure
  */
 static struct PaymentActivity *
-launch_payment (const struct Product *product)
+launch_payment (struct Product *product)
 {
   struct PaymentActivity *pa;
   json_t *orderReq;
@@ -1318,6 +1335,7 @@ launch_payment (const struct Product *product)
     return NULL;
   }
   pa = GNUNET_new (struct PaymentActivity);
+  pa->product = product;
   pa->amount = product->price;
   pa->po = TALER_MERCHANT_order_put (ctx,
                                      backendBaseUrl,
@@ -1369,6 +1387,7 @@ refund_complete_cb (void *cls,
 {
   struct Refund *r = cls;
 
+  (void) obj;
   r->rio = NULL;
   if (MHD_HTTP_OK != http_status)
   {
@@ -1390,6 +1409,7 @@ refund_complete_cb (void *cls,
 static void
 vend_failure ()
 {
+  struct Product *p;
   struct Refund *r;
 
   if (NULL == payment_activity)
@@ -1397,8 +1417,11 @@ vend_failure ()
     GNUNET_break (0);
     return;
   }
+  p = payment_activity->product;
   GNUNET_log (GNUNET_ERROR_TYPE_INFO,
-              "Received MDB vend failure, refunding customer\n");
+              "Received MDB vend failure for `%s', refunding customer\n",
+              p->description);
+  p->sold_out = GNUNET_YES;
   mdb.cmd = &endSession;
   mdb.session_running = GNUNET_NO;
   r = GNUNET_new (struct Refund);
@@ -1512,6 +1535,17 @@ read_keyboard_command (void *cls)
   for (unsigned int i = 0; i < products_length; i++)
     if (((char) input) == products[i].key)
     {
+      if ( (sold_out_enabled) &&
+           (products[i].sold_out) )
+      {
+        GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+                    "Product %s sold out, denying vend\n",
+                    products[i].description);
+        mdb.cmd = &denyVend;
+        run_mdb_event_loop ();
+        start_read_keyboard ();
+        return;
+      }
       payment_activity = launch_payment (&products[i]);
       start_read_keyboard ();
       return;
@@ -1659,7 +1693,7 @@ write_mdb_command (void *cls)
       chkSum += mdb.txBuffer[idx] = mdb.cmd->cmd.bin[idx];
     for (size_t idx = 0; idx < mdb.cmd->data.bin_size; idx++)
       chkSum += mdb.txBuffer[idx + mdb.cmd->cmd.bin_size] =
-                  mdb.cmd->data.bin[idx];
+        mdb.cmd->data.bin[idx];
     mdb.txBuffer[mdb.cmd->cmd.bin_size + mdb.cmd->data.bin_size] =
       (uint8_t) (chkSum & 0xFF);
   }
@@ -1783,6 +1817,15 @@ handle_command (const char *hex,
               GNUNET_log (GNUNET_ERROR_TYPE_INFO,
                           "Product %u selected on NFC\n",
                           product);
+              if ( (sold_out_enabled) &&
+                   (products[i].sold_out) )
+              {
+                GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+                            "Product %s sold out, denying vend\n",
+                            products[i].description);
+                mdb.cmd = &denyVend;
+                return;
+              }
               payment_activity = launch_payment (&products[i]);
               return;
             }
@@ -2513,6 +2556,10 @@ main (int argc,
                                "disable-mdb",
                                "disable all interactions with the MDB (for 
testing without machine)",
                                &disable_mdb),
+    GNUNET_GETOPT_option_flag ('s',
+                               "enable-soldout",
+                               "enable detection of sold-out products, 
preventing vend operations of the respective product until the process is 
restarted",
+                               &sold_out_enabled),
     GNUNET_GETOPT_option_flag ('t',
                                "disable-tty",
                                "disable all keyboard interactions (for running 
from systemd)",

-- 
To stop receiving notification emails like this one, please contact
address@hidden.



reply via email to

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