Skip to content

Commit

Permalink
Update the error_code_from method to grab and alpha_numeric characters
Browse files Browse the repository at this point in the history
Spreedly ref: ECS-3536
  • Loading branch information
DustinHaefele committed May 23, 2024
1 parent 23cc081 commit 1fa6320
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
5 changes: 4 additions & 1 deletion lib/active_merchant/billing/gateways/adyen.rb
Original file line number Diff line number Diff line change
Expand Up @@ -903,7 +903,10 @@ def post_data(action, parameters = {})
end

def error_code_from(response)
response.dig('additionalData', 'refusalReasonRaw').try(:scan, /^\d+/).try(:first) || STANDARD_ERROR_CODE_MAPPING[response['errorCode']] || response['errorCode'] || response['refusalReason']
response.dig('additionalData', 'refusalReasonRaw').try(:match, /^([a-zA-Z0-9 ]{1,5})(?=:)/).try(:[], 1).try(:strip) ||
STANDARD_ERROR_CODE_MAPPING[response['errorCode']] ||
response['errorCode'] ||
response['refusalReason']
end

def network_transaction_id_from(response)
Expand Down
25 changes: 25 additions & 0 deletions test/unit/gateways/adyen_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,16 @@ def test_failed_authorise_visa
response = @gateway.send(:commit, 'authorise', {}, {})

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

def test_failed_fraud_raw_refusal
@gateway.expects(:ssl_post).returns(failed_fraud_visa_response)

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

assert_equal 'N7', response.error_code
assert_failure response
end

Expand All @@ -359,6 +369,7 @@ def test_failed_authorise_mastercard
response = @gateway.send(:commit, 'authorise', {}, {})

assert_equal 'Refused | 01 : New account information available', response.message
assert_equal '01', response.error_code
assert_failure response
end

Expand Down Expand Up @@ -1916,6 +1927,20 @@ def failed_authorize_visa_response
RESPONSE
end

def failed_fraud_visa_response
<<-RESPONSE
{
"additionalData":
{
"refusalReasonRaw": "N7 : FRAUD"
},
"refusalReason": "Refused",
"pspReference":"8514775559925128",
"resultCode":"Refused"
}
RESPONSE
end

def failed_without_raw_refusal_reason
<<-RESPONSE
{
Expand Down

0 comments on commit 1fa6320

Please sign in to comment.