Security News
Oracle Drags Its Feet in the JavaScript Trademark Dispute
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
braintree-web-drop-in
Advanced tools
A pre-made payments UI for accepting cards and alternative payments in the browser built using version 3 of the [Braintree JS client SDK](https://github.com/braintree/braintree-web).
A pre-made payments UI for accepting cards and alternative payments in the browser built using version 3 of the Braintree JS client SDK.
Because we're still in beta, the API and designs are subject to change. If you have any feedback in these areas, create an issue or email us at web-drop-in-beta@getbraintree.com.
Drop-in is currently available directly from our servers, which you can save locally or include in your project through a script tag:
<script src="https://js.braintreegateway.com/web/dropin/1.0.0-beta.5/js/dropin.min.js"></script>
Drop-in provides a payment method object containing the payment method nonce to send to your server. To get this object, use the requestPaymentMethod
function as shown below.
For credit cards, this attempts to validate the card form and will call the supplied callback with a payload, including the payment method nonce, if successful. If not successful, an error will be shown in the UI and the callback will be called with an error.
Other payment methods may behave differently. Refer to their documentation for details.
In your create
call, provide an authorization
and a selector
:
authorization
: Your client authorization should be a client token from your server or a tokenization key that can be found in the Braintree Control Panel. If you pass a customer ID when generating the client token, Drop-in will display that customer's saved payment methods and automatically store any newly-added payment methods in their Vault record.
selector
: This must be the selector for an empty element, such as a <div>
, where Drop-in will be included on your page.
var submitButton = document.querySelector('#submit-button');
braintree.dropin.create({
authorization: 'CLIENT_AUTHORIZATION',
selector: '#dropin-container'
}, function (err, dropinInstance) {
submitButton.addEventListener('click', function () {
dropinInstance.requestPaymentMethod(function (err, payload) {
if (err) {
// Handle errors in requesting payment method
// This includes invalid card form or no payment method available
// Errors relevant to customers will be show in the UI as well
return;
}
// Send payload.nonce to your server
});
});
});
The structure of the credit card payment method object returned in the callback of requestPaymentMethod
can be found here.
If PayPal is enabled for your merchant account, include PayPal configuration options in the create
call. The required flow
property can be either vault
or checkout
, depending on whether you want to use the PayPal Vault or Checkout flow.
braintree.dropin.create({
authorization: 'CLIENT_AUTHORIZATION',
selector: '#dropin-container',
paypal: {
flow: 'checkout',
amount: 10.00,
currency: 'USD'
}
}, callback);
You can find more PayPal configuration options in the Braintree JS client SDK v3 reference.
The structure of the PayPal payment method object returned in the callback of requestPaymentMethod
can be found here.
This is a full example of a Drop-in integration that only accepts credit cards.
<!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.0.0-beta.4/js/dropin.min.js"></script>
<script>
var submitButton = document.querySelector('#submit-button');
braintree.dropin.create({
authorization: 'CLIENT_AUTHORIZATION',
selector: '#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>
While in beta, we're still actively working on Drop-in. This means you might have to change your integration when upgrading your Drop-in version. This includes any custom CSS styling applied to data-braintree-id
attributes.
Browser support will be limited during beta and will not include Internet Explorer 9 or 10, but will eventually include all browsers supported by Braintree.js.
Much of the behavior in this version of Drop-in differs from the previous version. At this point, adding the hidden payment_method_nonce
input and automatic form submission (the default behavior in the previous version) are not available.
Here are some of the features we're still working on:
1.0.0-beta.5
FAQs
[![Build Status](https://github.com/braintree/braintree-web-drop-in/workflows/Unit%20Tests/badge.svg)](https://github.com/braintree/braintree-web-drop-in/actions?query=workflow%3A%22Unit+Tests%22) [![Build Status](https://github.com/braintree/braintree-we
The npm package braintree-web-drop-in receives a total of 15,161 weekly downloads. As such, braintree-web-drop-in popularity was classified as popular.
We found that braintree-web-drop-in demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Security News
The Linux Foundation is warning open source developers that compliance with global sanctions is mandatory, highlighting legal risks and restrictions on contributions.
Security News
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.