diff --git a/lib/active_merchant/billing/gateways/braintree/token_nonce.rb b/lib/active_merchant/billing/gateways/braintree/token_nonce.rb index dc9a3e0bc90..6574c768e45 100644 --- a/lib/active_merchant/billing/gateways/braintree/token_nonce.rb +++ b/lib/active_merchant/billing/gateways/braintree/token_nonce.rb @@ -21,7 +21,7 @@ def url def create_token_nonce_for_payment_method(payment_method) headers = { 'Accept' => 'application/json', - 'Authorization' => "Bearer #{client_token}", + 'Authorization' => "Bearer #{client_token['authorizationFingerprint']}", 'Content-Type' => 'application/json', 'Braintree-Version' => '2018-05-10' } @@ -35,8 +35,8 @@ def create_token_nonce_for_payment_method(payment_method) end def client_token - base64_token = @braintree_gateway.client_token.generate - JSON.parse(Base64.decode64(base64_token))['authorizationFingerprint'] + base64_token = @braintree_gateway.client_token.generate({ merchant_account_id: options[:merchant_account_id] }.compact) + JSON.parse(Base64.decode64(base64_token)) end private diff --git a/test/remote/gateways/remote_braintree_token_nonce_test.rb b/test/remote/gateways/remote_braintree_token_nonce_test.rb index cbc8dbc3c24..2542dd0e22c 100644 --- a/test/remote/gateways/remote_braintree_token_nonce_test.rb +++ b/test/remote/gateways/remote_braintree_token_nonce_test.rb @@ -26,8 +26,17 @@ 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_successfully_create_token_nonce_for_bank_account