Skip to content

Commit 62dfda8

Browse files
authored
Merge pull request #315 from pplant/session.authentication.fix
Session authentication fix
2 parents e6ef511 + 57b61ef commit 62dfda8

File tree

3 files changed

+47
-2
lines changed

3 files changed

+47
-2
lines changed

lib/adyen/client.rb

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,10 @@ def service_url_base(service)
107107
when 'PosMobile'
108108
url = "https://checkout-#{@env}.adyen.com/checkout/possdk"
109109
supports_live_url_prefix = true
110+
when 'SessionAuthentication'
111+
subdomain = @env == :live ? "authe-#{@env}" : @env
112+
url = "https://#{subdomain}.adyen.com/authe/api"
113+
supports_live_url_prefix = false
110114
else
111115
raise ArgumentError, 'Invalid service specified'
112116
end
@@ -140,7 +144,7 @@ def service_url(service, action, version)
140144
def call_adyen_api(service, action, request_data, headers, version, _with_application_info: false)
141145
# get URL for requested endpoint
142146
url = service_url(service, action.is_a?(String) ? action : action.fetch(:url), version)
143-
147+
144148
auth_type = auth_type(service, request_data)
145149

146150
# initialize Faraday connection object
@@ -223,6 +227,9 @@ def call_adyen_api(service, action, request_data, headers, version, _with_applic
223227
when 403
224228
full_message = build_error_message(response.body, 'Authorisation error')
225229
raise Adyen::PermissionError.new(full_message, request_data, response.body)
230+
when 404
231+
full_message = build_error_message(response.body, 'Not found error')
232+
raise Adyen::NotFoundError.new(full_message, request_data, response.body)
226233
when 422
227234
full_message = build_error_message(response.body, 'Validation error')
228235
raise Adyen::ValidationError.new(full_message, request_data, response.body)
@@ -368,8 +375,10 @@ def build_error_message(response_body, default_message)
368375
full_message = default_message
369376
begin
370377
error_details = response_body
378+
error_details = JSON.parse(response_body, symbolize_names: true) if response_body.is_a?(String)
379+
371380
# check different attributes to support both RFC 7807 and legacy models
372-
message = error_details[:detail] || error_details[:message]
381+
message = error_details[:detail] || error_details[:message] || error_details
373382
error_code = error_details[:errorCode]
374383
if message && error_code
375384
full_message = "#{message} ErrorCode: #{error_code}"

lib/adyen/errors.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,12 @@ def initialize(msg, request)
105105
end
106106
end
107107

108+
class NotFoundError < AdyenError
109+
def initialize(msg, request, response)
110+
super(request, response, msg, 404)
111+
end
112+
end
113+
108114
# catchall for errors which don't have more specific classes
109115
class APIError < AdyenError
110116
def initialize(msg, request, response, code)

spec/client_spec.rb

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,18 @@
303303
.to eq('https://ca-test.adyen.com/ca/services/DisputesService')
304304
end
305305

306+
it 'checks the creation of SessionAuthentication url for the test env' do
307+
client = Adyen::Client.new(env: :test)
308+
expect(client.service_url_base('SessionAuthentication'))
309+
.to eq('https://test.adyen.com/authe/api')
310+
end
311+
312+
it 'checks the creation of SessionAuthentication url for the live env' do
313+
client = Adyen::Client.new(env: :live)
314+
expect(client.service_url_base('SessionAuthentication'))
315+
.to eq('https://authe-live.adyen.com/authe/api')
316+
end
317+
306318
it 'raises FormatError on 400 response and checks content' do
307319
client = Adyen::Client.new(api_key: 'api_key', env: :test)
308320
mock_faraday_connection = double(Faraday::Connection)
@@ -401,4 +413,22 @@
401413
expect(error.msg).to eq('Unexpected error. ErrorCode: 999')
402414
end
403415
end
416+
417+
it 'raises NotFoundError on 404 response and checks content' do
418+
client = Adyen::Client.new(api_key: 'api_key', env: :test)
419+
mock_faraday_connection = double(Faraday::Connection)
420+
error_body = "701 Version 71 is not supported, latest version: 68"
421+
mock_response = Faraday::Response.new(status: 404, body: error_body)
422+
423+
allow(Faraday).to receive(:new).and_return(mock_faraday_connection)
424+
allow(mock_faraday_connection).to receive_message_chain(:headers, :[]=)
425+
allow(mock_faraday_connection).to receive(:post).and_return(mock_response)
426+
427+
expect {
428+
client.checkout.payments_api.payments({})
429+
}.to raise_error(Adyen::NotFoundError) do |error|
430+
expect(error.code).to eq(404)
431+
expect(error.msg).to eq('Not found error')
432+
end
433+
end
404434
end

0 commit comments

Comments
 (0)