gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] [taler-merchant] branch master updated: tests for /check-pa


From: gnunet
Subject: [GNUnet-SVN] [taler-merchant] branch master updated: tests for /check-payment
Date: Mon, 22 Jan 2018 19:09:53 +0100

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

dold pushed a commit to branch master
in repository merchant.

The following commit(s) were added to refs/heads/master by this push:
     new 0b97373  tests for /check-payment
0b97373 is described below

commit 0b9737325f1bc20e1b38473ab24e89a8f2676577
Author: Florian Dold <address@hidden>
AuthorDate: Mon Jan 22 19:09:46 2018 +0100

    tests for /check-payment
---
 src/lib/test_merchant_api.c | 132 +++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 131 insertions(+), 1 deletion(-)

diff --git a/src/lib/test_merchant_api.c b/src/lib/test_merchant_api.c
index 26c0828..5f31d3a 100644
--- a/src/lib/test_merchant_api.c
+++ b/src/lib/test_merchant_api.c
@@ -241,7 +241,12 @@ enum OpCode
   /**
    * Pickup a tip.
    */
-  OC_TIP_PICKUP
+  OC_TIP_PICKUP,
+
+  /**
+   * Check pay status.
+   */
+  OC_CHECK_PAYMENT,
 
 };
 
@@ -995,6 +1000,32 @@ struct Command
 
     } tip_pickup;
 
+    struct {
+
+      /**
+       * Reference for the contract we want to check.
+       */
+      const char *contract_ref;
+
+      /**
+       * The text case fails if this field is not here, and it is
+       * very uncleary why.
+       */
+      uint64_t layout_dummy;
+
+      /**
+       * Whether to expect the payment to be settled or not.
+       */
+      int expect_paid;
+
+      /**
+       * Operation handle for the /check-payment request,
+       * NULL if operation is not running.
+       */
+      struct TALER_MERCHANT_CheckPaymentOperation *cpo;
+
+    } check_payment;
+
   } details;
 
 };
@@ -2086,6 +2117,49 @@ proposal_lookup_cb (void *cls,
 
 
 /**
+ * Callback for GET /proposal issued at backend. Just check
+ * whether response code is as expected.
+ *
+ * @param cls closure
+ * @param http_status HTTP status code we got
+ * @param json full response we got
+ */
+static void
+check_payment_cb (void *cls,
+                  unsigned int http_status,
+                  const json_t *obj,
+                  int paid,
+                  int refunded,
+                  struct TALER_Amount *refund_amount,
+                  const char *payment_redirect_url)
+{
+  struct InterpreterState *is = cls;
+  struct Command *cmd = &is->commands[is->ip];
+
+  GNUNET_log (GNUNET_ERROR_TYPE_INFO, "check payment: expected paid: %s: %d\n",
+              cmd->label,
+              cmd->details.check_payment.expect_paid);
+  GNUNET_log (GNUNET_ERROR_TYPE_INFO, "check payment: paid: %d\n",
+              paid);
+  GNUNET_log (GNUNET_ERROR_TYPE_INFO, "check payment: url: %s\n",
+              payment_redirect_url);
+
+  cmd->details.check_payment.cpo = NULL;
+  if (paid != cmd->details.check_payment.expect_paid)
+  {
+    GNUNET_break (0);
+    fail (is);
+    return;
+  }
+
+  cmd->details.proposal_lookup.plo = NULL;
+  if (cmd->expected_response_code != http_status)
+    fail (is);
+  next_command (is);
+}
+
+
+/**
  * Function called with detailed wire transfer data.
  *
  * @param cls closure
@@ -2645,6 +2719,17 @@ cleanup_state (struct InterpreterState *is)
         cmd->details.tip_pickup.sigs = NULL;
       }
       break;
+    case OC_CHECK_PAYMENT:
+      if (NULL != cmd->details.check_payment.cpo)
+      {
+        GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+                    "Command %u (%s) did not complete\n",
+                    i,
+                    cmd->label);
+        TALER_MERCHANT_check_payment_cancel (cmd->details.check_payment.cpo);
+        cmd->details.check_payment.cpo = NULL;
+      }
+      break;
     default:
       GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
                   "Shutdown: unknown instruction %d at %u (%s)\n",
@@ -2913,6 +2998,36 @@ interpreter_run (void *cls)
       }
     }
     break;
+  case OC_CHECK_PAYMENT:
+    {
+      const char *order_id;
+
+      GNUNET_assert (NULL != cmd->details.check_payment.contract_ref);
+      GNUNET_assert (NULL != (ref =
+                              find_command (is,
+                                            
cmd->details.check_payment.contract_ref)));
+
+      order_id = json_string_value (json_object_get 
(ref->details.proposal.contract_terms,
+                                                     "order_id"));
+
+      GNUNET_assert (NULL != order_id);
+
+      if (NULL == (cmd->details.check_payment.cpo
+                   = TALER_MERCHANT_check_payment (ctx,
+                                                   MERCHANT_URL,
+                                                   instance,
+                                                   order_id,
+                                                   NULL,
+                                                   NULL,
+                                                   NULL,
+                                                   check_payment_cb,
+                                                   is)))
+      {
+        GNUNET_break (0);
+        fail (is);
+      }
+    }
+    break;
   case OC_ADMIN_ADD_INCOMING:
     {
       char *subject;
@@ -4016,6 +4131,14 @@ run (void *cls)
         \"products\":\
           [ {\"description\":\"ice cream\",\
              \"value\":\"{EUR:5}\"} ] }"},
+
+    /* check payment before we pay */
+    { .oc = OC_CHECK_PAYMENT,
+      .label = "check-payment-1",
+      .expected_response_code = MHD_HTTP_OK,
+      .details.check_payment.contract_ref = "create-proposal-1",
+      .details.check_payment.expect_paid = GNUNET_NO },
+
     /* execute simple payment */
     { .oc = OC_PAY,
       .label = "deposit-simple",
@@ -4026,6 +4149,13 @@ run (void *cls)
       .details.pay.amount_with_fee = "EUR:5",
       .details.pay.amount_without_fee = "EUR:4.99" },
 
+    /* check payment after we've paid */
+    { .oc = OC_CHECK_PAYMENT,
+      .label = "check-payment-2",
+      .expected_response_code = MHD_HTTP_OK,
+      .details.check_payment.contract_ref = "create-proposal-1",
+      .details.check_payment.expect_paid = GNUNET_YES },
+
     /* Try to replay payment reusing coin */
     { .oc = OC_PAY,
       .label = "replay-simple",

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



reply via email to

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