Skip to content

Commit

Permalink
MercadoPago: Sending sponsor_id only on production
Browse files Browse the repository at this point in the history
Summary:
------------------------------
MercadoPago only sending platform/partnership info on production.

Remote Test:
------------------------------
Finished in 79.263845 seconds.
20 tests, 56 assertions, 0 failures, 0 errors, 0 pendings,
1 omissions, 0 notifications
100% passed

Unit Tests:
------------------------------
Finished in 68.455283 seconds.
6012 tests, 80277 assertions, 0 failures, 0 errors, 0 pendings,
0 omissions, 0 notifications
100% passed

RuboCop:
------------------------------
801 files inspected, no offenses detected
  • Loading branch information
Heavyblade committed Aug 30, 2024
1 parent 166ca88 commit 5144482
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/active_merchant/billing/gateways/mercado_pago.rb
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ def add_merchant_services(post, options)
end

def add_additional_data(post, options)
post[:sponsor_id] = options[:sponsor_id]
post[:sponsor_id] = options[:sponsor_id] unless test?
post[:metadata] = options[:metadata] if options[:metadata]
post[:device_id] = options[:device_id] if options[:device_id]
post[:additional_info] = {
Expand Down
14 changes: 14 additions & 0 deletions test/remote/gateways/remote_mercado_pago_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -394,4 +394,18 @@ def test_successful_purchase_with_3ds
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

def test_successful_purchase_with_3ds_mandatory
three_ds_cc = credit_card('5031755734530604', verification_value: '123', month: 11, year: 2025)
@options[:execute_threed] = true
@options[:three_ds_mode] = 'mandatory'

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
22 changes: 22 additions & 0 deletions test/unit/gateways/mercado_pago_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -529,6 +529,28 @@ def test_set_binary_mode_to_nil_when_request_is_3ds
end.respond_with(successful_authorize_response)
end

def test_should_not_include_sponsor_id_when_test_mode_is_enabled
@options[:sponsor_id] = '1234'

stub_comms do
@gateway.purchase(@amount, @credit_card, @options)
end.check_request do |endpoint, data, _headers|
assert_not_match(%r("sponsor_id":), data) if /payments/.match?(endpoint)
end.respond_with(successful_purchase_response)
end

def test_should_include_sponsor_id_when_test_mode_is_disabled
@gateway.stubs(test?: false)
@options[:sponsor_id] = '1234'

stub_comms do
@gateway.purchase(@amount, @credit_card, @options)
end.check_request do |endpoint, data, _headers|
request = JSON.parse(data)
assert_equal '1234', request['sponsor_id'] if /payments/.match?(endpoint)
end.respond_with(successful_purchase_response)
end

private

def pre_scrubbed
Expand Down

0 comments on commit 5144482

Please sign in to comment.