Skip to content

Commit

Permalink
CheckoutV2: Parse AVS and CVV checks
Browse files Browse the repository at this point in the history
The CheckoutV2 gateway had logic in the response parsing
method that would limit the scope of parsing to only authorize or
purchase. This presents an issue for merchants using `verify-payment`
or other methods that may have the AVS and CVV checks in the response.

This commit also updates the AVS and CVV checks to use `dig` to
safely try parsing out the values

Test Summary
Remote:
93 tests, 227 assertions, 0 failures, 0 errors, 0 pendings, 0 omissions, 0 notifications
100% passed
  • Loading branch information
aenand committed Jul 11, 2023
1 parent 0521d61 commit c8b989e
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 7 deletions.
1 change: 1 addition & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
* Stripe PI: Update parameters for creation of customer [almalee24] #4782
* PaywayDotCom: update `live_url` [jcreiff] #4824
* Stripe & Stripe PI: Update login key validation [almalee24] #4816
* CheckoutV2: Parse the AVS and CVV checks more often [aenand] #4822

== Version 1.131.0 (June 21, 2023)
* Redsys: Add supported countries [jcreiff] #4811
Expand Down
11 changes: 4 additions & 7 deletions lib/active_merchant/billing/gateways/checkout_v2.rb
Original file line number Diff line number Diff line change
Expand Up @@ -363,9 +363,6 @@ def commit(action, post, options, authorization = nil, method = :post)
end

def response(action, succeeded, response, source_id = nil)
successful_response = succeeded && action == :purchase || action == :authorize
avs_result = successful_response ? avs_result(response) : nil
cvv_result = successful_response ? cvv_result(response) : nil
authorization = authorization_from(response) unless action == :unstore
body = action == :unstore ? { response_code: response.to_s } : response
Response.new(
Expand All @@ -375,8 +372,8 @@ def response(action, succeeded, response, source_id = nil)
authorization: authorization,
error_code: error_code_from(succeeded, body),
test: test?,
avs_result: avs_result,
cvv_result: cvv_result
avs_result: avs_result(response),
cvv_result: cvv_result(response)
)
end

Expand Down Expand Up @@ -427,11 +424,11 @@ def base_url
end

def avs_result(response)
response['source'] && response['source']['avs_check'] ? AVSResult.new(code: response['source']['avs_check']) : nil
response.respond_to?(:dig) && response.dig('source', 'avs_check') ? AVSResult.new(code: response['source']['avs_check']) : nil
end

def cvv_result(response)
response['source'] && response['source']['cvv_check'] ? CVVResult.new(response['source']['cvv_check']) : nil
response.respond_to?(:dig) && response.dig('source', 'cvv_check') ? CVVResult.new(response['source']['cvv_check']) : nil
end

def parse(body, error: nil)
Expand Down

0 comments on commit c8b989e

Please sign in to comment.