Skip to content

Commit

Permalink
Adyen: Fix error_code_from for unknown errors
Browse files Browse the repository at this point in the history
Updated `error_code_from` to respond with default gateway error code in
case error is not listed in `STANDARD_ERROR_CODE_MAPPING`.

CE-2512

Remote:
123 tests, 440 assertions, 2 failures, 0 errors, 0 pendings, 0 omissions, 0 notifications
98.374% passed

Unit:
5146 tests, 75480 assertions, 0 failures, 0 errors, 0 pendings, 0 omissions, 0 notifications
100% passed

Rubocop:
739 files inspected, no offenses detected
  • Loading branch information
ajawadmirza committed Apr 6, 2022
1 parent b90037b commit f7b0d5f
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
* CyberSource: Update and fix test coverage [peteroas] #4374
* Airwallex: QA fixes for address and create_setup_intent handling [therufs] #4377
* Airwallex: add `descriptor` field and update logic for sending `request_id` and `merchant_order_id` [dsmcclain] #4379
* Adyen: Fix `error_code_from` implementation [ajawadmirza] #4381

== Version 1.125.0 (January 20, 2022)
* Wompi: support gateway [therufs] #4173
Expand Down
2 changes: 1 addition & 1 deletion lib/active_merchant/billing/gateways/adyen.rb
Original file line number Diff line number Diff line change
Expand Up @@ -672,7 +672,7 @@ def post_data(action, parameters = {})
end

def error_code_from(response)
STANDARD_ERROR_CODE_MAPPING[response['errorCode']]
STANDARD_ERROR_CODE_MAPPING[response['errorCode']] || response['errorCode']
end

def network_transaction_id_from(response)
Expand Down
18 changes: 18 additions & 0 deletions test/remote/gateways/remote_adyen_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -638,6 +638,24 @@ def test_successful_authorize_and_capture_with_unionpay_card
assert_equal '[capture-received]', capture.message
end

def test_error_code_render_from_response
options = {
order_id: '123',
email: '[email protected]',
billing_address: {
address2: 'address2',
zip: '31331',
city: 'Wanaque',
state: 'NJ',
country: 'IE'
},
delivery_date: 'invalid'
}
response = @gateway.authorize(@amount, @credit_card, options)
assert_failure response
assert_equal '702', response.error_code
end

def test_partial_capture
auth = @gateway.authorize(@amount, @credit_card, @options)
assert_success auth
Expand Down
38 changes: 38 additions & 0 deletions test/unit/gateways/adyen_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,22 @@ def test_failed_authorize
assert_failure response
end

def test_standard_error_code_mapping
@gateway.expects(:ssl_post).returns(failed_billing_field_response)

response = @gateway.authorize(@amount, @credit_card, @options)
assert_failure response
assert_equal 'incorrect_address', response.error_code
end

def test_unknown_error_code_mapping
@gateway.expects(:ssl_post).returns(failed_invalid_delivery_field_response)

response = @gateway.authorize(@amount, @credit_card, @options)
assert_failure response
assert_equal '702', response.error_code
end

def test_failed_authorise3d
@gateway.expects(:ssl_post).returns(failed_authorize_response)

Expand Down Expand Up @@ -1608,6 +1624,28 @@ def successful_verify_response
RESPONSE
end

def failed_billing_field_response
<<~RESPONSE
{
"status": 422,
"errorCode": "132",
"message": "Required field 'billingAddress.street' is not provided.",
"errorType": "validation"
}
RESPONSE
end

def failed_invalid_delivery_field_response
<<~RESPONSE
{
"status": 500,
"errorCode": "702",
"message": "The 'deliveryDate' field is invalid. Invalid date (year)",
"errorType": "validation"
}
RESPONSE
end

def failed_verify_response
<<-RESPONSE
{
Expand Down

0 comments on commit f7b0d5f

Please sign in to comment.