The Braintree JavaScript SDK has several ways for you to collect customer payment information. The easiest way to get up and running is via the Drop-in UI. For other integrations, please see the JS SDK Overview.

Client side payment token flow Diagram demonstrating the required interaction between the client, Braintree servers and your server.


Add Drop-in to your page:

  <meta charset="utf-8">
  <script src=""></script>
  <div id="dropin-container"></div>
  <button id="submit-button">Request payment method</button>
    var button = document.querySelector('#submit-button');

      authorization: 'CLIENT_TOKEN_FROM_SERVER',
      container: '#dropin-container'
    }, function (createErr, instance) {
      button.addEventListener('click', function () {
        instance.requestPaymentMethod(function (err, payload) {
          // Submit payload.nonce to your server

Get a client token

To start up, the JavaScript SDK needs a client token generated by your Braintree server SDK. To see how to generate one, please follow Simple Server (the next page) until you've completed the Generate a client token section.

Once you've generated a client token, embed it into your template.

  authorization: CLIENT_TOKEN_FROM_SERVER,
  container: '#dropin-container'
}, function (err, instance) {
  /* ... */

There are a number of ways to get your client token into JavaScript so you can set up Braintree. Many people choose to interpolate the client token into the HTML/JavaScript itself; alternatively, you could load the client token from an AJAX call to an exposed client token URL on your server.

Test your integration

Create a sandbox account

If you haven't already, sign up for a free Braintree sandbox account:

Sign Up for a Braintree Sandbox Account

Log in to obtain your sandbox API credentials. You'll need your:

  • Sandbox merchant ID
  • Public key
  • Private key

Use these credentials for your development and testing.


When you go live, you will need to replace your sandbox API credentials with production API credentials.

Test values

When testing in the sandbox, be sure to use our test card numbers (e.g. 4111111111111111) and nonces (e.g. fake-valid-nonce). Real payment method data will not work in the sandbox. See our Testing page for more details.

Send payment method nonce to server

A Braintree client-side integration sends payment information – like a credit card or a PayPal authorization – to Braintree in exchange for a payment method nonce, a one time use value that represents that payment method.

On your server, use a payment method nonce with a Braintree server SDK to charge a card or update a customer's payment methods.

world.greeted = true

At this point, you should have a working client-side checkout flow. When your user provides payment information, you receive a payment method nonce and send it to your server.

Next, your server closes the loop by using the payment method nonce to create a transaction.

Next Page: Simple Server →