JavaScript v2

Configuration for braintree.setup

Braintree.js integrations are created with braintree.setup.

  1. JavaScript
braintree.setup(authorization, integrationType, options)

ArgumentTypeValue
authorizationstringA string representing your client token or tokenization key
integrationTypestring'dropin' or 'custom'
optionsObject An options object. See Setup options for more details.

Setup method optionsAnchorIcon

All available options which can be passed to the braintree.setup method, under the options object. These are independent from the options specific to the two supported integration types, Drop-in and Custom.

KeyIntegrationTypeValue
paypalanyObject See PayPal options.
dataCollectoranyObject See Premium Fraud Management Tools.
enableCORSanyboolean Enabling this allows Braintree.js to use AJAX with CORS to make requests instead of JSONP.

If you are using a Content Security Policy, you may need to tweak your directives to allow Braintree.js to communicate from your webpage. See Using Braintree.js with a Content Security Policy.
onReadyanyfunction

This callback is called when the Braintree integration is ready. It is called with one object that represents the integration. It has the following properties:

`teardown` Method used to remove this integration. See Teardown for usage.
paypal

Object containing methods to launch and close the PayPal flow. These methods are not available in Drop-in integrations.

`initAuthFlow` Opens the PayPal flow. Must be called synchronously as result of a user click event or the PayPal flow popup will automatically be blocked by the browser. Only available in Custom integrations.
closeAuthFlowCloses the PayPal flow. Only available in Custom integrations.
deviceData A JSON string of device details for use in fraud detection.
onPaymentMethodReceivedanyfunction

This callback is called after the successful tokenization of a payment method.

When subscribed to this callback, we will not add a hidden nonce input to your form nor submit the form automatically. It is up to you to send data to your server as you see fit, usually inside of this callback.

This callback is called with one object that contains information about the received payment method:

`nonce`The payment method nonce to send to your server for transactions
type A string representing the type of payment method generated; either 'CreditCard' or 'PayPalAccount'
details An object representing more details about the payment method. See details object for more information.
paymentMethodNonceReceivedDrop-infunction This callback is deprecated in favor of onPaymentMethodReceived.

onErroranyfunction

Called when an error occurs. This typically happens when you have a configuration error but can also happen when there is a failure in tokenization. The error object provides two keys:

`type` A string describing the type of error that occurred (e.g. "CONFIGURATION", "VALIDATION", or "SERVER"). Not all types are emitted for all integrations.
messageA human-readable string describing the error.
containerDrop-instring The ID of the container that Drop-in should be placed into. This field is required for Drop-in.
idCustomstring The ID of the form that Custom should be placed into. This field is required for Custom.
hostedFieldsCustomObject See Hosted Fields options.
defaultFirstDrop-inboolean When you specify a customerID that has vaulted payment methods associated with it, Drop-in displays a list of those payment methods and automatically pre-selects the one used most recently. If you pass defaultFirst, Drop-in will instead pre-select the payment method marked as default for the customer. Learn more about marking payment methods as default when creating a customer or creating a payment method.

onPaymentMethodReceiveddetailsobjectAnchorIcon

When the onPaymentMethodReceived callback is passed as part of the options parameter in braintree.setup, the callback returns a details object. The contents of the details object vary depending on the type of payment method.

Credit cardAnchorIcon

A credit card will return basic information about the card used. This is generally useful when updating your UI to reflect the card type used.

KeyTypeValue
`cardType``string` The type of card used. Can be `'Visa'`, `'Mastercard'`, `'Discover'`, `'American Express'`, `'UnionPay'`, or `'JCB'`.
`lastTwo``string`The last two digits of the supplied card

PayPalAnchorIcon

PayPal responses will contain the following:

KeyTypeValue
billingAddressobject

Returns the customer's billing address with the following properties:

  • countryCodeAlpha2(String)
  • locality(String)
  • postalCode(String)
  • region(String)
  • streetAddress(String)

This option is not available to all merchants. Contact PayPal Support for details on eligibility and enabling this information.

emailstringEmail address associated with the customer's PayPal account.
firstNamestringFirst name associated with the customer's PayPal account.
lastNamestringLast name associated with the customer's PayPal account.
payerIdstringUnique ID associated with the customer's PayPal account.
phonestring Phone number associated with the customer's PayPal account. This is only available if the option is enabled in your PayPal business account.
shippingAddressobject

Returns the customer's shipping address along with the following properties:

  • countryCodeAlpha2(String)
  • locality(String)
  • postalCode(String)
  • region(String)
  • streetAddress(String)

Learn more about configuring PayPal.

If you accept cookies, we’ll use them to improve and customize your experience and enable our partners to show you personalized PayPal ads when you visit other sites. Manage cookies and learn more