Skip to content

Commit 9109f3c

Browse files
Copilotgcatanese
andcommitted
Fix Client#initialize to use setter methods for env and live_url_prefix validation
Co-authored-by: gcatanese <1771700+gcatanese@users.noreply.github.com>
1 parent 9614001 commit 9109f3c

2 files changed

Lines changed: 21 additions & 3 deletions

File tree

lib/adyen/client.rb

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ def initialize(ws_user: nil, ws_password: nil, api_key: nil, oauth_token: nil, e
2222
@ws_password = ws_password
2323
@api_key = api_key
2424
@oauth_token = oauth_token
25-
@env = env
25+
self.env = env
2626
@application_name = application_name
2727
@adapter = adapter || Faraday.default_adapter
2828
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
3333
@adapter_options = adapter_options || {}
3434
end
3535
@mock_service_url_base = mock_service_url_base || "http://localhost:#{mock_port}"
36-
@live_url_prefix = live_url_prefix
36+
self.live_url_prefix = live_url_prefix
3737
if RUBY_VERSION >= '3.2'
3838
# set default timeouts
3939
@connection_options = connection_options || Faraday::ConnectionOptions.new(
@@ -60,7 +60,9 @@ def env=(value)
6060

6161
# remove 'https' from live_url_prefix if necessary
6262
def live_url_prefix=(value)
63-
value['https://'] = '' unless value['https://'].nil?
63+
unless value.nil?
64+
value['https://'] = '' unless value['https://'].nil?
65+
end
6466
@live_url_prefix = value
6567
end
6668

spec/client_spec.rb

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,22 @@
1818
.to eq(:test)
1919
end
2020

21+
it 'raises ArgumentError when initialized with an invalid env string' do
22+
expect { Adyen::Client.new(env: 'live') }
23+
.to raise_error(ArgumentError)
24+
end
25+
26+
it 'raises ArgumentError when initialized with an invalid env value' do
27+
expect { Adyen::Client.new(env: :invalid) }
28+
.to raise_error(ArgumentError)
29+
end
30+
31+
it 'strips https:// from live_url_prefix when passed via constructor' do
32+
client = Adyen::Client.new(env: :live, live_url_prefix: 'https://myprefix')
33+
expect(client.service_url_base('Payment'))
34+
.to eq('https://myprefix-pal-live.adyenpayments.com/pal/servlet/Payment')
35+
end
36+
2137
it 'sets the version number' do
2238
@shared_values[:client].checkout.version = @shared_values[:version]
2339
expect(@shared_values[:client].checkout.version)

0 commit comments

Comments
 (0)