gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] [taler-merchant] 05/22: fix multi-coin payment.


From: gnunet
Subject: [GNUnet-SVN] [taler-merchant] 05/22: fix multi-coin payment.
Date: Sat, 17 Mar 2018 01:58:30 +0100

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

marcello pushed a commit to branch master
in repository merchant.

commit 502d45357714af100a47cb52241c2eae37aa770c
Author: Marcello Stanisci <address@hidden>
AuthorDate: Thu Mar 8 11:04:07 2018 +0100

    fix multi-coin payment.
    
    Calculate the per-coin amount and amount - deposit fee
    to be specified in the deposit permission.
---
 src/include/taler_merchant_service.h |  8 ++---
 src/lib/merchant_api_pay.c           |  5 ++--
 src/lib/test_merchant_api_twisted.c  | 48 ++++++++++++++++++++----------
 src/lib/testing_api_cmd_pay.c        | 57 ++++++++++++++++++------------------
 4 files changed, 69 insertions(+), 49 deletions(-)

diff --git a/src/include/taler_merchant_service.h 
b/src/include/taler_merchant_service.h
index 2dd0b20..6c0339f 100644
--- a/src/include/taler_merchant_service.h
+++ b/src/include/taler_merchant_service.h
@@ -303,12 +303,12 @@ struct TALER_MERCHANT_PayCoin
   struct TALER_CoinSpendPrivateKeyP coin_priv;
 
   /**
-   * Amount this coin is to contribute (including fee).
+   * Amount this coin contributes to (including fee).
    */
   struct TALER_Amount amount_with_fee;
 
   /**
-   * Amount this coin is to contribute (without fee).
+   * Amount this coin contributes to (without fee).
    */
   struct TALER_Amount amount_without_fee;
 
@@ -493,12 +493,12 @@ struct TALER_MERCHANT_PaidCoin
   struct TALER_CoinSpendSignatureP coin_sig;
 
   /**
-   * Amount this coin is to contribute (including fee).
+   * Amount this coin contributes to (including fee).
    */
   struct TALER_Amount amount_with_fee;
 
   /**
-   * Amount this coin is to contribute (without fee).
+   * Amount this coin contributes to (without fee).
    */
   struct TALER_Amount amount_without_fee;
 
