Skip to content

Commit

Permalink
Braintree: Support override_application_id (#5194)
Browse files Browse the repository at this point in the history
* Braintree: Support override_application_id

COMP-266

ActiveMerchant currently uses Class.application_id or @options[:channel] to let merchants
pass platform BN codes to gateways to signify that a transaction may be going to one merchant's
accounts but it originates from a platform or aggregator.

This poses a problem in that the Class value is assigned at compile time and the @options[:channel]
refers to a static value used when initializing the class.

This commit adds support for `override_application_id` which is a way for aggregators to pass in a
new BN code at transaction time alongside transaction parameters.

Test Summary
Remote:
123 tests, 661 assertions, 0 failures, 0 errors, 0 pendings, 0 omissions, 0 notifications
100% passed

Cannot add a remote test because there is no generic `channel` value

* drop unnecessary ensure

* simplify tests

* changelog
  • Loading branch information
aenand committed Aug 14, 2024
1 parent 0f2ae6f commit 4fbb4ae
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
* Elavon: Update sending CVV for MIT transactions [almalee24] #5210
* Adyen: Fix NT integration [jherreraa] #5155
* HPS: Update NetworkTokenizationCreditCard flow [almalee24] #5178
* Braintree: Support override_application_id [aenand] #5194

== Version 1.137.0 (August 2, 2024)
* Unlock dependency on `rexml` to allow fixing a CVE (#5181).
Expand Down
2 changes: 1 addition & 1 deletion lib/active_merchant/billing/gateways/braintree_blue.rb
Original file line number Diff line number Diff line change
Expand Up @@ -815,7 +815,7 @@ def add_addresses(parameters, options)
end

def add_channel(parameters, options)
channel = @options[:channel] || application_id
channel = options[:override_application_id] || @options[:channel] || application_id
parameters[:channel] = channel if channel
end

Expand Down
11 changes: 10 additions & 1 deletion test/unit/gateways/braintree_blue_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -939,7 +939,7 @@ def test_that_setting_a_wiredump_device_on_the_gateway_sets_the_braintree_logger
end
end

def test_solution_id_is_added_to_create_transaction_parameters
def test_channel_is_added_to_create_transaction_parameters
assert_nil @gateway.send(:create_transaction_parameters, 100, credit_card('41111111111111111111'), {})[:channel]
ActiveMerchant::Billing::BraintreeBlueGateway.application_id = 'ABC123'
assert_equal @gateway.send(:create_transaction_parameters, 100, credit_card('41111111111111111111'), {})[:channel], 'ABC123'
Expand All @@ -950,6 +950,15 @@ def test_solution_id_is_added_to_create_transaction_parameters
ActiveMerchant::Billing::BraintreeBlueGateway.application_id = nil
end

def test_override_application_id_is_sent_to_channel
gateway = BraintreeBlueGateway.new(merchant_id: 'test', public_key: 'test', private_key: 'test', channel: 'overidden-channel')
gateway_response = gateway.send(:create_transaction_parameters, 100, credit_card('41111111111111111111'), {})
assert_equal gateway_response[:channel], 'overidden-channel'

gateway_response = gateway.send(:create_transaction_parameters, 100, credit_card('41111111111111111111'), { override_application_id: 'override-application-id' })
assert_equal gateway_response[:channel], 'override-application-id'
end

def test_successful_purchase_with_descriptor
Braintree::TransactionGateway.any_instance.expects(:sale).with do |params|
(params[:descriptor][:name] == 'wow*productname') &&
Expand Down

0 comments on commit 4fbb4ae

Please sign in to comment.