diff options
Diffstat (limited to 'src/backend/taler-merchant-httpd_private-patch-instances-ID.c')
-rw-r--r-- | src/backend/taler-merchant-httpd_private-patch-instances-ID.c | 225 |
1 files changed, 26 insertions, 199 deletions
diff --git a/src/backend/taler-merchant-httpd_private-patch-instances-ID.c b/src/backend/taler-merchant-httpd_private-patch-instances-ID.c index b8e0052d..027d5869 100644 --- a/src/backend/taler-merchant-httpd_private-patch-instances-ID.c +++ b/src/backend/taler-merchant-httpd_private-patch-instances-ID.c @@ -1,6 +1,6 @@ /* This file is part of TALER - (C) 2020-2021 Taler Systems SA + (C) 2020-2023 Taler Systems SA TALER is free software; you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as @@ -26,6 +26,7 @@ #include "taler-merchant-httpd_private-patch-instances-ID.h" #include "taler-merchant-httpd_helper.h" #include <taler/taler_json_lib.h> +#include <taler/taler_dbevents.h> /** @@ -62,16 +63,18 @@ patch_instances_ID (struct TMH_MerchantInstance *mi, struct TMH_HandlerContext *hc) { struct TALER_MERCHANTDB_InstanceSettings is; - json_t *payto_uris; const char *name; + const char *uts = "business"; struct TMH_WireMethod *wm_head = NULL; struct TMH_WireMethod *wm_tail = NULL; struct GNUNET_JSON_Specification spec[] = { - GNUNET_JSON_spec_json ("payto_uris", - &payto_uris), GNUNET_JSON_spec_string ("name", &name), GNUNET_JSON_spec_mark_optional ( + GNUNET_JSON_spec_string ("user_type", + &uts), + NULL), + GNUNET_JSON_spec_mark_optional ( GNUNET_JSON_spec_string ("website", (const char **) &is.website), NULL), @@ -87,14 +90,8 @@ patch_instances_ID (struct TMH_MerchantInstance *mi, &is.address), GNUNET_JSON_spec_json ("jurisdiction", &is.jurisdiction), - TALER_JSON_spec_amount ("default_max_wire_fee", - TMH_currency, - &is.default_max_wire_fee), - GNUNET_JSON_spec_uint32 ("default_wire_fee_amortization", - &is.default_wire_fee_amortization), - TALER_JSON_spec_amount ("default_max_deposit_fee", - TMH_currency, - &is.default_max_deposit_fee), + GNUNET_JSON_spec_bool ("use_stefan", + &is.use_stefan), GNUNET_JSON_spec_relative_time ("default_wire_transfer_delay", &is.default_wire_transfer_delay), GNUNET_JSON_spec_relative_time ("default_pay_delay", @@ -102,7 +99,6 @@ patch_instances_ID (struct TMH_MerchantInstance *mi, GNUNET_JSON_spec_end () }; enum GNUNET_DB_QueryStatus qs; - bool committed = false; GNUNET_assert (NULL != mi); memset (&is, @@ -119,6 +115,19 @@ patch_instances_ID (struct TMH_MerchantInstance *mi, ? MHD_YES : MHD_NO; } + if (NULL == uts) + uts = "business"; + if (GNUNET_OK != + TALER_KYCLOGIC_kyc_user_type_from_string (uts, + &is.ut)) + { + GNUNET_break_op (0); + GNUNET_JSON_parse_free (spec); + return TALER_MHD_reply_with_error (connection, + MHD_HTTP_BAD_REQUEST, + TALER_EC_GENERIC_PARAMETER_MALFORMED, + "user_type"); + } if (! TMH_location_object_valid (is.address)) { GNUNET_break_op (0); @@ -149,15 +158,7 @@ patch_instances_ID (struct TMH_MerchantInstance *mi, "jurisdiction"); } - if (! TMH_payto_uri_array_valid (payto_uris)) - { - GNUNET_JSON_parse_free (spec); - return TALER_MHD_reply_with_error (connection, - MHD_HTTP_BAD_REQUEST, - TALER_EC_GENERIC_PAYTO_URI_MALFORMED, - NULL); - } - for (unsigned int i = 0; i<MAX_RETRIES; i++) + for (unsigned int retry = 0; retry<MAX_RETRIES; retry++) { /* Cleanup after earlier loops */ { @@ -184,6 +185,7 @@ patch_instances_ID (struct TMH_MerchantInstance *mi, /* Check for equality of settings */ if (! ( (0 == strcmp (mi->settings.name, name)) && + (mi->settings.ut == is.ut) && ((mi->settings.email == is.email) || (NULL != is.email && NULL != mi->settings.email && 0 == strcmp (mi->settings.email, @@ -200,18 +202,7 @@ patch_instances_ID (struct TMH_MerchantInstance *mi, is.address)) && (1 == json_equal (mi->settings.jurisdiction, is.jurisdiction)) && - (GNUNET_YES == TALER_amount_cmp_currency ( - &mi->settings.default_max_deposit_fee, - &is.default_max_deposit_fee)) && - (0 == TALER_amount_cmp (&mi->settings.default_max_deposit_fee, - &is.default_max_deposit_fee)) && - (GNUNET_YES == TALER_amount_cmp_currency ( - &mi->settings.default_max_wire_fee, - &is.default_max_wire_fee)) && - (0 == TALER_amount_cmp (&mi->settings.default_max_wire_fee, - &is.default_max_wire_fee)) && - (mi->settings.default_wire_fee_amortization == - is.default_wire_fee_amortization) && + (mi->settings.use_stefan == is.use_stefan) && (GNUNET_TIME_relative_cmp (mi->settings.default_wire_transfer_delay, ==, is.default_wire_transfer_delay)) && @@ -233,161 +224,13 @@ patch_instances_ID (struct TMH_MerchantInstance *mi, goto giveup; } } - - /* Check for changes in accounts */ - { - unsigned int len = json_array_size (payto_uris); - struct TMH_WireMethod *matches[GNUNET_NZL (len)]; - bool matched; - - memset (matches, - 0, - sizeof (matches)); - for (struct TMH_WireMethod *wm = mi->wm_head; - NULL != wm; - wm = wm->next) - { - const char *uri = wm->payto_uri; - - GNUNET_assert (NULL != uri); - matched = false; - for (unsigned int i = 0; i<len; i++) - { - const char *str = json_string_value (json_array_get (payto_uris, - i)); - if (0 == strcasecmp (uri, - str)) - { - /* our own existing payto URIs should be unique, that is no - duplicates in the list, so we cannot match twice */ - GNUNET_assert (NULL == matches[i]); - matches[i] = wm; - matched = true; - break; - } - } - /* delete unmatched (= removed) accounts */ - if ( (! matched) && - (wm->active) ) - { - /* Account was REMOVED */ - GNUNET_log (GNUNET_ERROR_TYPE_INFO, - "Existing account `%s' not found, inactivating it.\n", - uri); - wm->deleting = true; - qs = TMH_db->inactivate_account (TMH_db->cls, - mi->settings.id, - &wm->h_wire); - if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT != qs) - { - TMH_db->rollback (TMH_db->cls); - if (GNUNET_DB_STATUS_SOFT_ERROR == qs) - goto retry; - else - goto giveup; - } - } - } - /* Find _new_ accounts */ - for (unsigned int i = 0; i<len; i++) - { - struct TALER_MERCHANTDB_AccountDetails ad; - struct TMH_WireMethod *wm; - - if (NULL != matches[i]) - { - wm = matches[i]; - if (! wm->active) - { - qs = TMH_db->activate_account (TMH_db->cls, - mi->settings.id, - &wm->h_wire); - if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT != qs) - { - TMH_db->rollback (TMH_db->cls); - if (GNUNET_DB_STATUS_SOFT_ERROR == qs) - goto retry; - else - goto giveup; - } - } - wm->enabling = true; - continue; - } - ad.payto_uri = json_string_value (json_array_get (payto_uris, - i)); - GNUNET_assert (NULL != ad.payto_uri); - GNUNET_log (GNUNET_ERROR_TYPE_INFO, - "Adding NEW account `%s'\n", - ad.payto_uri); - wm = TMH_setup_wire_account (ad.payto_uri); - GNUNET_assert (NULL != wm); /* checked payto_uri validity earlier */ - GNUNET_CONTAINER_DLL_insert (wm_head, - wm_tail, - wm); - ad.h_wire = wm->h_wire; - ad.salt = wm->wire_salt; - ad.active = true; - qs = TMH_db->insert_account (TMH_db->cls, - mi->settings.id, - &ad); - if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT != qs) - { - TMH_db->rollback (TMH_db->cls); - if (GNUNET_DB_STATUS_SOFT_ERROR == qs) - goto retry; - else - goto giveup; - } - } - } - qs = TMH_db->commit (TMH_db->cls); retry: if (GNUNET_DB_STATUS_SOFT_ERROR == qs) continue; - if (qs >= 0) - committed = true; break; } /* for(... MAX_RETRIES) */ giveup: - /* Deactivate existing wire methods that were removed above */ - for (struct TMH_WireMethod *wm = mi->wm_head; - NULL != wm; - wm = wm->next) - { - /* We did not flip the 'active' bits earlier because the - DB transaction could still fail. Now it is time to update our - runtime state. */ - GNUNET_assert (! (wm->deleting & wm->enabling)); - if (committed) - { - if (wm->deleting) - wm->active = false; - if (wm->enabling) - wm->active = true; - } - wm->deleting = false; - wm->enabling = false; - } - if (! committed) - { - struct TMH_WireMethod *wm; - - while (NULL != (wm = wm_head)) - { - GNUNET_CONTAINER_DLL_remove (wm_head, - wm_tail, - wm); - free_wm (wm); - } - GNUNET_JSON_parse_free (spec); - return TALER_MHD_reply_with_error (connection, - MHD_HTTP_INTERNAL_SERVER_ERROR, - TALER_EC_GENERIC_DB_COMMIT_FAILED, - NULL); - } - /* Update our 'settings' */ GNUNET_free (mi->settings.name); GNUNET_free (mi->settings.email); @@ -397,6 +240,7 @@ giveup: json_decref (mi->settings.jurisdiction); is.id = mi->settings.id; mi->settings = is; + // mi->settings.user_type = (enum TALER_KYCLOGIC_KycUserType) is.user_type; mi->settings.address = json_incref (mi->settings.address); mi->settings.jurisdiction = json_incref (mi->settings.jurisdiction); mi->settings.name = GNUNET_strdup (name); @@ -407,23 +251,6 @@ giveup: if (NULL != is.logo) mi->settings.logo = GNUNET_strdup (is.logo); - /* Add 'new' wire methods to our list */ - { - struct TMH_WireMethod *wm; - - /* Note: this _could_ be done more efficiently if - someone wrote a GNUNET_CONTAINER_DLL_merge()... */ - while (NULL != (wm = wm_head)) - { - GNUNET_CONTAINER_DLL_remove (wm_head, - wm_tail, - wm); - GNUNET_CONTAINER_DLL_insert (mi->wm_head, - mi->wm_tail, - wm); - } - } - GNUNET_JSON_parse_free (spec); TMH_reload_instances (mi->settings.id); return TALER_MHD_reply_static (connection, |