Skip to content

Commit

Permalink
Add 3dsecure options for securionpay
Browse files Browse the repository at this point in the history
  • Loading branch information
Karol Szolz committed Oct 14, 2019
1 parent b715b4e commit 7f9bf94
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 3 deletions.
23 changes: 21 additions & 2 deletions lib/active_merchant/billing/gateways/securion_pay.rb
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,9 @@ def create_post_for_auth_or_purchase(money, payment, options)
post[:metadata] = {}
post[:metadata][:email] = options[:email]
end
if options[:three_d_secure]
add_3d_secure_options(post, options)
end
post
end

Expand Down Expand Up @@ -176,6 +179,22 @@ def add_address(post, options)
end
end

def add_3d_secure_options(post, options)
three_d_secure = options[:three_d_secure]
post[:threeDSecure] = {}

unless three_d_secure[:require_attempt].nil?
post[:threeDSecure][:requireAttempt] = three_d_secure[:require_attempt]
end
unless three_d_secure[:require_enrolled_card].nil?
post[:threeDSecure][:requireEnrolledCard] = three_d_secure[:require_enrolled_card]
end
unless three_d_secure[:require_successful_liability_shift_for_enrolled_card].nil?
post[:threeDSecure][:requireSuccessfulLiabilityShiftForEnrolledCard] =
three_d_secure[:require_successful_liability_shift_for_enrolled_card]
end
end

def parse(body)
JSON.parse(body)
end
Expand Down Expand Up @@ -213,11 +232,11 @@ def post_data(params)
return nil unless params

params.map do |key, value|
next if value.blank?
next if value.to_s.blank?
if value.is_a?(Hash)
h = {}
value.each do |k, v|
h["#{key}[#{k}]"] = v unless v.blank?
h["#{key}[#{k}]"] = v unless v.to_s.blank?
end
post_data(h)
elsif value.is_a?(Array)
Expand Down
16 changes: 15 additions & 1 deletion test/unit/gateways/securion_pay_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -86,14 +86,28 @@ def test_invalid_raw_response

def test_client_data_submitted_with_purchase
stub_comms(@gateway, :ssl_request) do
updated_options = @options.merge({ description: 'test charge', ip: '127.127.127.127', user_agent: 'browser XXX', referrer: 'http://www.foobar.com', email: '[email protected]' })
updated_options = @options.merge({
description: 'test charge',
ip: '127.127.127.127',
user_agent: 'browser XXX',
referrer: 'http://www.foobar.com',
email: '[email protected]',
three_d_secure: {
require_attempt: true,
require_enrolled_card: true,
require_successful_liability_shift_for_enrolled_card: false
}
})
@gateway.purchase(@amount, @credit_card, updated_options)
end.check_request do |method, endpoint, data, headers|
assert_match(/description=test\+charge/, data)
assert_match(/ip=127\.127\.127\.127/, data)
assert_match(/user_agent=browser\+XXX/, data)
assert_match(/referrer=http\%3A\%2F\%2Fwww\.foobar\.com/, data)
assert_match(/metadata\[email\]=foo\%40bar\.com/, data)
assert_match(/threeDSecure\[requireAttempt\]=true/, data)
assert_match(/threeDSecure\[requireEnrolledCard\]=true/, data)
assert_match(/threeDSecure\[requireSuccessfulLiabilityShiftForEnrolledCard\]=false/, data)
end.respond_with(successful_purchase_response)
end

Expand Down

0 comments on commit 7f9bf94

Please sign in to comment.