There are two ways to integrate Drop-in into your page: a script tag integration and a JavaScript integration using dropin.create
.
The script tag integration is the fastest way to integrate. All you need to do is add the Drop-in script inside your form element where you want Drop-in to appear and include a data-braintree-dropin-authorization
property with your tokenization key or client token.
When your form is submitted, Drop-in will intercept the form submission and attempt to tokenize the payment method. If the tokenization is successful, it will insert the payment method nonce into a hidden input with the name payment_method_nonce
and then submit your form. If the tokenization is unsuccessful, a relevant error will be shown in the UI.
If you have data collector enabled, the device data will be injected into a hidden input with the name device_data
before form submission.
Specify creation options as data attributes in your script tag, as shown in the examples below. The following configuration properties may be set:
data-locale
data-card.cardholder-name.required
data-payment-option-priority
data-data-collector.kount
data-data-collector.paypal
data-paypal.amount
data-paypal.currency
data-paypal.flow
data-paypal-credit.amount
data-paypal-credit.currency
data-paypal-credit.flow
For more control and customization, use dropin.create
instead.
See our demo app for an example of using our script tag integration.
Examples
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Checkout</title>
</head>
<body>
<form id="payment-form" action="/" method="post">
<script src="https://js.braintreegateway.com/web/dropin/1.43.0/js/dropin.min.js"
data-braintree-dropin-authorization="CLIENT_AUTHORIZATION"
></script>
<input type="submit" value="Purchase"></input>
</form>
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Checkout</title>
</head>
<body>
<form id="payment-form" action="/" method="post">
<script src="https://js.braintreegateway.com/web/dropin/1.43.0/js/dropin.min.js"
data-braintree-dropin-authorization="CLIENT_AUTHORIZATION"
data-paypal.flow="checkout"
data-paypal.amount="10.00"
data-paypal.currency="USD"
data-paypal-credit.flow="vault"
></script>
<input type="submit" value="Purchase"></input>
</form>
</body>
</html>
<form id="payment-form" action="/" method="post">
<script src="https://js.braintreegateway.com/web/dropin/1.43.0/js/dropin.min.js"
data-braintree-dropin-authorization="CLIENT_AUTHORIZATION"
data-locale="de_DE"
data-payment-option-priority='["paypal","card", "paypalCredit"]'
data-paypal.flow="checkout"
data-paypal.amount="10.00"
data-paypal.currency="USD"
data-paypal-credit.flow="vault"
></script>
<input type="submit" value="Purchase"></input>
</form>
<form id="payment-form" action="/" method="post">
<script src="https://js.braintreegateway.com/web/dropin/1.43.0/js/dropin.min.js"
data-braintree-dropin-authorization="CLIENT_AUTHORIZATION"
data-card.cardholder-name.required="false"
></script>
<input type="submit" value="Purchase"></input>
</form>
<form id="payment-form" action="/" method="post">
<script src="https://js.braintreegateway.com/web/dropin/1.43.0/js/dropin.min.js"
data-braintree-dropin-authorization="CLIENT_AUTHORIZATION"
data-card.cardholder-name.required="true"
></script>
<input type="submit" value="Purchase"></input>
</form>
Members
(static) VERSION :string
The current version of Drop-in, i.e. 1.43.0
.
Methods
(static) create(options, callbackopt) → {void|Promise}
This function is the entry point for braintree.dropin
. It is used for creating Dropin instances.
Parameters:
Name | Type | Attributes | Description | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
object |
Object containing all Dropin options: Properties
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
callback |
function |
<optional> |
The second argument, |
Examples
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Checkout</title>
</head>
<body>
<div id="dropin-container"></div>
<button id="submit-button">Purchase</button>
<script src="https://js.braintreegateway.com/web/dropin/1.43.0/js/dropin.min.js"></script>
<script>
var submitButton = document.querySelector('#submit-button');
braintree.dropin.create({
authorization: 'CLIENT_AUTHORIZATION',
container: '#dropin-container'
}, function (err, dropinInstance) {
if (err) {
// Handle any errors that might've occurred when creating Drop-in
console.error(err);
return;
}
submitButton.addEventListener('click', function () {
dropinInstance.requestPaymentMethod(function (err, payload) {
if (err) {
// Handle errors in requesting payment method
}
// Send payload.nonce to your server
});
});
});
</script>
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Checkout</title>
</head>
<body>
<div id="dropin-container"></div>
<button id="submit-button">Purchase</button>
<script src="https://js.braintreegateway.com/web/dropin/1.43.0/js/dropin.min.js"></script>
<script>
var submitButton = document.querySelector('#submit-button');
braintree.dropin.create({
authorization: 'CLIENT_AUTHORIZATION',
container: '#dropin-container'
}).then(function (dropinInstance) {
submitButton.addEventListener('click', function () {
dropinInstance.requestPaymentMethod().then(function (payload) {
// Send payload.nonce to your server
}).catch(function (err) {
// Handle errors in requesting payment method
});
});
}).catch(function (err) {
// Handle any errors that might've occurred when creating Drop-in
console.error(err);
});
</script>
</body>
</html>
braintree.dropin.create({
authorization: 'CLIENT_AUTHORIZATION',
container: '#dropin-container',
applePay: {
displayName: 'Merchant Name',
paymentRequest: {
total: {
label: 'Localized Name',
amount: '10.00'
}
}
},
paypal: {
flow: 'checkout',
amount: '10.00',
currency: 'USD'
},
paypalCredit: {
flow: 'checkout',
amount: '10.00',
currency: 'USD'
},
venmo: true
}, function (err, dropinInstance) {
// Set up a handler to request a payment method and
// submit the payment method nonce to your server
});
braintree.dropin.create({
authorization: 'CLIENT_AUTHORIZATION',
container: '#dropin-container',
venmo: {
allowNewBrowserTab: false
}
}, function (err, dropinInstance) {
// Set up a handler to request a payment method and
// submit the payment method nonce to your server
});
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Checkout</title>
</head>
<body>
<form id="payment-form" action="/" method="post">
<div id="dropin-container"></div>
<input type="submit" value="Purchase"></input>
<input type="hidden" id="nonce" name="payment_method_nonce"></input>
</form>
<script src="https://js.braintreegateway.com/web/dropin/1.43.0/js/dropin.min.js"></script>
<script>
var form = document.querySelector('#payment-form');
var nonceInput = document.querySelector('#nonce');
braintree.dropin.create({
authorization: 'CLIENT_AUTHORIZATION',
container: '#dropin-container'
}, function (err, dropinInstance) {
if (err) {
// Handle any errors that might've occurred when creating Drop-in
console.error(err);
return;
}
form.addEventListener('submit', function (event) {
event.preventDefault();
dropinInstance.requestPaymentMethod(function (err, payload) {
if (err) {
// Handle errors in requesting payment method
return;
}
// Send payload.nonce to your server
nonceInput.value = payload.nonce;
form.submit();
});
});
});
</script>
</body>
</html>
braintree.dropin.create({
authorization: 'CLIENT_AUTHORIZATION',
container: '#dropin-container',
translations: {
payingWith: 'You are paying with {{paymentSource}}',
chooseAnotherWayToPay: 'My custom chooseAnotherWayToPay string',
// Any other custom translation strings
}
}, callback);
braintree.dropin.create({
authorization: 'CLIENT_AUTHORIZATION',
container: '#dropin-container',
card: {
overrides: {
fields: {
number: {
placeholder: '1111 1111 1111 1111' // Update the number field placeholder
},
postalCode: {
minlength: 5 // Set the minimum length of the postal code field
},
cvv: null // Remove the CVV field from your form
},
styles: {
input: {
'font-size': '18px' // Change the font size for all inputs
},
':focus': {
color: 'red' // Change the focus color to red for all inputs
}
}
}
}
}, callback);
braintree.dropin.create({
authorization: 'CLIENT_AUTHORIZATION',
container: '#dropin-container',
card: {
overrides: {
fields: {
number: {
maskInput: {
showLastFour: true
}
},
cvv: {
maskInput: true
}
}
}
}
}, callback);
braintree.dropin.create({
authorization: 'CLIENT_AUTHORIZATION',
container: '#dropin-container',
card: {
cardholderName: true
}
}, callback);
braintree.dropin.create({
authorization: 'CLIENT_AUTHORIZATION',
container: '#dropin-container',
card: {
cardholderName: {
required: true
}
}
}, callback);
braintree.dropin.create({
authorization: 'CLIENT_AUTHORIZATION',
container: '#dropin-container',
threeDSecure: true
}, function (err, dropinInstance) {
// setup payment button
btn.addEventListener('click', function (e) {
e.preventDefault();
dropinInstance.requestPaymentMethod(|
threeDSecure: {
amount: '100.00',
billingAddress: {
givenName: 'Jill', // ASCII-printable characters required, else will throw a validation error
surname: 'Doe', // ASCII-printable characters required, else will throw a validation error
phoneNumber: '8101234567',
streetAddress: '555 Smith St.',
extendedAddress: '#5',
locality: 'Oakland',
region: 'CA',
postalCode: '12345',
countryCodeAlpha2: 'US'
},
// additional 3ds params
}
}, function (err, payload) {
// inspect payload.liablityShifted
// send payload.nonce to server
});
});
});
braintree.dropin.create({
authorization: 'CLIENT_AUTHORIZATION',
container: '#dropin-container',
vaultManager: true
}, callback);
Type Definitions
applePayCreateOptions :object
The configuration options for Apple Pay.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
buttonStyle |
string |
<optional> |
black |
Configures the Apple Pay button style. Valid values are |
displayName |
string |
The canonical name for your store. Use a non-localized name. This parameter should be a utf-8 string that is a maximum of 128 characters. The system may display this name to the user. |
||
applePaySessionVersion |
number |
<optional> |
2 |
The version of the |
paymentRequest |
external:ApplePayPaymentRequest |
The payment request details to apply on top of those from Braintree. |
cardCreateOptions :object
The configuration options for cards. Internally, Drop-in uses Hosted Fields to render the card form. The overrides.fields
and overrides.styles
allow the Hosted Fields to be customized.
Parameters:
Name | Type | Attributes | Default | Description | |||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
cardholderName |
boolean | object |
<optional> |
Will enable a cardholder name field above the card number field. If set to an object, you can specify whether or not the field is required. If set to a Properties
|
||||||||||||||||
overrides.fields |
object |
<optional> |
The Hosted Fields [ |
||||||||||||||||
overrides.styles |
object |
<optional> |
The Hosted Fields [ |
||||||||||||||||
clearFieldsAfterTokenization |
boolean |
<optional> |
true |
When false, the card form will not clear the card data when the customer returns to the card view after a successful tokenization. |
|||||||||||||||
vault |
object |
<optional> |
Configuration for vaulting credit cards. Only applies when using a client token with a customer id. Properties
|
dataCollectorOptions :object
The configuration options for Data Collector. Requires advanced fraud protection to be enabled in the Braintree gateway. If using Kount, contact our support team to configure your Kount ID. The device data will be included on the requestPaymentMethod payload.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
kount |
boolean |
<optional> |
If true, Kount fraud data collection is enabled. |
googlePayCreateOptions :object
The configuration options for Google Pay. Additional options from the few listed here are available, many have default values applied based on the settings found in the Braintree Gateway. For more information, see Google's Documentation.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
merchantId |
string |
The ID provided by Google for processing transactions in production. Not necessary for testing in sandbox. |
||
googlePayVersion |
string |
<optional> |
1 |
The version of the Google Pay API to use. Defaults to 1, but 2 can be passed in. |
transactionInfo |
external:GooglePayTransactionInfo |
The transaction details necessary for processing the payment. |
||
button |
external:GooglePayButtonOptions |
<optional> |
The button options for configuring the look of the Google Pay button. The |
paypalCreateOptions :object
The configuration options for PayPal and PayPalCredit. For a full list of options see the PayPal Checkout client reference options.
Parameters:
Name | Type | Attributes | Description | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
flow |
string |
Either |
|||||||||||
amount |
string | number |
<optional> |
The amount of the transaction. Required when using the Checkout flow. |
||||||||||
currency |
string |
<optional> |
The currency code of the amount, such as |
||||||||||
buttonStyle |
object |
<optional> |
The style object to apply to the PayPal button. Button customization includes color, shape, size, and label. The options found here are available. |
||||||||||
commit |
boolean |
<optional> |
The user action to show on the PayPal review page. If true, a |
||||||||||
vault |
object |
<optional> |
Configuration for vaulting PayPal accounts. Only applies when using a client token with a customer id. Properties
|
threeDSecureOptions :object
Configuration options to pass when creating the 3D Secure module used in Drop-in. amount
for 3D Secure verification can be passed here, but it's recomended that it and all other 3D Secure verification options be passed to the requestPaymentMethod options instead. Any cardinalSDKConfig
options must be passed here when creating Drop-in.
Parameters:
Name | Type | Description |
---|---|---|
cardinalSDKConfig |
options |
A configuration object to adjust the configuration for the underlying Cardinal SDK (Braintree's 3D Secure provider). See |
amount |
string |
Deprecated The amount to verify with 3D Secure. Set amount in the requestPaymentMethod options instead. |
venmoCreateOptions :object|boolean
The configuration options for Venmo. If true
is passed instead of a configuration object, the default settings listed will be used.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
allowNewBrowserTab |
boolean |
<optional> |
true |
If false, it restricts supported browsers to those that can app switch to the Venmo app without opening a new tab. |