lib/active_merchant/billing/gateways/barclaycard_smartpay.rb in activemerchant-1.95.0 vs lib/active_merchant/billing/gateways/barclaycard_smartpay.rb in activemerchant-1.96.0
- old
+ new
@@ -11,11 +11,11 @@
self.supported_cardtypes = [:visa, :master, :american_express, :discover, :diners_club, :jcb, :dankort, :maestro]
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)
super
end
@@ -35,11 +35,11 @@
post = payment_request(money, options)
post[:amount] = amount_hash(money, options[:currency])
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)
commit('authorise', post)
end
def capture(money, authorization, options = {})
requires!(options, :order_id)
@@ -184,11 +184,11 @@
return nil if authorization.empty?
return authorization.join('#')
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)
flat_hash = {}
hash.each_pair do |key, val|
@@ -208,16 +208,22 @@
'Authorization' => 'Basic ' + Base64.strict_encode64("#{account}@Company.#{@options[:company]}:#{password}").strip
}
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)
data.map do |key, val|
"#{key}=#{CGI.escape(val.to_s)}"
@@ -341,11 +347,34 @@
hash[:shopperReference] = options[:customer] if options[:customer]
hash.keep_if { |_, v| v }
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
end