diff --git a/src/lib/merchant_api_pay.c b/src/lib/merchant_api_pay.c
index 849b22b..75c2384 100644
--- a/src/lib/merchant_api_pay.c
+++ b/src/lib/merchant_api_pay.c
@@ -666,10 +666,11 @@ prepare_pay_generic (struct GNUNET_CURL_Context *ctx,
   dr.timestamp = GNUNET_TIME_absolute_hton (timestamp);
   dr.refund_deadline = GNUNET_TIME_absolute_hton (refund_deadline);
   dr.merchant = *merchant_pub;
+
   for (unsigned int i=0;i<num_coins;i++)
   {
-    const struct TALER_MERCHANT_PayCoin *coin = &coins[i];
-    struct TALER_MERCHANT_PaidCoin *p = &pc[i];
+    const struct TALER_MERCHANT_PayCoin *coin = &coins[i]; // coin priv.
+    struct TALER_MERCHANT_PaidCoin *p = &pc[i]; // coin pub.
     struct TALER_Amount fee;
 
     /* prepare 'dr' for this coin to generate coin signature */
diff --git a/src/lib/test_merchant_api_twisted.c 
b/src/lib/test_merchant_api_twisted.c
index 47f5714..adcb25f 100644
--- a/src/lib/test_merchant_api_twisted.c
+++ b/src/lib/test_merchant_api_twisted.c
@@ -162,7 +162,7 @@ run (void *cls,
      * Move money to the exchange's bank account.
      */
     CMD_TRANSFER_TO_EXCHANGE ("create-reserve-1",
-                              "EUR:5.01"),
+                              "EUR:2.02"),
     /**
      * Make a reserve exist, according to the previous
      * transfer.
@@ -172,13 +172,25 @@ run (void *cls,
     TALER_TESTING_cmd_check_bank_transfer
       ("check_bank_transfer-2",
        "http://localhost:8081/";,
-       "EUR:5.01", USER_ACCOUNT_NO, EXCHANGE_ACCOUNT_NO),
+       "EUR:2.02", USER_ACCOUNT_NO, EXCHANGE_ACCOUNT_NO),
 
     TALER_TESTING_cmd_withdraw_amount ("withdraw-coin-1",
                                        is->exchange,
                                        "create-reserve-1",
-                                       "EUR:5",
+                                       "EUR:1",
                                        MHD_HTTP_OK),
+
+    TALER_TESTING_cmd_withdraw_amount ("withdraw-coin-2",
+                                       is->exchange,
+                                       "create-reserve-1",
+                                       "EUR:1",
+                                       MHD_HTTP_OK),
+
+    TALER_TESTING_cmd_status ("withdraw-status",
+                              is->exchange,
+                              "create-reserve-1",
+                              "EUR:0",
+                              MHD_HTTP_OK),
     TALER_TESTING_cmd_proposal
       ("create-proposal-1",
        merchant_url,
@@ -193,11 +205,11 @@ run (void *cls,
         \"pay_deadline\":\"\\/Date(99999999999)\\/\",\
         \"amount\":\
           {\"currency\":\"EUR\",\
-           \"value\":5,\
+           \"value\":2,\
            \"fraction\":0},\
         \"summary\": \"merchant-lib testcase\",\
         \"products\": [ {\"description\":\"ice cream\",\
-                         \"value\":\"{EUR:5}\"} ] }",
+                         \"value\":\"{EUR:3}\"} ] }",
         NULL),
 
     TALER_TESTING_cmd_check_payment ("check-payment-1",
@@ -212,11 +224,13 @@ run (void *cls,
                            is->ctx,
                            MHD_HTTP_OK,
                            "create-proposal-1",
-                           "withdraw-coin-1",
-                           "EUR:5",
-                           "EUR:4.99",
-                           "EUR:0.01"),
+                           "withdraw-coin-1;" \
+                           "withdraw-coin-2",
+                           "EUR:2",
+                           "EUR:1.99", // no sense now
+                           "EUR:0.01"), // no sense now
 
+    #if 0
     TALER_TESTING_cmd_check_payment ("check-payment-2",
                                      merchant_url,
                                      is->ctx,
@@ -229,14 +243,14 @@ run (void *cls,
     TALER_TESTING_cmd_check_bank_transfer
       ("check_bank_transfer-1",
        exchange_url,
-       "EUR:4.98", 2, 62),
+       "EUR:5.98", 2, 62),
+    #endif
 
-    #if 0
     /* Should instead change the response body somehow! */
-    TALER_TESTING_cmd_hack_response_code ("hack-1",
-                                          CONFIG_FILE,
-                                          MHD_HTTP_FORBIDDEN),
-    #endif
+    #if 0
+    TALER_TESTING_cmd_empty_object ("hack-1",
+                                    CONFIG_FILE,
+                                    "deposits.0"),
 
     TALER_TESTING_cmd_merchant_track_transaction
       ("track-transaction-1",
@@ -247,6 +261,9 @@ run (void *cls,
        "deposit-simple",
        "EUR:0.01"), // ignored
 
+    #endif
+
+    #if 0
     TALER_TESTING_cmd_merchant_track_transfer
       ("track-transfer-1",
        merchant_url,
@@ -254,6 +271,7 @@ run (void *cls,
        MHD_HTTP_OK,
        "check_bank_transfer-1",
        "deposit-simple"),
+    #endif
 
     /**
      * End the suite.  Fixme: better to have a label for this
diff --git a/src/lib/testing_api_cmd_pay.c b/src/lib/testing_api_cmd_pay.c
index e628de9..6e8229a 100644
--- a/src/lib/testing_api_cmd_pay.c
+++ b/src/lib/testing_api_cmd_pay.c
@@ -394,13 +394,12 @@ check_payment_run (void *cls,
  * @return the command
  */
 struct TALER_TESTING_Command
-TALER_TESTING_cmd_check_payment (
-  const char *label,
-  const char *merchant_url,
-  struct GNUNET_CURL_Context *ctx,
-  unsigned int http_status,
-  const char *proposal_reference,
-  unsigned int expect_paid)
+TALER_TESTING_cmd_check_payment (const char *label,
+                                 const char *merchant_url,
+                                 struct GNUNET_CURL_Context *ctx,
+                                 unsigned int http_status,
+                                 const char *proposal_reference,
+                                 unsigned int expect_paid)
 {
   struct CheckPaymentState *cps;
   struct TALER_TESTING_Command cmd;
@@ -430,9 +429,10 @@ TALER_TESTING_cmd_check_payment (
  * @param[in] coins string specifying coins to add to @a pc,
  *            clobbered in the process
  * @param is interpreter state
- * @param amount_with_fee
- * @param amount_without_fee
- * @param refund_fee
+ * @param amount_with_fee total amount to be paid for a contract.
+ * @param amount_without_fee to be removed, there is no
+ *        per-contract fee, only per-coin exists.
+ * @param refund_fee per-contract? per-coin?
  * @return #GNUNET_OK on success
  */
 static int
@@ -454,6 +454,7 @@ build_coins (struct TALER_MERCHANT_PayCoin **pc,
     char *ctok;
     unsigned int ci;
     struct TALER_MERCHANT_PayCoin *icoin;
+    const struct TALER_EXCHANGE_DenomPublicKey *dpk;
 
     /* Token syntax is "LABEL[/NUMBER]" */
     ctok = strchr (token, '/');
@@ -512,6 +513,15 @@ build_coins (struct TALER_MERCHANT_PayCoin **pc,
     icoin->denom_pub = denom_pub->key;
     icoin->denom_sig = *denom_sig;
     icoin->denom_value = *denom_value;
+    icoin->amount_with_fee = *denom_value;
+    
+    GNUNET_assert (NULL != (dpk = TALER_TESTING_find_pk
+      (is->keys, &icoin->denom_value)));
+
+    GNUNET_assert (GNUNET_SYSERR != TALER_amount_subtract
+      (&icoin->amount_without_fee,
+       &icoin->denom_value,
+       &dpk->fee_deposit));
 
     GNUNET_assert
       (GNUNET_OK == TALER_TESTING_get_trait_url
@@ -519,14 +529,6 @@ build_coins (struct TALER_MERCHANT_PayCoin **pc,
 
     GNUNET_assert
       (GNUNET_OK == TALER_string_to_amount
-        (amount_with_fee, &icoin->amount_with_fee));
-
-    GNUNET_assert
-      (GNUNET_OK == TALER_string_to_amount
-        (amount_without_fee, &icoin->amount_without_fee));
-
-    GNUNET_assert
-      (GNUNET_OK == TALER_string_to_amount
         (refund_fee, &icoin->refund_fee));
   }
 
@@ -980,16 +982,15 @@ pay_traits (void *cls,
  * @return the command
  */
 struct TALER_TESTING_Command
-TALER_TESTING_cmd_pay (
-  const char *label,
-  const char *merchant_url,
-  struct GNUNET_CURL_Context *ctx,
-  unsigned int http_status,
-  const char *proposal_reference,
-  const char *coin_reference,
-  const char *amount_with_fee,
-  const char *amount_without_fee,
-  const char *refund_fee)
+TALER_TESTING_cmd_pay (const char *label,
+                       const char *merchant_url,
+                       struct GNUNET_CURL_Context *ctx,
+                       unsigned int http_status,
+                       const char *proposal_reference,
+                       const char *coin_reference,
+                       const char *amount_with_fee,
+                       const char *amount_without_fee,
+                       const char *refund_fee)
 {
   struct PayState *ps;
   struct TALER_TESTING_Command cmd;

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



reply via email to

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