Payment flow

Generate a client token

important

You must generate a client token if you want to use 3D Secure. Tokenization keys can't be used when processing 3D Secure transactions.

Before you can call the verify3DS method, you will need to generate a client token. The client_token is generated server-side and must be accessible from the JavaScript in your checkout page.

Specify a merchant account

If you would like to use a merchant account ID other than your default, specify the merchant_account_id when generating the client token.

note

This merchant account ID must match the merchant account ID used to create the transaction.

Render a checkout page

Next, include the JS SDK on your page:

HTML
Copy
Copied
<script src="https://js.braintreegateway.com/js/braintree-2.32.1.min.js"></script>

Finally, create the configured client:

HTML
Copy
Copied
<script>
var client = new braintree.api.Client({
  // Use the generated client token to instantiate the Braintree client.
  clientToken: 'CLIENT_TOKEN_FROM_SERVER'
});
</script>

Verify a credit card

Once the 3D Secure client has been created, you can verify transactions by passing either the paymentMethodNonce or the raw card information to verify3DS. This call will tokenize the data (if you are passing raw card data rather than a nonce) and will challenge the cardholder to authenticate (if the card is enrolled in a 3D Secure program, like Verified by Visa).

Here is an example of using a paymentMethodNonce received from a Drop-in or custom client-side integration:

JavaScript
Copy
Copied
client.verify3DS({
  amount: '500.00',
  creditCard: NONCE_FROM_DROPIN_OR_CUSTOM_INTEGRATION
}, function (err, response) {
  // Send response.nonce to use in your transaction
});

And here is an example of using the raw card information to verify the transaction:

JavaScript
Copy
Copied
client.verify3DS({
  amount: '500.00',
  creditCard: {
    // required parameters
    number: '4010000000000018',
    expirationDate: '10/20', // You can use either expirationDate
    expirationMonth: '12', // or expirationMonth
    expirationYear: '2020', // and expirationYear

    // optional parameters
    cardholderName: 'John Smith',
    cvv: '832',
    billingAddress: {
      postalCode: '94107'
    }
  }
}, function (err, response) {
  // Send response.nonce to use in your transaction
});

The transaction amount is required at verification for two reasons. First of all, it's an additional check to make sure the transaction being verified is the same as the one that is eventually authorized and settled. For this reason, the amount submitted for verification must match the amount sent to the Braintree server for authorization. Additionally, some issuers use the amount to help determine whether they should challenge the user to authenticate.

After the cardholder has completed the 3D Secure process, either an error argument or a response argument will be populated in your callback. You should attempt to handle any errors (if present), and then create the transaction using the nonce returned in the response object. In the following example, transactions would employ response.nonce.

JavaScript
Copy
Copied
client.verify3DS({
  amount: '500.00',
  creditCard: {
    number: '4010000000000018',
    expirationMonth: '12',
    expirationYear: '2020'
  }
}, function (err, response) {
  if (!err) {
    // 3D Secure finished. Using response.nonce you may proceed with the transaction with the associated server side parameters below.
  } else {
    // Handle errors
    var p = document.createElement('p');
    p.innerHTML = error.message;
    document.body.appendChild(p);
  }
});

Verify a vaulted credit card

First, on the server, generate and return a payment method nonce for the vaulted credit card.

Then, on the client, you can use the same verify3DS method as with card information—just pass the nonce instead.

JavaScript
Copy
Copied
client.verify3DS({
  amount: '500.00',
  creditCard: NONCE_FROM_YOUR_SERVER
}, function (err, response) {
  // Send response.nonce to use in your transaction
});

Advanced client-side options

We expose additional information about the authentication request that you can use for more advanced UI flows or risk assessment. You should be aware that making such assessments may result in accepting the liability for fraudulent transactions.

These parameters pass through the client-side first and should not be trusted for your server-side risk assessment. They should be used for UI flow only.

JavaScript
Copy
Copied
client.verify3DS({
  amount: '500.00',
  creditCard: {
    number: '4010000000000018',
    expirationMonth: '12',
    expirationYear: '2020'
  }
}, function (err, response) {
  var liabilityShifted = response.verificationDetails.liabilityShifted; // true || false
  var liabilityShiftPossible =  response.verificationDetails.liabilityShiftPossible; // true || false
});
  1. liabilityShifted indicates that 3D Secure worked and authentication succeeded. This will also be true if the issuing bank does not support 3D Secure, but the payment method does. In both cases, the liability for fraud has been shifted to the bank. You should go on creating a transaction using the new nonce.
  2. liabilityShiftPossible indicates that the payment method was eligible for 3D Secure. If liabilityShifted is false, then the user failed 3D Secure authentication. In this situation, the card brands recommend asking the user for another form of payment. However, if you have server-side risk assessment processes that allow for it, you can still use the new nonce to create a transaction. If you want to use a nonce that did not pass 3D Secure authentication, you need to set the required option to false in your server integration.
  3. If both of the above values are false then this card was ineligible for 3D Secure. You can continue to create the transaction with the new nonce. However, liability shift will not apply to this transaction. This case may be useful if you would like to ask the user for additional verification (AVS, etc).
important

For American Express SafeKey, liabilityShifted may be returned as true but Amex may later revoke the liability shift for the transaction based on your merchant behavior and fraud rate.

See also

Next Page: Server-side →

Still have questions?

If you can’t find an answer, contact our Support team