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

VersaPay: Improve Message Error and Error Mapping #5357

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 2 additions & 7 deletions lib/active_merchant/billing/gateways/versa_pay.rb
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@ def message_from(response, action)
gateway_response_errors = gateway_errors_message(response)

response_message = {
error: response.dig('error') || response.dig('wallets', 'error'),
errors: response.dig('errors')&.join(', ').presence,
gateway_error_message: first_transaction&.dig('gateway_error_message').presence,
gateway_response_errors: gateway_response_errors.presence
Expand All @@ -224,13 +225,7 @@ def authorization_from(response)
def error_code_from(response, action)
return if success_from(response, action)

first_transaction = response['transactions']&.first
error_info = {
gateway_error_code: first_transaction&.dig('gateway_error_code'),
response_code: response['response_code']
}.compact

error_info.map { |key, value| "#{key}: #{value}" }.join(' | ')
response.dig('transactions', 0, 'gateway_error_code')
end

def gateway_errors_message(response)
Expand Down
43 changes: 34 additions & 9 deletions test/remote/gateways/remote_versa_pay_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def test_failed_authorize_declined_credit_card
assert_equal response.authorization, "#{response.params['transaction']}||"
assert_equal response.params['transactions'][0]['action'], 'verify'

assert_equal response.error_code, 'gateway_error_code: 567.005 | response_code: 999'
assert_equal response.error_code, '567.005'
end

def test_failed_authorize_declined_amount
Expand All @@ -64,7 +64,7 @@ def test_failed_authorize_declined_amount
assert_equal response.authorization, "#{response.params['transaction']}||"
assert_equal response.params['transactions'][0]['action'], 'verify'

assert_equal response.error_code, 'gateway_error_code: 567.005 | response_code: 999'
assert_equal response.error_code, '567.005'
end

def test_successful_purchase
Expand All @@ -82,15 +82,15 @@ def test_failed_purchase_declined_credit_card
assert_failure response
assert_equal response.message, 'gateway_error_message: DECLINED | gateway_response_errors: [gateway - DECLINED]'
assert_equal response.params['transactions'][0]['action'], 'verify'
assert_equal response.error_code, 'gateway_error_code: 567.005 | response_code: 999'
assert_equal response.error_code, '567.005'
end

def test_failed_purchase_declined_amount
response = @gateway.purchase(501, @decline_credit_card, @options)
assert_failure response
assert_equal response.message, 'gateway_error_message: DECLINED | gateway_response_errors: [gateway - DECLINED]'
assert_equal response.params['transactions'][0]['action'], 'verify'
assert_equal response.error_code, 'gateway_error_code: 567.005 | response_code: 999'
assert_equal response.error_code, '567.005'
end

def test_failed_purchase_no_billing_address
Expand All @@ -101,14 +101,14 @@ def test_failed_purchase_no_billing_address

assert_equal response.message, 'errors: fund_address_unspecified'

assert_equal response.error_code, 'response_code: 999'
assert_equal response.error_code, nil
end

def test_failed_purchase_no_found_credit_card
response = @gateway.purchase(@amount, @no_valid_date_credit_card, @options)
assert_failure response
assert_equal response.message, 'errors: Validation failed: Credit card gateway token not found'
assert_equal response.error_code, 'response_code: 999'
assert_equal response.error_code, nil
end

def test_successful_capture
Expand Down Expand Up @@ -202,7 +202,7 @@ def test_failed_void
response = @gateway.void('123456', @options)
assert_failure response
assert_equal response.message, 'errors: order_not_found' # come from a 500 HTTP error
assert_equal response.error_code, 'response_code: 250'
assert_equal response.error_code, nil
end

def test_successful_refund
Expand All @@ -221,7 +221,7 @@ def test_failed_refund
response = @gateway.refund(@amount, '123456', @options)
assert_failure response
assert_equal response.message, 'errors: order_not_found' # come from a 500 HTTP error
assert_equal response.error_code, 'response_code: 250'
assert_equal response.error_code, nil
end

def test_successful_credit
Expand All @@ -237,7 +237,7 @@ def test_failed_credit
response = @gateway.credit(@amount, @no_valid_date_credit_card, @options)
assert_failure response
assert_equal response.message, 'errors: Validation failed: Credit card gateway token not found'
assert_equal response.error_code, 'response_code: 999'
assert_equal response.error_code, nil
end

def test_successful_store
Expand All @@ -258,6 +258,31 @@ def test_successful_store
assert_match response.params['wallets'][0]['credit_cards'][0]['token'], response.authorization
end

def test_failed_account_loggin
response = @bad_gateway.purchase(@credit_card, @options)
assert_failure response
assert_equal response.message, 'error: Please log in or create an account to continue.'
assert_equal response.error_code, nil
end

def test_failed_stored_with_invalid_cvv
credit_card = @credit_card.dup
credit_card.verification_value = nil
response = @gateway.store(credit_card, @options)
assert_failure response
assert_equal response.message, "error: Validation failed: CVV can't be blank, CVV should be a number, CVV too short (minimum is 3 characters), CVV should be 3 digits"
assert_equal response.error_code, nil
end

def test_failed_purchase_with_invalid_cvv
credit_card = @credit_card.dup
credit_card.verification_value = nil
response = @gateway.purchase(@amount, credit_card, @options)
assert_failure response
assert_equal response.message, "errors: CVV can't be blank, CVV should be a number, CVV too short (minimum is 3 characters"
assert_equal response.error_code, nil
end

def test_successful_purchase_after_store
store = @gateway.store(@credit_card, @options)
assert_success store
Expand Down
26 changes: 24 additions & 2 deletions test/unit/gateways/versa_pay_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,22 @@ def test_build_store_unstore_request_url
def test_error_code_from_errors
# a HTTP 412 response structure
error = @gateway.send(:error_code_from, { 'success' => false, 'errors' => ['fund_address_unspecified'], 'response_code' => 999 }, 'sale')
assert_equal error, 'response_code: 999'
assert_equal error, nil
gasb150 marked this conversation as resolved.
Show resolved Hide resolved
end

def test_error_code_from_gateway_error_code
error = @gateway.send(:error_code_from, declined_errors, 'sale')
assert_equal error, 'gateway_error_code: 567.005 | response_code: 999'
assert_equal error, '567.005'
end

def test_message_error_from_wallet
message = @gateway.send(:message_from, wallet_error, 'store')
assert_equal message, "error: Validation failed: CVV can't be blank, CVV should be a number, CVV too short (minimum is 3 characters), CVV should be 3 digits"
end

def test_message_error_from_loggin
message = @gateway.send(:message_from, log_in_error, 'authorize')
assert_equal message, 'error: Please log in or create an account to continue.'
end

def test_message_from_successful_purchase
Expand Down Expand Up @@ -857,6 +867,18 @@ def declined_errors
'response_code' => 999 }
end

def log_in_error
{ 'error' => 'Please log in or create an account to continue.' }
end

def wallet_error
{ 'wallet_token' => nil,
'fund_token' => nil,
'wallets' =>
{ 'error' =>
"Validation failed: CVV can't be blank, CVV should be a number, CVV too short (minimum is 3 characters), CVV should be 3 digits" } }
end

def pre_scrubbed
<<~PRE_SCRUBBED
opening connection to uat.versapay.com:443...
Expand Down
Loading