gnunet-svn
[Top][All Lists]
Advanced

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

[taler-merchant] branch master updated: add 'paid' to GET /private/order


From: gnunet
Subject: [taler-merchant] branch master updated: add 'paid' to GET /private/orders response entries
Date: Thu, 30 Jul 2020 23:35:59 +0200

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

jonathan-buchanan pushed a commit to branch master
in repository merchant.

The following commit(s) were added to refs/heads/master by this push:
     new 0347657  add 'paid' to GET /private/orders response entries
0347657 is described below

commit 034765718ee18166f634ba7dc996a159f82e76a6
Author: Jonathan Buchanan <jonathan.russ.buchanan@gmail.com>
AuthorDate: Thu Jul 30 17:35:50 2020 -0400

    add 'paid' to GET /private/orders response entries
---
 .../taler-merchant-httpd_private-get-orders.c      | 45 ++++++++++++++++++----
 src/include/taler_merchant_service.h               |  5 +++
 src/lib/merchant_api_get_orders.c                  |  2 +
 src/testing/test_merchant_api_twisted.c            |  2 +-
 4 files changed, 45 insertions(+), 9 deletions(-)

diff --git a/src/backend/taler-merchant-httpd_private-get-orders.c 
b/src/backend/taler-merchant-httpd_private-get-orders.c
index c14569d..d890fa8 100644
--- a/src/backend/taler-merchant-httpd_private-get-orders.c
+++ b/src/backend/taler-merchant-httpd_private-get-orders.c
@@ -42,6 +42,11 @@ struct AddOrderState
    * The result after adding the orders (0 for okay, anything else for an 
error).
    */
   int result;
+
+  /**
+   * In the case of an error, what message to respond with.
+   */
+  const char *ec_msg;
 };
 
 
@@ -253,6 +258,7 @@ add_order (void *cls,
 {
   struct AddOrderState *aos = cls;
   json_t *contract_terms;
+  struct GNUNET_HashCode h_contract_terms;
   enum GNUNET_DB_QueryStatus qs =
     TMH_db->lookup_order (TMH_db->cls,
                           aos->instance_id,
@@ -260,19 +266,38 @@ add_order (void *cls,
                           NULL,
                           &contract_terms);
   bool refundable = false;
+  bool paid;
   if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT != qs)
   {
     aos->result = 1;
+    aos->ec_msg = "failed to lookup order in database";
     json_decref (contract_terms);
     return;
   }
 
+  {
+    qs = TMH_db->lookup_order_status (TMH_db->cls,
+                                      aos->instance_id,
+                                      order_id,
+                                      &h_contract_terms,
+                                      &paid);
+    /* qs == 0: contract terms don't exist, so the order cannot be paid. */
+    if (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS == qs)
+      paid = false;
+    if (qs < 0)
+    {
+      aos->result = 1;
+      aos->ec_msg = "failed to lookup order status in database";
+      json_decref (contract_terms);
+      return;
+    }
+  }
+
   {
     struct TALER_Amount order_amount;
     struct GNUNET_TIME_Absolute rd;
 
     struct GNUNET_TIME_Absolute now = GNUNET_TIME_absolute_get ();
-    struct GNUNET_HashCode h_contract_terms;
 
     struct GNUNET_JSON_Specification spec[] = {
       TALER_JSON_spec_amount ("amount",
@@ -288,17 +313,16 @@ add_order (void *cls,
                            NULL, NULL))
     {
       aos->result = 1;
+      aos->ec_msg = "failed to parse order contract terms";
       json_decref (contract_terms);
       return;
     }
 
-    if (now.abs_value_us <= rd.abs_value_us)
+    if ((now.abs_value_us <= rd.abs_value_us) &&
+        paid)
     {
       struct TALER_Amount refund_amount;
 
-      GNUNET_assert (GNUNET_OK ==
-                     TALER_JSON_contract_hash (contract_terms,
-                                               &h_contract_terms));
       GNUNET_assert (GNUNET_OK ==
                      TALER_amount_get_zero (TMH_currency,
                                             &refund_amount));
@@ -310,6 +334,7 @@ add_order (void *cls,
       if (0 > qs)
       {
         aos->result = 1;
+        aos->ec_msg = "failed to lookup order refunds in database";
         json_decref (contract_terms);
         return;
       }
@@ -323,7 +348,7 @@ add_order (void *cls,
                  json_array_append_new (
                    aos->pa,
                    json_pack (
-                     "{s:s, s:I, s:o, s:O, s:O, s:b}",
+                     "{s:s, s:I, s:o, s:O, s:O, s:b, s:b}",
                      "order_id",
                      order_id,
                      "row_id",
@@ -337,7 +362,9 @@ add_order (void *cls,
                      json_object_get (contract_terms,
                                       "summary"),
                      "refundable",
-                     refundable)));
+                     refundable,
+                     "paid",
+                     paid)));
   json_decref (contract_terms);
 }
 
@@ -438,7 +465,7 @@ TMH_private_get_orders (const struct TMH_RequestHandler *rh,
       return TALER_MHD_reply_with_error (connection,
                                          MHD_HTTP_INTERNAL_SERVER_ERROR,
                                          TALER_EC_ORDERS_GET_DB_LOOKUP_ERROR,
-                                         "failed to lookup orders in 
database");
+                                         aos->ec_msg);
     }
     return TALER_MHD_reply_json_pack (connection,
                                       MHD_HTTP_OK,
@@ -598,6 +625,8 @@ TMH_private_get_orders (const struct TMH_RequestHandler *rh,
       return TALER_MHD_reply_with_error (connection,
                                          MHD_HTTP_INTERNAL_SERVER_ERROR,
                                          TALER_EC_ORDERS_GET_DB_LOOKUP_ERROR,
+                                         0 != aos->result ?
+                                         aos->ec_msg :
                                          "failed to lookup orders in 
database");
     }
   }
diff --git a/src/include/taler_merchant_service.h 
b/src/include/taler_merchant_service.h
index 7390103..ca391e1 100644
--- a/src/include/taler_merchant_service.h
+++ b/src/include/taler_merchant_service.h
@@ -1253,6 +1253,11 @@ struct TALER_MERCHANT_OrderEntry
    */
   bool refundable;
 
+  /**
+   * Whether the order has been paid.
+   */
+  bool paid;
+
 };
 
 
diff --git a/src/lib/merchant_api_get_orders.c 
b/src/lib/merchant_api_get_orders.c
index c958579..10989b6 100644
--- a/src/lib/merchant_api_get_orders.c
+++ b/src/lib/merchant_api_get_orders.c
@@ -96,6 +96,8 @@ parse_orders (const json_t *ia,
                                &ie->summary),
       GNUNET_JSON_spec_bool ("refundable",
                              &ie->refundable),
+      GNUNET_JSON_spec_bool ("paid",
+                             &ie->paid),
       GNUNET_JSON_spec_end ()
     };
 
diff --git a/src/testing/test_merchant_api_twisted.c 
b/src/testing/test_merchant_api_twisted.c
index 6b0ea36..9adf9e2 100644
--- a/src/testing/test_merchant_api_twisted.c
+++ b/src/testing/test_merchant_api_twisted.c
@@ -369,7 +369,7 @@ run (void *cls,
     TALER_TESTING_cmd_merchant_claim_order (
       "claim-1-incorrect-claim-token",
       twister_merchant_url,
-      MHD_HTTP_CONFLICT,
+      MHD_HTTP_NOT_FOUND,
       "create-proposal-1",
       NULL),
     TALER_TESTING_cmd_merchant_post_orders ("create-proposal-2",

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