Client-side Connect Flow

Add a Connect with Braintree button so a merchant can connect their Braintree account to your platform using Braintree Auth.

PrerequisitesAnchorIcon

Before you add the button, make sure you have:

  • The connect_url value your server generates with the Braintree server library's connect_url method. See Server-side Connect Flow.
  • A container on your page for the button, such as a DOM element, a DOM element ID, or a jQuery selector.

Add the Connect with Braintree buttonAnchorIcon

To make it easy to display the Connect with Braintree button, use the small JavaScript library braintree-oauth-connect.js. Add this library to your page and pass in the connect_url you generated on the server.

  1. HTML
<script src="https://assets.braintreegateway.com/v1/braintree-oauth-connect.js"></script>
<script>
const connectUrl = connect_url_from_server;
const partner = new BraintreeOAuthConnect({
  connectUrl: connectUrl,
  // the ID of a DOM element, a DOM node, or a jQuery object
  container: 'bt-oauth-connect-container',
  onError: function (errorObject) {
    console.warn(errorObject.message);
  }
});
</script>

When the script runs successfully, the Connect with Braintree button appears inside the container element you specified.

The parameters available are:

ParameterDescription
connectUrl Required. The URL generated by the Braintree server library's connect_url method.
container Required. The place on your page where the Connect with Braintree button will live. This can be:
  • A DOM element.
  • The ID of a DOM element, for example my-container-id.
  • If using jQuery, a jQuery selector.
onError(function callback(error) {}) Optional. Takes a callback function to receive errors as an object with a message property.
environment Optional. Accepts production (default if not provided) or sandbox.