Skip to content

Commit 9696c00

Browse files
committed
Remove invalid service and simplify authentication validation
The service specific validation for `PaymentSetupAndVerification` was useless as this service is not a valid service in `service_url_base`. Removing it means that we where able to simplify the validation as it is not service dependent anymore.
1 parent a071925 commit 9696c00

File tree

2 files changed

+11
-9
lines changed

2 files changed

+11
-9
lines changed

lib/adyen/client.rb

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -145,9 +145,7 @@ def call_adyen_api(service, action, request_data, headers, version, _with_applic
145145
# get URL for requested endpoint
146146
url = service_url(service, action.is_a?(String) ? action : action.fetch(:url), version)
147147

148-
# make sure valid authentication has been provided
149-
validate_auth_type(service, request_data)
150-
148+
# get method from action or default to post
151149
method = action.is_a?(String) ? 'post' : action.fetch(:method)
152150

153151
call_adyen_api_url(url, method, request_data, headers)
@@ -156,7 +154,7 @@ def call_adyen_api(service, action, request_data, headers, version, _with_applic
156154
# send request to adyen API with a given full URL
157155
def call_adyen_api_url(url, method, request_data, headers)
158156
# make sure valid authentication has been provided, without a specific service
159-
validate_auth_type(nil, request_data)
157+
validate_auth(request_data)
160158

161159
# initialize Faraday connection object
162160
conn = Faraday.new(url, @connection_options) do |faraday|
@@ -343,18 +341,14 @@ def auth_type
343341
"basic"
344342
end
345343

346-
def validate_auth_type(service, request_data)
344+
def validate_auth(request_data)
347345
# ensure authentication has been provided
348346
if @api_key.nil? && @oauth_token.nil? && (@ws_password.nil? || @ws_user.nil?)
349347
raise Adyen::AuthenticationError.new(
350348
'No authentication found - please set api_key, oauth_token, or ws_user and ws_password',
351349
request_data
352350
)
353351
end
354-
if service == "PaymentSetupAndVerification" && @api_key.nil? && @oauth_token.nil? && @ws_password.nil? && @ws_user.nil?
355-
raise Adyen::AuthenticationError.new('Checkout service requires API-key or oauth_token', request_data),
356-
'Checkout service requires API-key or oauth_token'
357-
end
358352
end
359353

360354
# build the error message from the response payload

spec/client_spec.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -537,6 +537,14 @@
537537

538538
expect(request_body_sent).to eq(hash_data.to_json)
539539
end
540+
541+
it 'validates authentication is provided' do
542+
client_without_auth = Adyen::Client.new(env: :test)
543+
544+
expect {
545+
client_without_auth.call_adyen_api('Checkout', 'payments', {}, {}, '71')
546+
}.to raise_error(Adyen::AuthenticationError, /No authentication found/)
547+
end
540548
end
541549

542550
describe '#call_adyen_api_url' do

0 commit comments

Comments
 (0)