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

Barclaycard Smartpay: 3DS2 Support #3251

Merged
merged 1 commit into from
Jun 25, 2019
Merged
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
1 change: 1 addition & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
* NMI: Add support for stored credentials [bayprogrammer] #3243
* Spreedly: Consolidate API requests and support bank accounts [lancecarlson] #3105
* BPoint: Hook up merchant_reference and CRN fields [curiousepic] #3249
* Barclaycard Smartpay: Add support for 3DS2 [britth] #3251

== Version 1.95.0 (May 23, 2019)
* Adyen: Constantize version to fix subdomains [curiousepic] #3228
Expand Down
49 changes: 39 additions & 10 deletions lib/active_merchant/billing/gateways/barclaycard_smartpay.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class BarclaycardSmartpayGateway < Gateway
self.homepage_url = 'https://www.barclaycardsmartpay.com/'
self.display_name = 'Barclaycard Smartpay'

API_VERSION = 'v30'
API_VERSION = 'v40'

def initialize(options = {})
requires!(options, :company, :merchant, :password)
Expand All @@ -37,7 +37,7 @@ def authorize(money, creditcard, options = {})
post[:card] = credit_card_hash(creditcard)
post[:billingAddress] = billing_address_hash(options) if options[:billing_address]
post[:deliveryAddress] = shipping_address_hash(options) if options[:shipping_address]
add_3ds(post, options) if options[:execute_threed]
add_3ds(post, options)
Copy link

Choose a reason for hiding this comment

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

We don't need the :execute_threed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

good question - i was mostly leaning on what's happening for adyen, which, in the add_3ds method will add 3ds2 browser info if that gets passed in (whether it receives the execute_threed flag or not), or will check that a 3ds flag is present before falling back to adding 3ds1 data

Copy link

Choose a reason for hiding this comment

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

👍 Might be something to monitor when it goes in production.

commit('authorise', post)
end

Expand Down Expand Up @@ -186,7 +186,7 @@ def authorization_from(parameters, response)
end

def parse_avs_code(response)
AVS_MAPPING[response['avsResult'][0..1].strip] if response['avsResult']
AVS_MAPPING[response['additionalData']['avsResult'][0..1].strip] if response.dig('additionalData', 'avsResult')
end

def flatten_hash(hash, prefix = nil)
Expand All @@ -210,12 +210,18 @@ def headers(account, password)
end

def parse(response)
Hash[
response.split('&').map do |x|
key, val = x.split('=', 2)
[key.split('.').last, CGI.unescape(val)]
parsed_response = {}
params = CGI.parse(response)
params.each do |key, value|
parsed_key = key.split('.', 2)
if parsed_key.size > 1
parsed_response[parsed_key[0]] ||= {}
parsed_response[parsed_key[0]][parsed_key[1]] = value[0]
else
parsed_response[parsed_key[0]] = value[0]
end
]
end
parsed_response
end

def post_data(data)
Expand Down Expand Up @@ -343,8 +349,31 @@ def store_request(options)
end

def add_3ds(post, options)
post[:additionalData] = { executeThreeD: 'true' }
post[:browserInfo] = { userAgent: options[:user_agent], acceptHeader: options[:accept_header] }
if three_ds_2_options = options[:three_ds_2]
if browser_info = three_ds_2_options[:browser_info]
post[:browserInfo] = {
acceptHeader: browser_info[:accept_header],
colorDepth: browser_info[:depth],
javaEnabled: browser_info[:java],
language: browser_info[:language],
screenHeight: browser_info[:height],
screenWidth: browser_info[:width],
timeZoneOffset: browser_info[:timezone],
userAgent: browser_info[:user_agent]
}

if device_channel = three_ds_2_options[:channel]
post[:threeDS2RequestData] = {
deviceChannel: device_channel,
notificationURL: three_ds_2_options[:notification_url]
}
end
end
else
return unless options[:execute_threed] || options[:threed_dynamic]
post[:browserInfo] = { userAgent: options[:user_agent], acceptHeader: options[:accept_header] }
post[:additionalData] = { executeThreeD: 'true' } if options[:execute_threed]
end
end
end
end
Expand Down
34 changes: 34 additions & 0 deletions test/remote/gateways/remote_barclaycard_smartpay_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,30 @@ def setup
zip: '95014',
country: 'US'
})

@normalized_3ds_2_options = {
reference: '345123',
shopper_email: '[email protected]',
shopper_ip: '77.110.174.153',
shopper_reference: 'John Smith',
billing_address: address(),
order_id: '123',
stored_credential: {reason_type: 'unscheduled'},
three_ds_2: {
channel: 'browser',
browser_info: {
accept_header: 'unknown',
depth: 100,
java: false,
language: 'US',
height: 1000,
width: 500,
timezone: '-120',
user_agent: 'unknown'
},
notification_url: 'https://example.com/notification'
}
}
end

def teardown
Expand Down Expand Up @@ -176,6 +200,16 @@ def test_successful_authorize_with_3ds
refute response.params['paRequest'].blank?
end

def test_successful_authorize_with_3ds2_browser_client_data
assert response = @gateway.authorize(@amount, @three_ds_enrolled_card, @normalized_3ds_2_options)
assert response.test?
refute response.authorization.blank?
assert_equal response.params['resultCode'], 'IdentifyShopper'
refute response.params['additionalData']['threeds2.threeDS2Token'].blank?
refute response.params['additionalData']['threeds2.threeDSServerTransID'].blank?
refute response.params['additionalData']['threeds2.threeDSMethodURL'].blank?
end

