Skip to content

Commit

Permalink
Adyen: Support raw refusal reason
Browse files Browse the repository at this point in the history
ECS-3082

A change was made two months ago to provide the MerchantAdviceCode
as the error message if available before falling back to the
refusalReasonRaw value. Some merchants do not want this change
in messaging so this gives them a way to elect which error
message they want

Test Summary
Remote:
11 failing tests on master
134 tests, 447 assertions, 11 failures, 0 errors, 0 pendings, 0 omissions, 0 notifications
91.791% passed
  • Loading branch information
aenand committed Jul 27, 2023
1 parent 413f4af commit 104d857
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

== HEAD
* PaymentExpress: Correct endpoints [steveh] #4827
* Adyen: Add option to elect which error message [aenand] #4843

== Version 1.134.0 (July 25, 2023)
* Update required Ruby version [almalee24] #4823
Expand Down
18 changes: 14 additions & 4 deletions lib/active_merchant/billing/gateways/adyen.rb
Original file line number Diff line number Diff line change
Expand Up @@ -706,7 +706,7 @@ def commit(action, parameters, options)
success = success_from(action, response, options)
Response.new(
success,
message_from(action, response),
message_from(action, response, options),
response,
authorization: authorization_from(action, parameters, response),
test: test?,
Expand Down Expand Up @@ -776,20 +776,30 @@ def success_from(action, response, options)
end
end

def message_from(action, response)
return authorize_message_from(response) if %w(authorise authorise3d authorise3ds2).include?(action.to_s)
def message_from(action, response, options = {})
return authorize_message_from(response, options) if %w(authorise authorise3d authorise3ds2).include?(action.to_s)

response['response'] || response['message'] || response['result'] || response['resultCode']
end

def authorize_message_from(response)
def authorize_message_from(response, options = {})
return raw_authorize_error_message(response) if options[:raw_error_message]

if response['refusalReason'] && response['additionalData'] && (response['additionalData']['merchantAdviceCode'] || response['additionalData']['refusalReasonRaw'])
"#{response['refusalReason']} | #{response['additionalData']['merchantAdviceCode'] || response['additionalData']['refusalReasonRaw']}"
else
response['refusalReason'] || response['resultCode'] || response['message'] || response['result']
end
end

def raw_authorize_error_message(response)
if response['refusalReason'] && response['additionalData'] && response['additionalData']['refusalReasonRaw']
"#{response['refusalReason']} | #{response['additionalData']['refusalReasonRaw']}"
else
response['refusalReason'] || response['resultCode'] || response['message'] || response['result']
end
end

def authorization_from(action, parameters, response)
return nil if response['pspReference'].nil?

Expand Down
9 changes: 9 additions & 0 deletions test/unit/gateways/adyen_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,15 @@ def test_failed_authorise_mastercard
assert_failure response
end

def test_failed_authorise_mastercard_raw_error_message
@gateway.expects(:ssl_post).returns(failed_authorize_mastercard_response)

response = @gateway.send(:commit, 'authorise', {}, { raw_error_message: true })

assert_equal 'Refused | 01: Refer to card issuer', response.message
assert_failure response
end

def test_successful_capture
@gateway.expects(:ssl_post).returns(successful_capture_response)
response = @gateway.capture(@amount, '7914775043909934')
Expand Down

0 comments on commit 104d857

Please sign in to comment.