merchant

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

commit de160b1fb8c55f553d87ad7a19f82c143f2a11bc
parent 55e0f3759fe57f2063b66613e46f5107b2212700
Author: Marcello Stanisci <marcello.stanisci@inria.fr>
Date:   Thu,  8 Jun 2017 10:37:35 +0200

get refunds from database, only testing for zero rows returned.

Diffstat:
Msrc/backenddb/plugin_merchantdb_postgres.c | 17+++++++++++------
Msrc/backenddb/test_merchantdb.c | 33++++++++++++++++++++++++++++++---
2 files changed, 41 insertions(+), 9 deletions(-)

diff --git a/src/backenddb/plugin_merchantdb_postgres.c b/src/backenddb/plugin_merchantdb_postgres.c @@ -123,7 +123,7 @@ postgres_initialize (void *cls) ",PRIMARY KEY (order_id, merchant_pub)" ");"), GNUNET_PQ_make_execute ("CREATE TABLE IF NOT EXISTS merchant_refunds (" - " rtransaction_id SERIAL" + " rtransaction_id INT8 NOT NULL" ",h_contract_terms BYTEA NOT NULL" ",coin_pub BYTEA NOT NULL CHECK (LENGTH(coin_pub)=32)" ",reason VARCHAR NOT NULL" @@ -271,6 +271,10 @@ postgres_initialize (void *cls) " ORDER BY row_id DESC, timestamp DESC" " LIMIT $3", 3), + GNUNET_PQ_make_prepare ("find_refunds_from_contract_terms_hash", + "SELECT * FROM merchant_refunds" + " WHERE h_contract_terms=$1", + 1), GNUNET_PQ_make_prepare ("find_contract_terms_by_date_and_range", "SELECT" " contract_terms" @@ -1492,10 +1496,10 @@ postgres_find_deposits_by_wtid (void *cls, * #GNUNET_SYSERR if there were errors talking to the DB */ int -get_refunds_from_contract_terms_hash (void *cls, - const struct GNUNET_HashCode *h_contract_terms, - TALER_MERCHANTDB_RefundCallback rc, - void *rc_cls) +postgres_get_refunds_from_contract_terms_hash (void *cls, + const struct GNUNET_HashCode *h_contract_terms, + TALER_MERCHANTDB_RefundCallback rc, + void *rc_cls) { struct PostgresClosure *pg = cls; @@ -1508,7 +1512,7 @@ get_refunds_from_contract_terms_hash (void *cls, }; result = GNUNET_PQ_exec_prepared (pg->conn, - "FIXME", + "find_refunds_from_contract_terms_hash", params); if (PGRES_TUPLES_OK != PQresultStatus (result)) { @@ -1704,6 +1708,7 @@ libtaler_plugin_merchantdb_postgres_init (void *cls) plugin->find_contract_terms_by_date = &postgres_find_contract_terms_by_date; plugin->find_contract_terms_by_date_and_range = &postgres_find_contract_terms_by_date_and_range; plugin->find_contract_terms_from_hash = &postgres_find_contract_terms_from_hash; + plugin->get_refunds_from_contract_terms_hash = &postgres_get_refunds_from_contract_terms_hash; return plugin; } diff --git a/src/backenddb/test_merchantdb.c b/src/backenddb/test_merchantdb.c @@ -200,6 +200,28 @@ transaction_cb (void *cls, } /** + * Function called with information about a refund. + * + * @param cls closure + * @param coin_pub public coin from which the refund comes from + * @param rtransaction_id identificator of the refund + * @param reason human-readable explaination of the refund + * @param refund_amount refund amount which is being taken from coin_pub + * @param refund_fee cost of this refund operation + */ +void +refund_cb(void *cls, + const struct TALER_CoinSpendPublicKeyP *coin_pub, + uint64_t rtransaction_id, + const char *reason, + const struct TALER_Amount *refund_amount, + const struct TALER_Amount *refund_fee) +{ + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "refund_cb\n"); + /* FIXME, more logic here? */ +} + +/** * Callback for `find_contract_terms_by_date`. * * @param cls closure @@ -485,9 +507,9 @@ run (void *cls) NULL)); FAILIF (GNUNET_OK != plugin->find_transfers_by_hash (plugin->cls, - &h_contract_terms, - &transfer_cb, - NULL)); + &h_contract_terms, + &transfer_cb, + NULL)); FAILIF (GNUNET_OK != plugin->find_deposits_by_wtid (plugin->cls, &wtid, @@ -499,6 +521,11 @@ run (void *cls) &wtid, &proof_cb, NULL)); + FAILIF (GNUNET_NO != + plugin->get_refunds_from_contract_terms_hash (plugin->cls, + &h_contract_terms, + &refund_cb, + NULL)); if (-1 == result) result = 0;