From 674c5afc94e6378d99203fda0ff79ef7bcad8877 Mon Sep 17 00:00:00 2001 From: Mike Virata-Stone Date: Fri, 5 Sep 2025 20:34:58 -0700 Subject: [PATCH] Attempt to fix NetSuite by updating the version... cross your fingers... also, the endpoint must be after the token config, otherwise it fails for some reason --- config/initializers/netsuite.rb | 40 +++++++++++++++++++-------------- 1 file changed, 23 insertions(+), 17 deletions(-) diff --git a/config/initializers/netsuite.rb b/config/initializers/netsuite.rb index cf6ae612..e7f0eaf6 100644 --- a/config/initializers/netsuite.rb +++ b/config/initializers/netsuite.rb @@ -2,9 +2,15 @@ def common_netsuite_config(config) config.reset! config.account ENV["STOCKAID_NETSUITE_ACCOUNT_ID"] - config.api_version ENV.fetch("STOCKAID_NETSUITE_API_VERSION", "2018_2") + config.api_version ENV.fetch("STOCKAID_NETSUITE_API_VERSION", "2025_1") config.read_timeout ENV.fetch("STOCKAID_NETSUITE_READ_TIMEOUT", 60).to_i - config.wsdl_domain NetSuite::Utilities.data_center_url(ENV["STOCKAID_NETSUITE_ACCOUNT_ID"]).sub(%r{\A\w+://}, "") + + yield if block_given? + + # This requires the token setup, otherwise it will fail to fetch or set the endpoint + endpoint_value = NetSuite::Utilities.data_center_url(ENV["STOCKAID_NETSUITE_ACCOUNT_ID"]).sub(%r{\A\w+://}, "") + config.wsdl_domain endpoint_value + config.endpoint "https://#{endpoint_value}/services/NetSuitePort_#{config.api_version}" end if Rails.env.test? @@ -21,12 +27,12 @@ def common_netsuite_config(config) STOCKAID_NETSUITE_TOKEN_SECRET ].all? { |x| ENV[x].present? } NetSuite.configure do - common_netsuite_config(self) - - consumer_key ENV["STOCKAID_NETSUITE_CONSUMER_KEY"] - consumer_secret ENV["STOCKAID_NETSUITE_CONSUMER_SECRET"] - token_id ENV["STOCKAID_NETSUITE_TOKEN_ID"] - token_secret ENV["STOCKAID_NETSUITE_TOKEN_SECRET"] + common_netsuite_config(self) do + consumer_key ENV["STOCKAID_NETSUITE_CONSUMER_KEY"] + consumer_secret ENV["STOCKAID_NETSUITE_CONSUMER_SECRET"] + token_id ENV["STOCKAID_NETSUITE_TOKEN_ID"] + token_secret ENV["STOCKAID_NETSUITE_TOKEN_SECRET"] + end end Rails.logger.info "Initialized NetSuite integration with token authentication" @@ -39,17 +45,17 @@ def common_netsuite_config(config) STOCKAID_NETSUITE_ROLE ].all? { |x| ENV[x].present? } NetSuite.configure do - common_netsuite_config(self) - - email ENV["STOCKAID_NETSUITE_EMAIL"] - password ENV["STOCKAID_NETSUITE_PASSWORD"] - role ENV["STOCKAID_NETSUITE_ROLE"].to_i + common_netsuite_config(self) do + email ENV["STOCKAID_NETSUITE_EMAIL"] + password ENV["STOCKAID_NETSUITE_PASSWORD"] + role ENV["STOCKAID_NETSUITE_ROLE"].to_i - self.soap_header = { - "platformMsgs:ApplicationInfo" => { - "platformMsgs:applicationId" => ENV["STOCKAID_NETSUITE_APPLICATION_ID"] + self.soap_header = { + "platformMsgs:ApplicationInfo" => { + "platformMsgs:applicationId" => ENV["STOCKAID_NETSUITE_APPLICATION_ID"] + } } - } + end end Rails.logger.info "Initialized NetSuite integration with password authentication"