merchant

Merchant backend to process payments, run by merchants
Log | Files | Refs | Submodules | README | LICENSE

commit bd79ca83a26aec30d5b5e60ef573b56d5f8c8645
parent 6efeffdd62f2b599ffaf219e741592bcdd103b46
Author: Marcello Stanisci <marcello.stanisci@inria.fr>
Date:   Tue, 13 Jun 2017 20:50:26 +0200

- only commit refund if amount refunded per coin is > zero
- add valid second refund increasing

Diffstat:
Msrc/backenddb/plugin_merchantdb_postgres.c | 46+++++++++++++++++++++++++++-------------------
Msrc/backenddb/test_merchantdb.c | 19++++++++++++++++++-
2 files changed, 45 insertions(+), 20 deletions(-)

diff --git a/src/backenddb/plugin_merchantdb_postgres.c b/src/backenddb/plugin_merchantdb_postgres.c @@ -2002,22 +2002,24 @@ process_deposits_cb (void *cls, /*Always commit the smallest as refund*/ - if (1 != insert_refund (ctx->pg, - ctx->h_contract_terms, - &coin_pub, - ctx->reason, - small)) - { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Could not commit refund worth %s for coin '%s'" - ", as of contract/reason: %s/%s\n", - TALER_amount_to_string (small), - TALER_B2S (&coin_pub), - GNUNET_h2s (ctx->h_contract_terms), - ctx->reason); - ctx->err = GNUNET_SYSERR; - return; - } + if ( (0 != small->value) || (0 != small->fraction) ) + if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT != + insert_refund (ctx->pg, + ctx->h_contract_terms, + &coin_pub, + ctx->reason, + small)) + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Could not commit refund worth %s for coin '%s'" + ", as of contract/reason: %s/%s\n", + TALER_amount_to_string (small), + TALER_B2S (&coin_pub), + GNUNET_h2s (ctx->h_contract_terms), + ctx->reason); + ctx->err = GNUNET_SYSERR; + return; + } GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Detracting %s as refund, from coin %s\n", @@ -2029,15 +2031,21 @@ process_deposits_cb (void *cls, if ( (0 == ctx->refund->value) && (0 == ctx->refund->fraction) ) + { + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + "All refund amount has been allocated\n"); break; + } } - if (-1 == TALER_amount_cmp (&attempted_refund, &previous_refund)) + if (-1 == TALER_amount_cmp (&attempted_refund, + &previous_refund)) { - GNUNET_log (GNUNET_ERROR_TYPE_INFO, - "Attempted refund lesser than the previous awarded one. %s vs %s\n", + GNUNET_log (GNUNET_ERROR_TYPE_WARNING, + "Attempted refund lesser than the previous" + "awarded one. %s vs %s\n", TALER_amount_to_string (&attempted_refund), TALER_amount_to_string (&previous_refund)); ctx->err = GNUNET_NO; diff --git a/src/backenddb/test_merchantdb.c b/src/backenddb/test_merchantdb.c @@ -128,6 +128,13 @@ static struct TALER_Amount refund_amount; */ static struct TALER_Amount little_refund_amount; + +/** + * Amount to be refunded in a call which is subsequent + * to the good one, expected to succeed. + */ +static struct TALER_Amount right_second_refund_amount; + /** * Public key of the coin. Set to some random value. */ @@ -387,7 +394,7 @@ run (void *cls) refund_deadline = GNUNET_TIME_absolute_get(); GNUNET_TIME_round_abs (&refund_deadline); GNUNET_assert (GNUNET_OK == - TALER_string_to_amount (CURRENCY ":10", + TALER_string_to_amount (CURRENCY ":2", &amount_with_fee)); GNUNET_assert (GNUNET_OK == TALER_string_to_amount (CURRENCY ":0.000010", @@ -401,6 +408,9 @@ run (void *cls) GNUNET_assert (GNUNET_OK == TALER_string_to_amount (CURRENCY ":1", &little_refund_amount)); + GNUNET_assert (GNUNET_OK == + TALER_string_to_amount (CURRENCY ":4", + &right_second_refund_amount)); RND_BLK (&coin_pub); deposit_proof = json_object (); GNUNET_assert (0 == @@ -563,6 +573,13 @@ run (void *cls) &merchant_pub, &little_refund_amount, "make refund testing fail")); + FAILIF (GNUNET_OK != + plugin->increase_refund_for_contract (plugin->cls, + &h_contract_terms, + &merchant_pub, + &right_second_refund_amount, + "make refund testing fail")); + if (-1 == result) result = 0;