Skip to content

Commit

Permalink
Payflow: include AuthenticationStatus with 3DS 2.x (#4168)
Browse files Browse the repository at this point in the history
  • Loading branch information
bbraschi authored Oct 28, 2021
1 parent 3d8b4e2 commit 44d0383
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
* Payflow: use proper case for 3DS 2.x element names [bbraschi] #4113
* Realex: Add support for stored credentials [dsmcclain] #4170
* Moka: Add support for InstallmentNumber field [dsmcclain] #4172
* Payflow: include AuthenticationStatus for 3DS 2.x [bbraschi] #4168

== Version 1.123.0 (September 10th, 2021)
* Paysafe: Add gateway integration [meagabeth] #4085
Expand Down
16 changes: 12 additions & 4 deletions lib/active_merchant/billing/gateways/payflow.rb
Original file line number Diff line number Diff line change
Expand Up @@ -296,11 +296,19 @@ def add_three_d_secure(options, xml)
end

def authentication_status(three_d_secure, xml)
if three_d_secure[:authentication_response_status].present?
xml.tag! 'Status', three_d_secure[:authentication_response_status]
elsif three_d_secure[:directory_response_status].present?
xml.tag! 'Status', three_d_secure[:directory_response_status]
status = if three_d_secure[:authentication_response_status].present?
three_d_secure[:authentication_response_status]
elsif three_d_secure[:directory_response_status].present?
three_d_secure[:directory_response_status]
end
if status.present?
xml.tag! 'Status', status
xml.tag! 'AuthenticationStatus', status if version_2_or_newer?(three_d_secure)
end
end

def version_2_or_newer?(three_d_secure)
three_d_secure[:version]&.start_with?('2')
end

def credit_card_type(credit_card)
Expand Down
24 changes: 24 additions & 0 deletions test/unit/gateways/payflow_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,28 @@ def test_authorization_with_three_d_secure_option_with_ds_transaction_id_include
end.respond_with(successful_authorization_response)
end

def test_authorization_with_three_d_secure_option_with_version_2_x_and_authentication_response_status_include_authentication_status
expected_version = '2.2.0'
expected_authentication_status = SUCCESSFUL_AUTHENTICATION_STATUS
three_d_secure_option = three_d_secure_option(options: { version: expected_version })
stub_comms do
@gateway.authorize(@amount, @credit_card, @options.merge(three_d_secure_option))
end.check_request do |_endpoint, data, _headers|
assert_three_d_secure REXML::Document.new(data), authorize_buyer_auth_result_path, expected_version: expected_version, expected_authentication_status: expected_authentication_status
end.respond_with(successful_authorization_response)
end

def test_authorization_with_three_d_secure_option_with_version_1_x_and_authentication_response_status_does_not_include_authentication_status
expected_version = '1.0.2'
expected_authentication_status = nil
three_d_secure_option = three_d_secure_option(options: { version: expected_version })
stub_comms do
@gateway.authorize(@amount, @credit_card, @options.merge(three_d_secure_option))
end.check_request do |_endpoint, data, _headers|
assert_three_d_secure REXML::Document.new(data), authorize_buyer_auth_result_path, expected_version: expected_version, expected_authentication_status: expected_authentication_status
end.respond_with(successful_authorization_response)
end

def test_successful_authorization_with_more_options
partner_id = 'partner_id'
PayflowGateway.application_id = partner_id
Expand Down Expand Up @@ -939,10 +961,12 @@ def assert_three_d_secure(
xml_doc,
buyer_auth_result_path,
expected_status: SUCCESSFUL_AUTHENTICATION_STATUS,
expected_authentication_status: nil,
expected_version: nil,
expected_ds_transaction_id: nil
)
assert_text_value_or_nil expected_status, REXML::XPath.first(xml_doc, "#{buyer_auth_result_path}/Status")
assert_text_value_or_nil(expected_authentication_status, REXML::XPath.first(xml_doc, "#{buyer_auth_result_path}/AuthenticationStatus"))
assert_text_value_or_nil 'QvDbSAxSiaQs241899E0', REXML::XPath.first(xml_doc, "#{buyer_auth_result_path}/AuthenticationId")
assert_text_value_or_nil 'pareq block', REXML::XPath.first(xml_doc, "#{buyer_auth_result_path}/PAReq")
assert_text_value_or_nil 'https://bankacs.bank.com/ascurl', REXML::XPath.first(xml_doc, "#{buyer_auth_result_path}/ACSUrl")
Expand Down

0 comments on commit 44d0383

Please sign in to comment.