Skip to content

Commit

Permalink
Braintree: Pass overridden mid into client token for GS 3DS (#5166)
Browse files Browse the repository at this point in the history
Summary:
------------------------------
Add merchant_account_id for the Client Token Generate and returns a string which contains all authorization and configuration information that the client needs to initialize the client SDK to communicate with Braintree

[ECS-3617](https://spreedly.atlassian.net/browse/ECS-3617)
[ECS-3607](https://spreedly.atlassian.net/browse/ECS-3607)

Remote Test:
------------------------------
Finished in 6.262003 seconds.
7 tests, 15 assertions, 0 failures, 0 errors, 0 pendings, 0 omissions, 0 notifications
100% passed
1.12 tests/s, 2.40 assertions/s

Unit Tests:
------------------------------
Finished in 38.744354 seconds.
5956 tests, 79952 assertions, 0 failures, 0 errors, 0 pendings, 0 omissions, 0 notifications
100% passed
153.73 tests/s, 2063.58 assertions/s

RuboCop:
------------------------------
798 files inspected, no offenses detected

Co-authored-by: Luis Urrea <devluisurrea+endava@gmail.com>
  • Loading branch information
sinourain and Luis Urrea committed Jul 17, 2024
1 parent 941c6d2 commit 568466b
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 8 deletions.
1 change: 1 addition & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
* Credorax: Update 3DS version mapping [almalee24] #5159
* Add Maestro card bins [yunnydang] #5172
* Braintree: Remove stored credential v1 [almalee24] #5175
* Braintree Blue: Pass overridden mid into client token for GS 3DS [sinourain] #5166

== Version 1.136.0 (June 3, 2024)
* Shift4V2: Add new gateway based on SecurionPay adapter [heavyblade] #4860
Expand Down
10 changes: 5 additions & 5 deletions lib/active_merchant/billing/gateways/braintree/token_nonce.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ def url
"https://payments#{'.sandbox' if sandbox}.braintree-api.com/graphql"
end

def create_token_nonce_for_payment_method(payment_method)
def create_token_nonce_for_payment_method(payment_method, options = {})
headers = {
'Accept' => 'application/json',
'Authorization' => "Bearer #{client_token}",
'Authorization' => "Bearer #{client_token(options)['authorizationFingerprint']}",
'Content-Type' => 'application/json',
'Braintree-Version' => '2018-05-10'
}
Expand All @@ -34,9 +34,9 @@ def create_token_nonce_for_payment_method(payment_method)
return token, message
end

def client_token
base64_token = @braintree_gateway.client_token.generate
JSON.parse(Base64.decode64(base64_token))['authorizationFingerprint']
def client_token(options = {})
base64_token = @braintree_gateway.client_token.generate({ merchant_account_id: options[:merchant_account_id] || @options[:merchant_account_id] }.compact)
JSON.parse(Base64.decode64(base64_token))
end

private
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 @@ -1036,7 +1036,7 @@ def bank_account_errors(payment_method, options)
end

def add_bank_account_to_customer(payment_method, options)
bank_account_nonce, error_message = TokenNonce.new(@braintree_gateway, options).create_token_nonce_for_payment_method payment_method
bank_account_nonce, error_message = TokenNonce.new(@braintree_gateway, options).create_token_nonce_for_payment_method(payment_method, options)
return Response.new(false, error_message) unless bank_account_nonce.present?

result = @braintree_gateway.payment_method.create(
Expand Down
21 changes: 19 additions & 2 deletions test/remote/gateways/remote_braintree_token_nonce_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,25 @@ def setup

def test_client_token_generation
generator = TokenNonce.new(@braintree_backend)
token = generator.client_token
assert_not_nil token
client_token = generator.client_token
assert_not_nil client_token
assert_not_nil client_token['authorizationFingerprint']
end

def test_client_token_generation_with_mid
@options[:merchant_account_id] = '1234'
generator = TokenNonce.new(@braintree_backend, @options)
client_token = generator.client_token
assert_not_nil client_token
assert_equal client_token['merchantAccountId'], '1234'
end

def test_client_token_generation_with_a_new_mid
@options[:merchant_account_id] = '1234'
generator = TokenNonce.new(@braintree_backend, @options)
client_token = generator.client_token({ merchant_account_id: '5678' })
assert_not_nil client_token
assert_equal client_token['merchantAccountId'], '5678'
end

def test_successfully_create_token_nonce_for_bank_account
Expand Down

0 comments on commit 568466b

Please sign in to comment.