merchant

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

commit 9f8b9743f382ee627439634369788489248c9a41
parent ff8fdfa0ec4f617993d385bb4258fb0538156c20
Author: Christian Grothoff <christian@grothoff.org>
Date:   Sat, 15 Oct 2016 03:14:23 +0200

resolving merge conflict with Marcello, mostly exactly the same changes

Diffstat:
Msrc/backend/taler-merchant-httpd_pay.c | 216++++++++++++++++++++++++++++++++++++++++----------------------------------------
Msrc/backend/taler-merchant-httpd_track-transaction.c | 10+++++-----
Msrc/backenddb/plugin_merchantdb_postgres.c | 14+++++++-------
Msrc/backenddb/test_merchantdb.c | 10+++++-----
Msrc/include/taler_merchantdb_plugin.h | 11+++++------
5 files changed, 130 insertions(+), 131 deletions(-)

diff --git a/src/backend/taler-merchant-httpd_pay.c b/src/backend/taler-merchant-httpd_pay.c @@ -797,35 +797,35 @@ check_coin_paid (void *cls, */ static void check_transaction_exists (void *cls, - uint64_t transaction_id, - const struct TALER_MerchantPublicKeyP *merchant_pub, - const char *exchange_uri, - const struct GNUNET_HashCode *h_contract, - const struct GNUNET_HashCode *h_xwire, - struct GNUNET_TIME_Absolute timestamp, - struct GNUNET_TIME_Absolute refund, - const struct TALER_Amount *total_amount) + uint64_t transaction_id, + const struct TALER_MerchantPublicKeyP *merchant_pub, + const char *exchange_uri, + const struct GNUNET_HashCode *h_contract, + const struct GNUNET_HashCode *h_xwire, + struct GNUNET_TIME_Absolute timestamp, + struct GNUNET_TIME_Absolute refund, + const struct TALER_Amount *total_amount) { struct PayContext *pc = cls; if ( (0 == memcmp (h_contract, - &pc->h_contract, - sizeof (struct GNUNET_HashCode))) && + &pc->h_contract, + sizeof (struct GNUNET_HashCode))) && (0 == memcmp (h_xwire, - &pc->mi->h_wire, - sizeof (struct GNUNET_HashCode))) && + &pc->mi->h_wire, + sizeof (struct GNUNET_HashCode))) && (timestamp.abs_value_us == pc->timestamp.abs_value_us) && (refund.abs_value_us == pc->refund_deadline.abs_value_us) && (0 == TALER_amount_cmp (total_amount, - &pc->amount) ) ) + &pc->amount) ) ) { pc->transaction_exits = GNUNET_YES; } else - { - GNUNET_break_op (0); - pc->transaction_exits = GNUNET_SYSERR; - } + { + GNUNET_break_op (0); + pc->transaction_exits = GNUNET_SYSERR; + } } extern struct MerchantInstance * @@ -846,17 +846,17 @@ get_instance (struct json_t *json); */ int MH_handler_pay (struct TMH_RequestHandler *rh, - struct MHD_Connection *connection, - void **connection_cls, - const char *upload_data, - size_t *upload_data_size) + struct MHD_Connection *connection, + void **connection_cls, + const char *upload_data, + size_t *upload_data_size) { struct PayContext *pc; int res; json_t *root; GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "In handler for /pay.\n"); + "In handler for /pay.\n"); if (NULL == *connection_cls) { pc = GNUNET_new (struct PayContext); @@ -878,35 +878,35 @@ MH_handler_pay (struct TMH_RequestHandler *rh, return MHD_NO; /* hard error */ } res = MHD_queue_response (connection, - pc->response_code, - pc->response); + pc->response_code, + pc->response); if (NULL != pc->response) { MHD_destroy_response (pc->response); pc->response = NULL; } GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Queueing response (%u) for /pay (%s).\n", - (unsigned int) pc->response_code, - res ? "OK" : "FAILED"); + "Queueing response (%u) for /pay (%s).\n", + (unsigned int) pc->response_code, + res ? "OK" : "FAILED"); return res; } if (NULL != pc->chosen_exchange) { GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Shouldn't be here. Old MHD version?\n"); + "Shouldn't be here. Old MHD version?\n"); return MHD_YES; } res = TMH_PARSE_post_json (connection, - &pc->json_parse_context, - upload_data, - upload_data_size, - &root); + &pc->json_parse_context, + upload_data, + upload_data_size, + &root); if (GNUNET_SYSERR == res) { GNUNET_break (0); return TMH_RESPONSE_reply_external_error (connection, - "failed to parse JSON body"); + "failed to parse JSON body"); } if ((GNUNET_NO == res) || (NULL == root)) return MHD_YES; /* the POST's body has to be further fetched */ @@ -935,95 +935,95 @@ MH_handler_pay (struct TMH_RequestHandler *rh, }; res = TMH_PARSE_json_data (connection, - root, - spec); + root, + spec); if (GNUNET_YES != res) { json_decref (root); GNUNET_break (0); return (GNUNET_NO == res) ? MHD_YES : MHD_NO; } - pc->mi = mi; + pc->mi = get_instance (root); GNUNET_log (GNUNET_ERROR_TYPE_INFO, - "/pay: picked instance %s\n", - pc->mi->id); + "/pay: picked instance %s\n", + pc->mi->id); if (NULL == pc->mi) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Not able to find the specified receiver\n"); + "Not able to find the specified receiver\n"); json_decref (root); return TMH_RESPONSE_reply_external_error (connection, - "Unknown receiver given"); + "Unknown receiver given"); } GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "The receiver for this deposit is '%s', whose bank details are '%s'\n", - pc->mi->id, - json_dumps (pc->mi->j_wire, JSON_COMPACT)); + "The receiver for this deposit is '%s', whose bank details are '%s'\n", + pc->mi->id, + json_dumps (pc->mi->j_wire, JSON_COMPACT)); pc->chosen_exchange = GNUNET_strdup (chosen_exchange); GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Parsed JSON for /pay.\n"); + "Parsed JSON for /pay.\n"); cp.purpose.purpose = htonl (TALER_SIGNATURE_MERCHANT_CONTRACT); cp.purpose.size = htonl (sizeof (struct TALER_ContractPS)); cp.transaction_id = GNUNET_htonll (pc->transaction_id); TALER_amount_hton (&cp.total_amount, - &pc->amount); + &pc->amount); TALER_amount_hton (&cp.max_fee, - &pc->max_fee); + &pc->max_fee); cp.h_contract = pc->h_contract; cp.merchant_pub = pc->mi->pubkey; if (GNUNET_OK != - GNUNET_CRYPTO_eddsa_verify (TALER_SIGNATURE_MERCHANT_CONTRACT, - &cp.purpose, - &merchant_sig.eddsa_sig, - &pc->mi->pubkey.eddsa_pub)) + GNUNET_CRYPTO_eddsa_verify (TALER_SIGNATURE_MERCHANT_CONTRACT, + &cp.purpose, + &merchant_sig.eddsa_sig, + &pc->mi->pubkey.eddsa_pub)) { GNUNET_break (0); GNUNET_JSON_parse_free (spec); json_decref (root); return TMH_RESPONSE_reply_external_error (connection, - "invalid merchant signature supplied"); + "invalid merchant signature supplied"); } /* 'wire_transfer_deadline' is optional, if it is not present, generate it here; it will be timestamp plus the wire_transfer_delay supplied in config file */ if (NULL == json_object_get (root, - "wire_transfer_deadline")) + "wire_transfer_deadline")) { pc->wire_transfer_deadline = GNUNET_TIME_absolute_add (pc->timestamp, - wire_transfer_delay); + wire_transfer_delay); if (pc->wire_transfer_deadline.abs_value_us < pc->refund_deadline.abs_value_us) { - /* Refund value very large, delay wire transfer accordingly */ - pc->wire_transfer_deadline = pc->refund_deadline; + /* Refund value very large, delay wire transfer accordingly */ + pc->wire_transfer_deadline = pc->refund_deadline; } } else { struct GNUNET_JSON_Specification espec[] = { - GNUNET_JSON_spec_absolute_time ("wire_transfer_deadline", - &pc->wire_transfer_deadline), - GNUNET_JSON_spec_end() + GNUNET_JSON_spec_absolute_time ("wire_transfer_deadline", + &pc->wire_transfer_deadline), + GNUNET_JSON_spec_end() }; res = TMH_PARSE_json_data (connection, - root, - espec); + root, + espec); if (GNUNET_YES != res) { - GNUNET_JSON_parse_free (spec); - json_decref (root); - GNUNET_break (0); - return (GNUNET_NO == res) ? MHD_YES : MHD_NO; + GNUNET_JSON_parse_free (spec); + json_decref (root); + GNUNET_break (0); + return (GNUNET_NO == res) ? MHD_YES : MHD_NO; } if (pc->wire_transfer_deadline.abs_value_us < pc->refund_deadline.abs_value_us) { - GNUNET_break (0); - GNUNET_JSON_parse_free (spec); - json_decref (root); - return TMH_RESPONSE_reply_external_error (connection, - "refund deadline after wire transfer deadline"); + GNUNET_break (0); + GNUNET_JSON_parse_free (spec); + json_decref (root); + return TMH_RESPONSE_reply_external_error (connection, + "refund deadline after wire transfer deadline"); } } @@ -1034,46 +1034,46 @@ MH_handler_pay (struct TMH_RequestHandler *rh, GNUNET_JSON_parse_free (spec); json_decref (root); return TMH_RESPONSE_reply_external_error (connection, - "no coins given"); + "no coins given"); } /* note: 1 coin = 1 deposit confirmation expected */ pc->dc = GNUNET_new_array (pc->coins_cnt, - struct DepositConfirmation); + struct DepositConfirmation); /* This loop populates the array 'dc' in 'pc' */ json_array_foreach (coins, coins_index, coin) { struct DepositConfirmation *dc = &pc->dc[coins_index]; struct GNUNET_JSON_Specification spec[] = { - TALER_JSON_spec_denomination_public_key ("denom_pub", &dc->denom), - TALER_JSON_spec_amount ("f" /* FIXME */, &dc->amount_with_fee), - GNUNET_JSON_spec_fixed_auto ("coin_pub", &dc->coin_pub), - TALER_JSON_spec_denomination_signature ("ub_sig", &dc->ub_sig), - GNUNET_JSON_spec_fixed_auto ("coin_sig", &dc->coin_sig), - GNUNET_JSON_spec_end() + TALER_JSON_spec_denomination_public_key ("denom_pub", &dc->denom), + TALER_JSON_spec_amount ("f" /* FIXME */, &dc->amount_with_fee), + GNUNET_JSON_spec_fixed_auto ("coin_pub", &dc->coin_pub), + TALER_JSON_spec_denomination_signature ("ub_sig", &dc->ub_sig), + GNUNET_JSON_spec_fixed_auto ("coin_sig", &dc->coin_sig), + GNUNET_JSON_spec_end() }; res = TMH_PARSE_json_data (connection, - coin, - spec); + coin, + spec); if (GNUNET_YES != res) { - GNUNET_JSON_parse_free (spec); - json_decref (root); - GNUNET_break (0); - return (GNUNET_NO == res) ? MHD_YES : MHD_NO; + GNUNET_JSON_parse_free (spec); + json_decref (root); + GNUNET_break (0); + return (GNUNET_NO == res) ? MHD_YES : MHD_NO; } { - char *s; - - s = TALER_amount_to_string (&dc->amount_with_fee); - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Coin #%i has f %s\n", - coins_index, - s); - GNUNET_free (s); - } + char *s; + + s = TALER_amount_to_string (&dc->amount_with_fee); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Coin #%i has f %s\n", + coins_index, + s); + GNUNET_free (s); + } dc->index = coins_index; dc->pc = pc; @@ -1084,16 +1084,16 @@ 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, - &mi->pubkey, - &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); return TMH_RESPONSE_reply_internal_error (connection, - "Merchant database error"); + "Merchant database error"); } if (0 == pc->pending) { @@ -1103,11 +1103,11 @@ MH_handler_pay (struct TMH_RequestHandler *rh, /* Payment succeeded in the past; take short cut and accept immediately */ resp = MHD_create_response_from_buffer (0, - NULL, - MHD_RESPMEM_PERSISTENT); + NULL, + MHD_RESPMEM_PERSISTENT); ret = MHD_queue_response (connection, - MHD_HTTP_OK, - resp); + MHD_HTTP_OK, + resp); MHD_destroy_response (resp); json_decref (root); return ret; @@ -1115,15 +1115,15 @@ MH_handler_pay (struct TMH_RequestHandler *rh, /* Check if transaction is already known, if not store it. */ if (GNUNET_SYSERR == db->find_transaction (db->cls, - pc->transaction_id, - &pc->mi->pubkey, - &check_transaction_exists, + 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"); + "Merchant database error"); } if (GNUNET_SYSERR == pc->transaction_exits) { @@ -1137,7 +1137,7 @@ MH_handler_pay (struct TMH_RequestHandler *rh, if (GNUNET_OK != db->store_transaction (db->cls, pc->transaction_id, - &pc->mi->pubkey, + &pc->mi->pubkey, pc->chosen_exchange, &pc->h_contract, &pc->mi->h_wire, @@ -1148,7 +1148,7 @@ MH_handler_pay (struct TMH_RequestHandler *rh, GNUNET_break (0); json_decref (root); return TMH_RESPONSE_reply_internal_error (connection, - "Merchant database error"); + "Merchant database error"); } } diff --git a/src/backend/taler-merchant-httpd_track-transaction.c b/src/backend/taler-merchant-httpd_track-transaction.c @@ -912,11 +912,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, - &tctx->mi->pubkey, - &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/backenddb/plugin_merchantdb_postgres.c b/src/backenddb/plugin_merchantdb_postgres.c @@ -766,18 +766,18 @@ postgres_find_transaction (void *cls, * * @param cls closure * @param transaction_id key for the search - * @param merchant_pub public key of the merchant + * @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, - const struct TALER_MerchantPublicKeyP *merchant_pub, - 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; @@ -1223,8 +1223,8 @@ 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_by_id_and_coin = &postgres_find_payments_by_id_and_coin; + 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,11 +381,11 @@ run (void *cls) NULL)); FAILIF (GNUNET_OK != - plugin->find_payments_by_id (plugin->cls, - transaction_id, - &merchant_pub, - &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 @@ -285,12 +285,11 @@ struct TALER_MERCHANTDB_Plugin * #GNUNET_SYSERR on hard errors */ int - (*find_payments_by_id) (void *cls, - uint64_t transaction_id, - const struct TALER_MerchantPublicKeyP *merchant_pub, - 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); /** * Lookup information about coin payments by transaction ID and coin.