merchant

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

commit 3c61e8385ca4822cf1d39ec021237fc213a526f1
parent d17e571f782a6c9c178f8aa6232524af867eb1cb
Author: Christian Grothoff <christian@grothoff.org>
Date:   Sat,  4 Apr 2020 15:52:07 +0200

improve error handling, use configuration option names as per latest docs

Diffstat:
Msrc/backend/taler-merchant-httpd_auditors.c | 33++++++++++++++++++++++-----------
Msrc/backend/taler-merchant-httpd_exchanges.c | 34++++++++++++++++++++++++++++++----
Msrc/backend/taler-merchant-httpd_exchanges.h | 2+-
Msrc/backend/taler-merchant-httpd_pay.c | 2+-
Msrc/lib/test_merchant_api.conf | 7++++---
Msrc/lib/test_merchant_api_twisted.conf | 4++--
6 files changed, 60 insertions(+), 22 deletions(-)

diff --git a/src/backend/taler-merchant-httpd_auditors.c b/src/backend/taler-merchant-httpd_auditors.c @@ -152,27 +152,38 @@ parse_auditors (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg = cls; char *pks; struct Auditor auditor; + char *currency; if (0 != strncasecmp (section, - "auditor-", - strlen ("auditor-"))) + "merchant-auditor-", + strlen ("merchant-auditor-"))) return; if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string (cfg, section, - "NAME", - &auditor.name)) + "CURRENCY", + &currency)) { GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, section, - "NAME"); + "CURRENCY"); return; } - // FIXME: url -> auditor_url + if (0 != strcasecmp (currency, + TMH_currency)) + { + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + "Auditor given in section `%s' is for another currency. Skipping.\n", + section); + GNUNET_free (currency); + return; + } + GNUNET_free (currency); + auditor.name = GNUNET_strdup (&section[strlen ("merchant-auditor-")]); if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string (cfg, section, - "URL", + "AUDITOR_BASE_URL", &auditor.url)) { GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, @@ -184,12 +195,12 @@ parse_auditors (void *cls, if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string (cfg, section, - "PUBLIC_KEY", + "AUDITOR_KEY", &pks)) { GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, section, - "PUBLIC_KEY"); + "AUDITOR_KEY"); GNUNET_free (auditor.name); GNUNET_free (auditor.url); return; @@ -201,8 +212,8 @@ parse_auditors (void *cls, { GNUNET_log_config_invalid (GNUNET_ERROR_TYPE_ERROR, section, - "PUBLIC_KEY", - "valid public key"); + "AUDITOR_KEY", + "need a valid EdDSA public key"); GNUNET_free (auditor.name); GNUNET_free (auditor.url); GNUNET_free (pks); diff --git a/src/backend/taler-merchant-httpd_exchanges.c b/src/backend/taler-merchant-httpd_exchanges.c @@ -292,7 +292,7 @@ retry_exchange (void *cls) /* might be a scheduled reload and not our first attempt */ exchange->retry_task = NULL; GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Connecting to exchange exchange %s in retry_exchange\n", + "Connecting to exchange %s in retry_exchange()\n", exchange->url); if (NULL != exchange->conn) { @@ -304,6 +304,8 @@ retry_exchange (void *cls) &keys_mgmt_cb, exchange, TALER_EXCHANGE_OPTION_END); + /* Note: while the API spec says 'returns NULL on error', the implementation + actually never returns NULL. */ GNUNET_break (NULL != exchange->conn); } @@ -1028,6 +1030,7 @@ accept_exchanges (void *cls, char *url; char *mks; struct Exchange *exchange; + char *currency; if (0 != strncasecmp (section, "merchant-exchange-", @@ -1036,12 +1039,33 @@ accept_exchanges (void *cls, if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string (cfg, section, - "BASE_URL", + "CURRENCY", + &currency)) + { + GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, + section, + "CURRENCY"); + return; + } + if (0 != strcasecmp (currency, + TMH_currency)) + { + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + "Exchange given in section `%s' is for another currency. Skipping.\n", + section); + GNUNET_free (currency); + return; + } + GNUNET_free (currency); + if (GNUNET_OK != + GNUNET_CONFIGURATION_get_value_string (cfg, + section, + "EXCHANGE_BASE_URL", &url)) { GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, section, - "BASE_URL"); + "EXCHANGE_BASE_URL"); return; } exchange = GNUNET_new (struct Exchange); @@ -1065,7 +1089,7 @@ accept_exchanges (void *cls, GNUNET_log_config_invalid (GNUNET_ERROR_TYPE_ERROR, section, "MASTER_KEY", - _ ("ill-formed key")); + _ ("ill-formed EdDSA key")); } GNUNET_free (mks); } @@ -1183,6 +1207,8 @@ TMH_EXCHANGES_done () GNUNET_SCHEDULER_cancel (exchange->retry_task); exchange->retry_task = NULL; } + GNUNET_assert (NULL == exchange->fo_head); + GNUNET_assert (NULL == exchange->fo_tail); GNUNET_free (exchange->url); GNUNET_free (exchange); } diff --git a/src/backend/taler-merchant-httpd_exchanges.h b/src/backend/taler-merchant-httpd_exchanges.h @@ -1,6 +1,6 @@ /* This file is part of TALER - (C) 2014, 2015 INRIA + (C) 2014-2020 Taler Systems SA TALER is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software diff --git a/src/backend/taler-merchant-httpd_pay.c b/src/backend/taler-merchant-httpd_pay.c @@ -1232,7 +1232,7 @@ process_pay_with_exchange (void *cls, pc, hc, TALER_MHD_make_json_pack ("{s:s, s:I, s:o}", - "hint", "invalid denomination", + "hint", "denomination not accepted", "code", (json_int_t) ec, "h_denom_pub", GNUNET_JSON_from_data_auto ( &denom_details->h_key))); diff --git a/src/lib/test_merchant_api.conf b/src/lib/test_merchant_api.conf @@ -118,9 +118,10 @@ ACTIVE_nulltip = YES # Sections starting with "merchant-exchange-" specify trusted exchanges # (by the merchant) -[merchant-exchange-kudos] -MASTER_KEY = 98NJW3CQHZQGQXTY3K85K531XKPAPAVV4Q5V8PYYRR00NJGZWNVG -BASE_URL = http://localhost:8081/ +[merchant-exchange-test] +MASTER_KEY = T1VVFQZZARQ1CMF4BN58EE7SKTW5AV2BS18S87ZEGYS4S29J6DNG +EXCHANGE_BASE_URL = http://localhost:8081/ +CURRENCY = EUR # only fixes skips. [auditor] diff --git a/src/lib/test_merchant_api_twisted.conf b/src/lib/test_merchant_api_twisted.conf @@ -1,9 +1,9 @@ # This file is in the public domain. @INLINE@ test_merchant_api.conf -[merchant-exchange-kudos] +[merchant-exchange-test] # must target the twister's http port. -BASE_URL = http://localhost:8888/ +EXCHANGE_BASE_URL = http://localhost:8888/ [exchange] BASE_URL = http://localhost:8888/