Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 23 additions & 17 deletions config/initializers/netsuite.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand All @@ -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"
Expand All @@ -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"
Expand Down