Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adyen: Fail unexpected 3DS responses #3546

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 7 additions & 2 deletions lib/active_merchant/billing/gateways/adyen.rb
Original file line number Diff line number Diff line change
Expand Up @@ -471,7 +471,7 @@ def commit(action, parameters, options)
raw_response = e.response.body
response = parse(raw_response)
end
success = success_from(action, response)
success = success_from(action, response, options)
Response.new(
success,
message_from(action, response),
Expand Down Expand Up @@ -520,7 +520,12 @@ def request_headers(options)
headers
end

def success_from(action, response)
def success_from(action, response, options)
if ['RedirectShopper', 'ChallengeShopper'].include?(response.dig('resultCode')) && !options[:execute_threed] && !options[:threed_dynamic]
response['refusalReason'] = 'Received unexpected 3DS authentication response. Use the execute_threed and/or threed_dynamic options to initiate a proper 3DS flow.'
return false
end

case action.to_s
when 'authorise', 'authorise3d'
['Authorised', 'Received', 'RedirectShopper'].include?(response['resultCode'])
Expand Down
10 changes: 10 additions & 0 deletions test/remote/gateways/remote_adyen_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,16 @@ def test_successful_authorize_with_3ds_dynamic_rule_broken
assert_equal response.params['resultCode'], 'Authorised'
end

# Fail in situations where neither execute_threed nor dynamic_threed is
# present, but the account is set to dynamic 3ds and it is triggered. This
# test assumes a Dynamic 3DS rule set for the Adyen test account to always
# perform 3ds auth for an amount of 8484
def test_purchase_fails_on_unexpected_3ds_initiation
response = @gateway.purchase(8484, @three_ds_enrolled_card, @options)
assert_failure response
assert_match 'Received unexpected 3DS authentication response', response.message
end

def test_successful_purchase_with_auth_data_via_threeds1_standalone
eci = '05'
cavv = '3q2+78r+ur7erb7vyv66vv\/\/\/\/8='
Expand Down
7 changes: 7 additions & 0 deletions test/unit/gateways/adyen_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,13 @@ def test_successful_authorize_with_3ds
refute response.params['paRequest'].blank?
end

def test_failed_authorize_with_unexpected_3ds
@gateway.expects(:ssl_post).returns(successful_authorize_with_3ds_response)
response = @gateway.authorize(@amount, @three_ds_enrolled_card, @options)
assert_failure response
assert_match 'Received unexpected 3DS authentication response', response.message
end

def test_successful_authorize_with_recurring_contract_type
stub_comms do
@gateway.authorize(100, @credit_card, @options.merge({recurring_contract_type: 'ONECLICK'}))
Expand Down