summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2020-05-17 22:52:27 +0200
committerChristian Grothoff <christian@grothoff.org>2020-05-17 22:52:27 +0200
commitdc6a6c0ad87a34198a49ea31b39c2eb2bd1e0acb (patch)
tree6a0c706c619a3ada56b7d8bf4169be9b5af48fca /src
parentde6225f820a6e1627786874d8df9df99b5f5e4bc (diff)
downloadmerchant-dc6a6c0ad87a34198a49ea31b39c2eb2bd1e0acb.tar.gz
merchant-dc6a6c0ad87a34198a49ea31b39c2eb2bd1e0acb.tar.bz2
merchant-dc6a6c0ad87a34198a49ea31b39c2eb2bd1e0acb.zip
misc. fixes
Diffstat (limited to 'src')
-rw-r--r--src/backend/taler-merchant-httpd.c2
-rw-r--r--src/backend/taler-merchant-httpd.h9
-rw-r--r--src/backend/taler-merchant-httpd_exchanges.c9
-rw-r--r--src/backend/taler-merchant-httpd_private-post-orders.c3
-rw-r--r--src/backenddb/merchant-0001.sql2
-rw-r--r--src/backenddb/plugin_merchantdb_postgres.c136
-rw-r--r--src/lib/merchant_api_post_orders.c4
-rw-r--r--src/testing/test_merchant_api.c4
8 files changed, 92 insertions, 77 deletions
diff --git a/src/backend/taler-merchant-httpd.c b/src/backend/taler-merchant-httpd.c
index e3640112..b280386b 100644
--- a/src/backend/taler-merchant-httpd.c
+++ b/src/backend/taler-merchant-httpd.c
@@ -1077,7 +1077,7 @@ url_handler (void *cls,
else
{
infix_strlen = slash - infix_url;
- suffix_url = slash;
+ suffix_url = slash + 1; /* skip the '/' */
suffix_strlen = strlen (suffix_url);
}
hc->infix = GNUNET_strndup (infix_url,
diff --git a/src/backend/taler-merchant-httpd.h b/src/backend/taler-merchant-httpd.h
index ceb7dfe2..7e1090d3 100644
--- a/src/backend/taler-merchant-httpd.h
+++ b/src/backend/taler-merchant-httpd.h
@@ -151,7 +151,11 @@ struct TMH_RequestHandler
{
/**
- * URL prefix the handler is for.
+ * URL prefix the handler is for, includes the '/',
+ * so "/orders" or "/products". Does *not* include
+ * "/private", that is controlled by the array in which
+ * the handler is defined. Must not contain any
+ * '/' except for the leading '/'.
*/
const char *url_prefix;
@@ -168,7 +172,8 @@ struct TMH_RequestHandler
bool skip_instance;
/**
- * URL suffix the handler is for.
+ * URL suffix the handler is for, excludes the '/',
+ * so "pay" or "claim", not "/pay".
*/
const char *url_suffix;
diff --git a/src/backend/taler-merchant-httpd_exchanges.c b/src/backend/taler-merchant-httpd_exchanges.c
index ef5bde94..fe4085d0 100644
--- a/src/backend/taler-merchant-httpd_exchanges.c
+++ b/src/backend/taler-merchant-httpd_exchanges.c
@@ -498,6 +498,7 @@ get_wire_fees (struct Exchange *exchange,
for (struct FeesByWireMethod *fbw = exchange->wire_fees_head;
NULL != fbw;
fbw = fbw->next)
+ {
if (0 == strcasecmp (fbw->wire_method,
wire_method) )
{
@@ -512,6 +513,10 @@ get_wire_fees (struct Exchange *exchange,
}
return af;
}
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Exchange supports `%s' as a wire method (but we do not use that one)\n",
+ fbw->wire_method);
+ }
return NULL;
}
@@ -551,6 +556,9 @@ process_find_operations (struct Exchange *exchange)
if (NULL == af)
{
need_wire = GNUNET_YES;
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Exchange does not support `%s' wire method (will retry later)\n",
+ fo->wire_method);
continue;
}
if (af->start_date.abs_value_us > now.abs_value_us)
@@ -688,6 +696,7 @@ handle_wire_data (void *cls,
exchange->wire_retry_delay = RETRY_BACKOFF (exchange->wire_retry_delay);
GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
"Exchange does not support our wire method. Retrying in %s\n",
+
GNUNET_STRINGS_relative_time_to_string (
exchange->wire_retry_delay,
GNUNET_YES));
diff --git a/src/backend/taler-merchant-httpd_private-post-orders.c b/src/backend/taler-merchant-httpd_private-post-orders.c
index e6af2583..7c6a0c39 100644
--- a/src/backend/taler-merchant-httpd_private-post-orders.c
+++ b/src/backend/taler-merchant-httpd_private-post-orders.c
@@ -930,12 +930,13 @@ TMH_private_post_orders (const struct TMH_RequestHandler *rh,
struct TMH_HandlerContext *hc)
{
json_t *order;
- const char *payment_target;
+ const char *payment_target = NULL;
unsigned int ips_len = 0;
struct InventoryProduct *ips = NULL;
unsigned int uuids_len = 0;
struct GNUNET_Uuid *uuids = NULL;
+ (void) rh;
order = json_object_get (hc->request_body,
"order");
if (NULL == order)
diff --git a/src/backenddb/merchant-0001.sql b/src/backenddb/merchant-0001.sql
index 9eb60e5c..5d502802 100644
--- a/src/backenddb/merchant-0001.sql
+++ b/src/backenddb/merchant-0001.sql
@@ -236,7 +236,7 @@ CREATE TABLE IF NOT EXISTS merchant_contract_terms
,paid BOOLEAN DEFAULT FALSE NOT NULL
,wired BOOLEAN DEFAULT FALSE NOT NULL
,fulfillment_url VARCHAR NOT NULL
- ,session_id VARCHAR NOT NULL
+ ,session_id VARCHAR DEFAULT '' NOT NULL
,UNIQUE (merchant_serial, order_id)
,UNIQUE (merchant_serial, h_contract_terms)
);
diff --git a/src/backenddb/plugin_merchantdb_postgres.c b/src/backenddb/plugin_merchantdb_postgres.c
index 8c1646a7..c69507d6 100644
--- a/src/backenddb/plugin_merchantdb_postgres.c
+++ b/src/backenddb/plugin_merchantdb_postgres.c
@@ -3646,7 +3646,6 @@ postgres_lookup_transfers (void *cls,
by_time = ( (before.abs_value_us !=
GNUNET_TIME_UNIT_FOREVER_ABS.abs_value_us) ||
(after.abs_value_us != GNUNET_TIME_UNIT_ZERO_ABS.abs_value_us) );
-
check_connection (pg);
GNUNET_snprintf (stmt,
sizeof (stmt),
@@ -3657,8 +3656,6 @@ postgres_lookup_transfers (void *cls,
params = (by_time)
? ( (NULL != payto_uri) ? params_payto_et : params_et)
: ( (NULL != payto_uri) ? params_payto : params_none);
-
- // FIXME: write SQL (_desc-variant!)
qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn,
stmt,
params,
@@ -3670,6 +3667,58 @@ postgres_lookup_transfers (void *cls,
}
+/**
+ * Store information about wire fees charged by an exchange,
+ * including signature (so we have proof).
+ *
+ * @param cls closure
+ * @paramm exchange_pub public key of the exchange
+ * @param h_wire_method hash of wire method
+ * @param wire_fee wire fee charged
+ * @param closing_fee closing fee charged (irrelevant for us,
+ * but needed to check signature)
+ * @param start_date start of fee being used
+ * @param end_date end of fee being used
+ * @param exchange_sig signature of exchange over fee structure
+ * @return transaction status code
+ */
+static enum GNUNET_DB_QueryStatus
+postgres_store_wire_fee_by_exchange (
+ void *cls,
+ const struct TALER_MasterPublicKeyP *master_pub,
+ const struct GNUNET_HashCode *h_wire_method,
+ const struct TALER_Amount *wire_fee,
+ const struct TALER_Amount *closing_fee,
+ struct GNUNET_TIME_Absolute start_date,
+ struct GNUNET_TIME_Absolute end_date,
+ const struct
+ TALER_MasterSignatureP *master_sig)
+{
+ struct PostgresClosure *pg = cls;
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_auto_from_type (master_pub),
+ GNUNET_PQ_query_param_auto_from_type (h_wire_method),
+ TALER_PQ_query_param_amount (wire_fee),
+ TALER_PQ_query_param_amount (closing_fee),
+ GNUNET_PQ_query_param_absolute_time (&start_date),
+ GNUNET_PQ_query_param_absolute_time (&end_date),
+ GNUNET_PQ_query_param_auto_from_type (master_sig),
+ GNUNET_PQ_query_param_end
+ };
+
+ /* no preflight check here, run in its own transaction by the caller */
+ check_connection (pg);
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Storing wire fee for %s starting at %s of %s\n",
+ TALER_B2S (master_pub),
+ GNUNET_STRINGS_absolute_time_to_string (start_date),
+ TALER_amount2s (wire_fee));
+ return GNUNET_PQ_eval_prepared_non_select (pg->conn,
+ "insert_wire_fee",
+ params);
+}
+
+
/* ********************* OLD API ************************** */
/**
@@ -3885,58 +3934,6 @@ postgres_get_authorized_tip_amount (void *cls,
/**
- * Store information about wire fees charged by an exchange,
- * including signature (so we have proof).
- *
- * @param cls closure
- * @paramm exchange_pub public key of the exchange
- * @param h_wire_method hash of wire method
- * @param wire_fee wire fee charged
- * @param closing_fee closing fee charged (irrelevant for us,
- * but needed to check signature)
- * @param start_date start of fee being used
- * @param end_date end of fee being used
- * @param exchange_sig signature of exchange over fee structure
- * @return transaction status code
- */
-static enum GNUNET_DB_QueryStatus
-postgres_store_wire_fee_by_exchange (
- void *cls,
- const struct TALER_MasterPublicKeyP *master_pub,
- const struct GNUNET_HashCode *h_wire_method,
- const struct TALER_Amount *wire_fee,
- const struct TALER_Amount *closing_fee,
- struct GNUNET_TIME_Absolute start_date,
- struct GNUNET_TIME_Absolute end_date,
- const struct
- TALER_MasterSignatureP *master_sig)
-{
- struct PostgresClosure *pg = cls;
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_auto_from_type (master_pub),
- GNUNET_PQ_query_param_auto_from_type (h_wire_method),
- TALER_PQ_query_param_amount (wire_fee),
- TALER_PQ_query_param_amount (closing_fee),
- GNUNET_PQ_query_param_absolute_time (&start_date),
- GNUNET_PQ_query_param_absolute_time (&end_date),
- GNUNET_PQ_query_param_auto_from_type (master_sig),
- GNUNET_PQ_query_param_end
- };
-
- /* no preflight check here, run in its own transaction by the caller */
- check_connection (pg);
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Storing wire fee for %s starting at %s of %s\n",
- TALER_B2S (master_pub),
- GNUNET_STRINGS_absolute_time_to_string (start_date),
- TALER_amount2s (wire_fee));
- return GNUNET_PQ_eval_prepared_non_select (pg->conn,
- "insert_wire_fee",
- params);
-}
-
-
-/**
* Lookup proof information about a wire transfer.
*
* @param cls closure
@@ -6303,6 +6300,21 @@ libtaler_plugin_merchantdb_postgres_init (void *cls)
" ORDER BY credit_serial DESC"
" LIMIT $3",
3),
+ /* For postgres_store_wire_fee_by_exchange() */
+ GNUNET_PQ_make_prepare ("insert_wire_fee",
+ "INSERT INTO merchant_exchange_wire_fees"
+ "(master_pub"
+ ",h_wire_method"
+ ",wire_fee_val"
+ ",wire_fee_frac"
+ ",closing_fee_val"
+ ",closing_fee_frac"
+ ",start_date"
+ ",end_date"
+ ",master_sig)"
+ " VALUES "
+ "($1, $2, $3, $4, $5, $6, $7, $8, $9)",
+ 9),
/* OLD API: */
#if 0
@@ -6326,20 +6338,6 @@ libtaler_plugin_merchantdb_postgres_init (void *cls)
" VALUES "
"($1, $2, $3, $4, $5)",
5),
- GNUNET_PQ_make_prepare ("insert_wire_fee",
- "INSERT INTO exchange_wire_fees"
- "(exchange_pub"
- ",h_wire_method"
- ",wire_fee_val"
- ",wire_fee_frac"
- ",closing_fee_val"
- ",closing_fee_frac"
- ",start_date"
- ",end_date"
- ",exchange_sig)"
- " VALUES "
- "($1, $2, $3, $4, $5, $6, $7, $8, $9)",
- 9),
GNUNET_PQ_make_prepare ("find_contract_terms_from_hash",
"SELECT"
" contract_terms"
diff --git a/src/lib/merchant_api_post_orders.c b/src/lib/merchant_api_post_orders.c
index 19dbdb47..7c4d513c 100644
--- a/src/lib/merchant_api_post_orders.c
+++ b/src/lib/merchant_api_post_orders.c
@@ -235,7 +235,9 @@ TALER_MERCHANT_orders_post2 (
po->ctx = ctx;
po->cb = cb;
po->cb_cls = cb_cls;
- po->url = TALER_url_join (backend_url, "orders", NULL);
+ po->url = TALER_url_join (backend_url,
+ "private/orders",
+ NULL);
req = json_pack ("{s:O}",
"order", (json_t *) order);
GNUNET_assert (NULL != req);
diff --git a/src/testing/test_merchant_api.c b/src/testing/test_merchant_api.c
index b8a471a7..ce181d1c 100644
--- a/src/testing/test_merchant_api.c
+++ b/src/testing/test_merchant_api.c
@@ -42,7 +42,7 @@
*/
#define CONFIG_FILE "test_merchant_api.conf"
-#define PAYTO_I1 "payto://taler-bank/localhost/3"
+#define PAYTO_I1 "payto://x-taler-bank/localhost/3"
/**
* Exchange base URL. Could also be taken from config.
@@ -1037,9 +1037,9 @@ run (void *cls,
merchant_url,
"product-1",
MHD_HTTP_NO_CONTENT),
-#if 0
TALER_TESTING_cmd_batch ("pay",
pay),
+#if 0
TALER_TESTING_cmd_batch ("double-spending",
double_spending),
TALER_TESTING_cmd_batch ("track",