def test_successful_authorize_and_capture
auth = @gateway.authorize(@amount, @credit_card, @options)
assert_success auth
Expand Down
40 changes: 40 additions & 0 deletions test/unit/gateways/barclaycard_smartpay_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,30 @@ def setup
zip: '95014',
country: 'US'
})

@normalized_3ds_2_options = {
reference: '345123',
shopper_email: '[email protected]',
shopper_ip: '77.110.174.153',
shopper_reference: 'John Smith',
billing_address: address(),
order_id: '123',
stored_credential: {reason_type: 'unscheduled'},
three_ds_2: {
channel: 'browser',
browser_info: {
accept_header: 'unknown',
depth: 100,
java: false,
language: 'US',
height: 1000,
width: 500,
timezone: '-120',
user_agent: 'unknown'
},
notification_url: 'https://example.com/notification'
}
}
end

def test_successful_purchase
Expand Down Expand Up @@ -189,6 +213,18 @@ def test_successful_authorize_with_3ds
assert response.test?
end

def test_successful_authorize_with_3ds2_browser_client_data
@gateway.stubs(:ssl_post).returns(successful_authorize_with_3ds2_response)

assert response = @gateway.authorize(@amount, @three_ds_enrolled_card, @normalized_3ds_2_options)
assert response.test?
assert_equal '8815609737078177', response.authorization
assert_equal response.params['resultCode'], 'IdentifyShopper'
refute response.params['additionalData']['threeds2.threeDS2Token'].blank?
refute response.params['additionalData']['threeds2.threeDSServerTransID'].blank?
refute response.params['additionalData']['threeds2.threeDSMethodURL'].blank?
end

def test_failed_authorize
@gateway.stubs(:ssl_post).returns(failed_authorize_response)

Expand Down Expand Up @@ -395,6 +431,10 @@ def successful_authorize_with_3ds_response
'pspReference=8815161318854998&resultCode=RedirectShopper&issuerUrl=https%3A%2F%2Ftest.adyen.com%2Fhpp%2F3d%2Fvalidate.shtml&md=WIFa2sF3CuPyN53Txjt3U%2F%2BDuCsddzywiY5NLgEAdUAXPksHUzXL5E%2BsfvdpolkGWR8b1oh%2FNA3jNaUP9UCgfjhXqRslGFy9OGqcZ1ITMz54HHm%2FlsCKN9bTftKnYA4F7GqvOgcIIrinUZjbMvW9doGifwzSqYLo6ASOm6bARL5n7cIFV8IWtA2yPlO%2FztKSTRJt1glN4s8sMcpE57z4soWKMuycbdXdpp6d4ZRSa%2F1TPF0MnJF0zNaSAAkw9JpXqGMOz5sFF2Smpc38HXJzM%2FV%2B1mmoDhhWmXXOb5YQ0QSCS7DXKIcr8ZtuGuGmFp0QOfZiO41%2B2I2N7VhONVx8xSn%2BLu4m6vaDIg5qsnd9saxaWwbJpl9okKm6pB2MJap9ScuBCcvI496BPCrjQ2LHxvDWhk6M3Exemtv942NQIGlsiPaW0KXoC2dQvBsxWh0K&paRequest=eNpVUtuOgjAQ%2FRXj%2B1KKoIWMTVgxWR%2B8RNkPaMpEycrFUlb8%2B20B190%2BnXPm0pnTQnpRiMkJZauQwxabRpxxkmfLacQYDeiczihjgR%2BGbMrhEB%2FxxuEbVZNXJaeO63hAntSUK3kRpeYg5O19s%2BPUm%2FnBHMhIoU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RQmiqwnVjXiFOv%2FEcWn0Z6IM2TnAfw3Kd2KwZ9JaePLtZ2Ck7%2FUEsdt1Kj2HYeE86WM4PESystER5oBT12xWXvbp8CEA7Mulmpd3bkiMl5IVRoSBL5pl4qZd1CrnG%2FeuvtXYTsN%2FdA%2BIcWwiLiXpmSwqaRB8DfChwouuNMAAkfKhQ6b3vLAToc3o%2B3Xa1QetsK8GI1pmjkoZRvLd2xfGhVe%2FmCl23wzQsAicwB9ZXXMgWbaS2OwdwsISQGOmsWrajzp7%2FvR0T4aHqJlrFvKnc9BrWEWbDi8g%2BDFZ2E2ifhFYSYhrHVA7yOIIDdTQnH3CIzaevxUAnbIyFsxrhy8USdP6R6CdJZ%2Bg0rIJ5%2FeZ5P8JjDiYJWi5FDJwy%2BNP9PQIFFim6psbELCtnAaW1m7pU1FeNwjYUGIdVD2f%2BVYJe4cWHPCaWAAsARNXTzjrfUEq%2BpEYDcs%2FLyTB8f69qSrmTSDGsCETsNNy27LY%2BtodGDKsxtW35jIqoV8l2Dra3wucman8nIZp3VTNtNvZDCqWetLXxBbFVZN6ecuoMPwhER5MBFUrkkXCSSFBK%2FNGp%2FXaEDP6A2hmUKvXikL3F9S7MIKQCUYC%2FI7K4DFYFBjTBzN4%3D&additionalData.threeds2.threeDSServerTransID=efbf9d05-5e6b-4659-a64e-f1dfa5d846c4&additionalData.threeds2.threeDSMethodURL=https%3A%2F%2Fpal-test.adyen.com%2Fthreeds2simulator%2Facs%2FstartMethod.shtml&pspReference=8815609737078177&resultCode=IdentifyShopper'
end

def failed_authorize_response
'pspReference=7914002630895750&refusalReason=Refused&resultCode=Refused'
end
Expand Down