merchant

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

commit 521aa89e5bca18cab12d8872bfccea5de11f48ce
parent 419ae31e828cde39879bd68db438853ba5f19735
Author: Marcello Stanisci <marcello.stanisci@inria.fr>
Date:   Thu, 13 Oct 2016 18:06:36 +0200

Fix select payments from DB. Namely, a merchant_pub query parameter was needed

Diffstat:
Msrc/backend/taler-merchant-httpd_pay.c | 21+++++++++++----------
Msrc/backend/taler-merchant-httpd_track-transaction.c | 9+++++----
Msrc/backend/taler-merchant-httpd_track-transfer.c | 36++++++++++++++++++++++++++++++++----
Msrc/backenddb/plugin_merchantdb_postgres.c | 18+++++++++++-------
Msrc/backenddb/test_merchantdb.c | 9+++++----
Msrc/include/taler_merchantdb_plugin.h | 10++++++----
6 files changed, 70 insertions(+), 33 deletions(-)

diff --git a/src/backend/taler-merchant-httpd_pay.c b/src/backend/taler-merchant-httpd_pay.c @@ -1083,10 +1083,11 @@ MH_handler_pay (struct TMH_RequestHandler *rh, /* Check if this payment attempt has already succeeded */ if (GNUNET_SYSERR == - db->find_payments_by_id (db->cls, - pc->transaction_id, - &check_coin_paid, - pc)) + db->find_payments (db->cls, + pc->transaction_id, + &pc->mi->pubkey, + &check_coin_paid, + pc)) { GNUNET_break (0); json_decref (root); @@ -1116,12 +1117,12 @@ MH_handler_pay (struct TMH_RequestHandler *rh, pc->transaction_id, &pc->mi->pubkey, &check_transaction_exists, - pc)) - - GNUNET_break (0); - json_decref (root); - return TMH_RESPONSE_reply_internal_error (connection, - "Merchant database error"); + pc)) + { + GNUNET_break (0); + json_decref (root); + return TMH_RESPONSE_reply_internal_error (connection, + "Merchant database error"); } if (GNUNET_SYSERR == pc->transaction_exits) { diff --git a/src/backend/taler-merchant-httpd_track-transaction.c b/src/backend/taler-merchant-httpd_track-transaction.c @@ -885,10 +885,11 @@ MH_handler_track_transaction (struct TMH_RequestHandler *rh, return TMH_RESPONSE_reply_internal_error (connection, "Database error"); } - ret = db->find_payments_by_id (db->cls, - transaction_id, - &coin_cb, - tctx); + ret = db->find_payments (db->cls, + transaction_id, + &tctx->mi->pubkey, + &coin_cb, + tctx); if (GNUNET_SYSERR == ret) { GNUNET_break (0); diff --git a/src/backend/taler-merchant-httpd_track-transfer.c b/src/backend/taler-merchant-httpd_track-transfer.c @@ -258,6 +258,7 @@ wire_transfer_cb (void *cls, struct TrackTransferContext *rctx = cls; unsigned int i; int ret; + struct TALER_MerchantPublicKeyP merchant_pub; rctx->wdh = NULL; GNUNET_log (GNUNET_ERROR_TYPE_INFO, @@ -274,6 +275,32 @@ wire_transfer_cb (void *cls, return; } + struct GNUNET_JSON_Specification spec[] = { + GNUNET_JSON_spec_fixed_auto ("merchant_pub", &merchant_pub.eddsa_pub), + GNUNET_JSON_spec_end () + }; + const char *error_name; + unsigned int error_line; + + if (GNUNET_SYSERR == GNUNET_JSON_parse (json, + spec, + &error_name, + &error_line)) + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Exchange did not give any merchant key in response\n"); + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Gotten json: %s\n", + json_dumps (json, JSON_INDENT (2))); + resume_track_transfer_with_response + (rctx, + MHD_HTTP_INTERNAL_SERVER_ERROR, + TMH_RESPONSE_make_internal_error ("The exchange did not include merchant key in response\n")); + return; + + } + + /*TODO Extract merchant_pub from json */ if (GNUNET_OK != db->store_transfer_to_proof (db->cls, rctx->uri, @@ -290,10 +317,11 @@ wire_transfer_cb (void *cls, { rctx->current_detail = &details[i]; rctx->check_transfer_result = GNUNET_NO; - ret = db->find_payments_by_id (db->cls, - details[i].transaction_id, - &check_transfer, - rctx); + ret = db->find_payments (db->cls, + details[i].transaction_id, + &merchant_pub, + &check_transfer, + rctx); if (GNUNET_SYSERR == ret) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, diff --git a/src/backenddb/plugin_merchantdb_postgres.c b/src/backenddb/plugin_merchantdb_postgres.c @@ -306,8 +306,9 @@ postgres_initialize (void *cls) ",deposit_fee_curr" ",exchange_proof" " FROM merchant_deposits" - " WHERE transaction_id=$1", - 1); + " WHERE transaction_id=$1" + " AND merchant_pub=$2", + 2); PG_PREPARE (pg, "find_transfers_by_transaction_id", "SELECT" @@ -750,16 +751,18 @@ postgres_find_transaction (void *cls, * * @param cls closure * @param transaction_id key for the search + * @param merchant_pub merchant's public key * @param cb function to call with payment data * @param cb_cls closure for @a cb * @return #GNUNET_OK on success, #GNUNET_NO if transaction Id is unknown, * #GNUNET_SYSERR on hard errors */ static int -postgres_find_payments_by_id (void *cls, - uint64_t transaction_id, - TALER_MERCHANTDB_CoinDepositCallback cb, - void *cb_cls) +postgres_find_payments (void *cls, + uint64_t transaction_id, + const struct TALER_MerchantPublicKeyP *merchant_pub, + TALER_MERCHANTDB_CoinDepositCallback cb, + void *cb_cls) { struct PostgresClosure *pg = cls; PGresult *result; @@ -767,6 +770,7 @@ postgres_find_payments_by_id (void *cls, struct GNUNET_PQ_QueryParam params[] = { GNUNET_PQ_query_param_uint64 (&transaction_id), + GNUNET_PQ_query_param_auto_from_type (merchant_pub), GNUNET_PQ_query_param_end }; result = GNUNET_PQ_exec_prepared (pg->conn, @@ -1117,7 +1121,7 @@ libtaler_plugin_merchantdb_postgres_init (void *cls) plugin->store_transfer_to_proof = &postgres_store_transfer_to_proof; plugin->find_transaction = &postgres_find_transaction; plugin->find_transactions_by_date = &postgres_find_transactions_by_date; - plugin->find_payments_by_id = &postgres_find_payments_by_id; + plugin->find_payments = &postgres_find_payments; plugin->find_transfers_by_id = &postgres_find_transfers_by_id; plugin->find_deposits_by_wtid = &postgres_find_deposits_by_wtid; plugin->find_proof_by_wtid = &postgres_find_proof_by_wtid; diff --git a/src/backenddb/test_merchantdb.c b/src/backenddb/test_merchantdb.c @@ -381,10 +381,11 @@ run (void *cls) NULL)); FAILIF (GNUNET_OK != - plugin->find_payments_by_id (plugin->cls, - transaction_id, - &deposit_cb, - NULL)); + plugin->find_payments (plugin->cls, + transaction_id, + &merchant_pub, + &deposit_cb, + NULL)); FAILIF (GNUNET_OK != plugin->find_transfers_by_id (plugin->cls, transaction_id, diff --git a/src/include/taler_merchantdb_plugin.h b/src/include/taler_merchantdb_plugin.h @@ -276,16 +276,18 @@ struct TALER_MERCHANTDB_Plugin * * @param cls closure * @param transaction_id key for the search + * @param merchant_pub merchant's public key * @param cb function to call with payment data * @param cb_cls closure for @a cb * @return #GNUNET_OK on success, #GNUNET_NO if transaction Id is unknown, * #GNUNET_SYSERR on hard errors */ int - (*find_payments_by_id) (void *cls, - uint64_t transaction_id, - TALER_MERCHANTDB_CoinDepositCallback cb, - void *cb_cls); + (*find_payments) (void *cls, + uint64_t transaction_id, + const struct TALER_MerchantPublicKeyP *merchant_pub, + TALER_MERCHANTDB_CoinDepositCallback cb, + void *cb_cls); /**