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

CyberSource Rest: Add the mcc field #5253

Open
wants to merge 1 commit 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: 7 additions & 2 deletions lib/active_merchant/billing/gateways/cyber_source.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1103,10 +1103,15 @@ def add_installments(xml, options)
end

def add_threeds_services(xml, options)
xml.tag! 'payerAuthEnrollService', { 'run' => 'true' } if options[:payer_auth_enroll_service]
if options[:payer_auth_enroll_service]
xml.tag! 'payerAuthEnrollService', { 'run' => 'true' } do
xml.tag! 'MCC', options[:mcc] if options[:mcc]
end
end

if options[:payer_auth_validate_service]
xml.tag! 'payerAuthValidateService', { 'run' => 'true' } do
xml.tag! 'signedPARes', options[:pares]
xml.tag! 'signedPARes', options[:pares] if options[:pares]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any particular reason to add this? I think it should be reliably included in options based on the way we communicate these details from the Spreedly side

end
end
end
Expand Down
1 change: 1 addition & 0 deletions lib/active_merchant/billing/gateways/cyber_source_rest.rb
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ def add_three_ds(post, payment_method, options)
post[:consumerAuthenticationInformation][:paSpecificationVersion] = three_d_secure[:version] if three_d_secure[:version]
post[:consumerAuthenticationInformation][:directoryServerTransactionID] = three_d_secure[:ds_transaction_id] if three_d_secure[:ds_transaction_id]
post[:consumerAuthenticationInformation][:eciRaw] = three_d_secure[:eci] if three_d_secure[:eci]
post[:consumerAuthenticationInformation][:mcc] = options[:mcc] if options[:mcc]
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hey @jcreiff after our discussion I changed it to be be pulling the mcc from the options object however would it pose any issue or concern if line 128 is still there? im thinking theres no point to send the mcc by itself if none of the rest of the threeds fields are there anyways but wanted to run it by you, thanks!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that guard clause should stay as is - the 3DS info is the main reason to enter this block of logic, and it doesn't seem like we want to entertain the option of only entering this method to add MCC.

However, this brings up a question about the requested use case that initiated this work, which I will follow up on in a separate thread

if three_d_secure[:xid].present?
post[:consumerAuthenticationInformation][:xid] = three_d_secure[:xid]
else
Expand Down
13 changes: 13 additions & 0 deletions test/remote/gateways/remote_cyber_source_rest_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -569,6 +569,19 @@ def test_successful_authorize_with_3ds2_visa
assert_success auth
end

def test_successful_authorize_with_3ds2_mcc
@options[:three_d_secure] = {
version: '2.2.0',
cavv: '3q2+78r+ur7erb7vyv66vv\/\/\/\/8=',
eci: '05',
ds_transaction_id: 'ODUzNTYzOTcwODU5NzY3Qw==',
enrolled: 'true',
authentication_response_status: 'Y'
}
auth = @gateway.authorize(@amount, @visa_card, @options.merge(mcc: '1234'))
assert_success auth
end

def test_successful_authorize_with_3ds2_mastercard
@options[:three_d_secure] = {
version: '2.2.0',
Expand Down
28 changes: 17 additions & 11 deletions test/remote/gateways/remote_cyber_source_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1100,20 +1100,26 @@ def test_successful_retrieve_subscription

def test_3ds_enroll_request_via_purchase
assert response = @gateway.purchase(1202, @three_ds_enrolled_card, @options.merge(payer_auth_enroll_service: true))
assert_equal '475', response.params['reasonCode']
assert !response.params['acsURL'].blank?
assert !response.params['paReq'].blank?
assert !response.params['xid'].blank?
assert !response.success?
assert_equal '100', response.params['reasonCode']
assert response.success?
end

def test_3ds_enroll_and_mcc_request_via_purchase
assert response = @gateway.purchase(1202, @three_ds_enrolled_card, @options.merge(payer_auth_enroll_service: true, mcc: '1234'))
assert_equal '100', response.params['reasonCode']
assert response.success?
end

def test_3ds_enroll_request_via_authorize
assert response = @gateway.authorize(1202, @three_ds_enrolled_card, @options.merge(payer_auth_enroll_service: true))
assert_equal '475', response.params['reasonCode']
assert !response.params['acsURL'].blank?
assert !response.params['paReq'].blank?
assert !response.params['xid'].blank?
assert !response.success?
assert response = @gateway.authorize(1202, @three_ds_enrolled_card, @options.merge(payer_auth_enroll_service: true, mcc: '1234'))
assert_equal '100', response.params['reasonCode']
assert response.success?
end

def test_3ds_enroll_and_mcc_request_via_authorize
assert response = @gateway.authorize(1202, @three_ds_enrolled_card, @options.merge(payer_auth_enroll_service: true, mcc: '1234'))
assert_equal '100', response.params['reasonCode']
assert response.success?
end

def test_successful_3ds_requests_with_unenrolled_card
Expand Down
3 changes: 2 additions & 1 deletion test/unit/gateways/cyber_source_rest_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -484,7 +484,7 @@ def test_mastercard_purchase_with_3ds2
cavv_algorithm: '2'
}
stub_comms do
@gateway.purchase(100, @master_card, @options)
@gateway.purchase(100, @master_card, @options.merge(mcc: '1234'))
end.check_request do |_endpoint, data, _headers|
json_data = JSON.parse(data)
assert_equal json_data['consumerAuthenticationInformation']['ucafAuthenticationData'], '3q2+78r+ur7erb7vyv66vv\/\/\/\/8='
Expand All @@ -496,6 +496,7 @@ def test_mastercard_purchase_with_3ds2
assert_equal json_data['consumerAuthenticationInformation']['xid'], '3q2+78r+ur7erb7vyv66vv\/\/\/\/8='
assert_equal json_data['consumerAuthenticationInformation']['veresEnrolled'], 'true'
assert_equal json_data['consumerAuthenticationInformation']['paresStatus'], 'Y'
assert_equal json_data['consumerAuthenticationInformation']['mcc'], '1234'
end.respond_with(successful_purchase_response)
end

Expand Down
7 changes: 4 additions & 3 deletions test/unit/gateways/cyber_source_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1473,11 +1473,12 @@ def test_malformed_xml_handling
assert response.test?
end

def test_3ds_enroll_response
def test_3ds_enroll_and_mcc_response
purchase = stub_comms do
@gateway.purchase(@amount, @credit_card, @options.merge(payer_auth_enroll_service: true))
@gateway.purchase(@amount, @credit_card, @options.merge(payer_auth_enroll_service: true, mcc: '1234'))
end.check_request do |_endpoint, data, _headers|
assert_match(/\<payerAuthEnrollService run=\"true\"\/\>/, data)
assert_match(/\<payerAuthEnrollService run=\"true\"\>/, data)
assert_match(/\<MCC\>1234\<\/MCC\>/, data)
end.respond_with(threedeesecure_purchase_response)

assert_failure purchase
Expand Down
Loading