diff --git a/lib/adyen/client.rb b/lib/adyen/client.rb index e3545c6..493edcc 100644 --- a/lib/adyen/client.rb +++ b/lib/adyen/client.rb @@ -22,7 +22,7 @@ def initialize(ws_user: nil, ws_password: nil, api_key: nil, oauth_token: nil, e @ws_password = ws_password @api_key = api_key @oauth_token = oauth_token - @env = env + self.env = env @application_name = application_name @adapter = adapter || Faraday.default_adapter if Gem::Version.new(Faraday::VERSION) >= Gem::Version.new('2.1') @@ -33,7 +33,7 @@ def initialize(ws_user: nil, ws_password: nil, api_key: nil, oauth_token: nil, e @adapter_options = adapter_options || {} end @mock_service_url_base = mock_service_url_base || "http://localhost:#{mock_port}" - @live_url_prefix = live_url_prefix + self.live_url_prefix = live_url_prefix if RUBY_VERSION >= '3.2' # set default timeouts @connection_options = connection_options || Faraday::ConnectionOptions.new( @@ -60,7 +60,9 @@ def env=(value) # remove 'https' from live_url_prefix if necessary def live_url_prefix=(value) - value['https://'] = '' unless value['https://'].nil? + unless value.nil? + value['https://'] = '' unless value['https://'].nil? + end @live_url_prefix = value end diff --git a/spec/client_spec.rb b/spec/client_spec.rb index 433766b..830e54b 100644 --- a/spec/client_spec.rb +++ b/spec/client_spec.rb @@ -18,6 +18,22 @@ .to eq(:test) end + it 'raises ArgumentError when initialized with an invalid env string' do + expect { Adyen::Client.new(env: 'live') } + .to raise_error(ArgumentError) + end + + it 'raises ArgumentError when initialized with an invalid env value' do + expect { Adyen::Client.new(env: :invalid) } + .to raise_error(ArgumentError) + end + + it 'strips https:// from live_url_prefix when passed via constructor' do + client = Adyen::Client.new(env: :live, live_url_prefix: 'https://myprefix') + expect(client.service_url_base('Payment')) + .to eq('https://myprefix-pal-live.adyenpayments.com/pal/servlet/Payment') + end + it 'sets the version number' do @shared_values[:client].checkout.version = @shared_values[:version] expect(@shared_values[:client].checkout.version)