merchant

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

commit 73e2e5a73a1a096c3e66649ffd92261320178614
parent c3916068ea8ccf7c5c26119e08ebb701a2544816
Author: Marcello Stanisci <marcello.stanisci@inria.fr>
Date:   Sun, 16 Jul 2017 12:38:40 +0200

making testcase pass to new "flagged as paid" policy

Diffstat:
Msrc/backenddb/plugin_merchantdb_postgres.c | 34+++++++++++++++++++++++++++++-----
Msrc/backenddb/test_merchantdb.c | 14+++++++++++++-
2 files changed, 42 insertions(+), 6 deletions(-)

diff --git a/src/backenddb/plugin_merchantdb_postgres.c b/src/backenddb/plugin_merchantdb_postgres.c @@ -288,6 +288,15 @@ postgres_initialize (void *cls) " FROM merchant_refunds" " WHERE coin_pub=$1", 1), + GNUNET_PQ_make_prepare ("find_contract_terms_history", + "SELECT" + " contract_terms" + " FROM merchant_contract_terms" + " WHERE" + " order_id=$1" + " AND merchant_pub=$2" + " AND paid=$3", + 3), GNUNET_PQ_make_prepare ("find_contract_terms", "SELECT" " contract_terms" @@ -296,6 +305,7 @@ postgres_initialize (void *cls) " order_id=$1" " AND merchant_pub=$2", 2), + GNUNET_PQ_make_prepare ("find_contract_terms_by_date", "SELECT" " contract_terms" @@ -305,9 +315,10 @@ postgres_initialize (void *cls) " WHERE" " timestamp<$1" " AND merchant_pub=$2" + " AND paid=$4" " ORDER BY row_id DESC, timestamp DESC" " LIMIT $3", - 3), + 4), GNUNET_PQ_make_prepare ("find_refunds_from_contract_terms_hash", "SELECT" " coin_pub" @@ -333,9 +344,10 @@ postgres_initialize (void *cls) " timestamp<$1" " AND merchant_pub=$2" " AND row_id<$3" + " AND paid=$5" " ORDER BY row_id DESC, timestamp DESC" " LIMIT $4", - 4), + 5), GNUNET_PQ_make_prepare ("find_contract_terms_by_date_and_range_future", "SELECT" " contract_terms" @@ -346,9 +358,10 @@ postgres_initialize (void *cls) " timestamp>$1" " AND merchant_pub=$2" " AND row_id>$3" + " AND paid=$5" " ORDER BY row_id DESC, timestamp DESC" " LIMIT $4", - 4), + 5), GNUNET_PQ_make_prepare ("find_transaction", "SELECT" " exchange_uri" @@ -579,7 +592,8 @@ postgres_find_contract_terms_from_hash (void *cls, /** - * Retrieve proposal data given its order id. + * Retrieve proposal data given its order id. Ignores if the + * proposal has been paid or not. * * @param cls closure * @param[out] contract_terms where to store the retrieved contract terms @@ -593,6 +607,7 @@ postgres_find_contract_terms (void *cls, const struct TALER_MerchantPublicKeyP *merchant_pub) { struct PostgresClosure *pg = cls; + struct GNUNET_PQ_QueryParam params[] = { GNUNET_PQ_query_param_string (order_id), GNUNET_PQ_query_param_auto_from_type (merchant_pub), @@ -883,9 +898,12 @@ postgres_find_contract_terms_history (void *cls, struct PostgresClosure *pg = cls; json_t *contract_terms; enum GNUNET_DB_QueryStatus qs; + unsigned int yes = GNUNET_YES; + struct GNUNET_PQ_QueryParam params[] = { GNUNET_PQ_query_param_string (order_id), GNUNET_PQ_query_param_auto_from_type (merchant_pub), + GNUNET_PQ_query_param_auto_from_type (&yes), GNUNET_PQ_query_param_end }; struct GNUNET_PQ_ResultSpec rs[] = { @@ -895,7 +913,7 @@ postgres_find_contract_terms_history (void *cls, }; qs = GNUNET_PQ_eval_prepared_singleton_select (pg->conn, - "find_contract_terms", + "find_contract_terms_history", params, rs); if (qs <= 0) @@ -1016,11 +1034,14 @@ postgres_find_contract_terms_by_date_and_range (void *cls, void *cb_cls) { struct PostgresClosure *pg = cls; + unsigned int yes = GNUNET_YES; + struct GNUNET_PQ_QueryParam params[] = { GNUNET_PQ_query_param_absolute_time (&date), GNUNET_PQ_query_param_auto_from_type (merchant_pub), GNUNET_PQ_query_param_uint64 (&start), GNUNET_PQ_query_param_uint64 (&nrows), + GNUNET_PQ_query_param_auto_from_type (&yes), GNUNET_PQ_query_param_end }; const char *stmt; @@ -1068,10 +1089,13 @@ postgres_find_contract_terms_by_date (void *cls, void *cb_cls) { struct PostgresClosure *pg = cls; + unsigned int yes = GNUNET_YES; + struct GNUNET_PQ_QueryParam params[] = { GNUNET_PQ_query_param_absolute_time (&date), GNUNET_PQ_query_param_auto_from_type (merchant_pub), GNUNET_PQ_query_param_uint64 (&nrows), + GNUNET_PQ_query_param_auto_from_type (&yes), GNUNET_PQ_query_param_end }; enum GNUNET_DB_QueryStatus qs; diff --git a/src/backenddb/test_merchantdb.c b/src/backenddb/test_merchantdb.c @@ -84,7 +84,7 @@ struct GNUNET_HashCode h_contract_terms; /** * Proposal's hash. */ -struct GNUNET_HashCode h_contract_terms; +struct GNUNET_HashCode h_contract_terms_future; /** * Time of the transaction. @@ -462,6 +462,11 @@ run (void *cls) timestamp, contract_terms)); + FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT != + plugin->mark_proposal_paid (plugin->cls, + &h_contract_terms, + &merchant_pub)); + json_t *out; FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT != @@ -503,6 +508,13 @@ run (void *cls) fake_now = GNUNET_TIME_absolute_subtract (timestamp, delta); + TALER_JSON_hash (contract_terms_future, + &h_contract_terms_future); + + FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT != + plugin->mark_proposal_paid (plugin->cls, + &h_contract_terms_future, + &merchant_pub)); FAILIF (2 != plugin->find_contract_terms_by_date_and_range (plugin->cls, fake_now,