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

MercadoPago: Adding 3DS gateway specific fields #5200

Merged
merged 1 commit into from
Aug 15, 2024
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
12 changes: 10 additions & 2 deletions lib/active_merchant/billing/gateways/mercado_pago.rb
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,8 @@ def purchase_request(money, payment, options = {})
add_net_amount(post, options)
add_taxes(post, options)
add_notification_url(post, options)
post[:binary_mode] = (options[:binary_mode].nil? ? true : options[:binary_mode])
add_3ds(post, options)
post[:binary_mode] = options.fetch(:binary_mode, true) unless options[:execute_threed]
post
end

Expand Down Expand Up @@ -287,7 +288,7 @@ def success_from(action, response)
if action == 'refund'
response['status'] != 404 && response['error'].nil?
else
%w[active approved authorized cancelled in_process].include?(response['status'])
%w[active approved authorized cancelled in_process pending].include?(response['status'])
end
end

Expand Down Expand Up @@ -322,6 +323,13 @@ def error_code_from(action, response)
end
end

def add_3ds(post, options)
return unless options[:execute_threed]

post[:three_d_secure_mode] = options[:three_ds_mode] == 'mandatory' ? 'mandatory' : 'optional'
post[:notification_url] = options[:notification_url] if options[:notification_url]
end

def url(action)
full_url = (test? ? test_url : live_url)
full_url + "/#{action}?access_token=#{CGI.escape(@options[:access_token])}"
Expand Down
15 changes: 14 additions & 1 deletion test/remote/gateways/remote_mercado_pago_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def setup
@options = {
billing_address: address,
shipping_address: address,
email: 'user+br@example.com',
email: 'test_user_1390220683@testuser.com',
description: 'Store Purchase'
}
@processing_options = {
Expand Down Expand Up @@ -363,4 +363,17 @@ def test_transcript_scrubbing
assert_scrubbed(@credit_card.verification_value, transcript)
assert_scrubbed(@gateway.options[:access_token], transcript)
end

def test_successful_purchase_with_3ds
three_ds_cc = credit_card('5483928164574623', verification_value: '123', month: 11, year: 2025)
@options[:execute_threed] = true

response = @gateway.purchase(290, three_ds_cc, @options)

assert_success response
assert_equal 'pending_challenge', response.message
assert_include response.params, 'three_ds_info'
assert_equal response.params['three_ds_info']['external_resource_url'], 'https://api.mercadopago.com/cardholder_authenticator/v2/prod/browser-challenges'
assert_include response.params['three_ds_info'], 'creq'
end
end
17 changes: 15 additions & 2 deletions test/unit/gateways/mercado_pago_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,13 @@ def setup
end

def test_successful_purchase
@gateway.expects(:ssl_post).at_most(2).returns(successful_purchase_response)
response = stub_comms do
@gateway.purchase(@amount, @credit_card, @options)
end.check_request do |endpoint, data, _headers|
request = JSON.parse(data)
assert_equal true, request['binary_mode'] if /payments/.match?(endpoint)
end.respond_with(successful_purchase_response)

response = @gateway.purchase(@amount, @credit_card, @options)
assert_success response

assert_equal '4141491|1.0', response.authorization
Expand Down Expand Up @@ -499,6 +503,15 @@ def test_invalid_taxes_shape
end
end

def test_set_binary_mode_to_nil_when_request_is_3ds
stub_comms do
@gateway.authorize(@amount, @credit_card, @options.merge(execute_threed: true))
end.check_request do |endpoint, data, _headers|
request = JSON.parse(data)
assert_nil request['binary_mode'] if /payments/.match?(endpoint)
end.respond_with(successful_authorize_response)
end

private

def pre_scrubbed
Expand Down
Loading