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

Braintree: Pass overridden mid into client token for GS 3DS #5166

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
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)
DustinHaefele marked this conversation as resolved.
Show resolved Hide resolved
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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❓ Question:

so Nraintree Sandbox doesn't care about a valid mid ?, you can just send a '1234' and they are going to provide you with a client token any way ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct, I tried passing multiple values ​​and got a successful result with every field sent including the known field

@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
Loading