Security News
Create React App Officially Deprecated Amid React 19 Compatibility Issues
Create React App is officially deprecated due to React 19 issues and lack of maintenance—developers should switch to Vite or other modern alternatives.
braintree-web-drop-in-react
Advanced tools
This is a React component that wraps braintree-web-drop-in
(v3).
Disclaimer: this is not an official Braintree module.
For issues and information concerning
braintree-web-drop-in
orbraintree-web
in general, please seebraintree/braintree-web-drop-in
andbraintree/braintree-web
.
This is an maintainted and updated rewrite of jeffcarp/braintree-react.
yarn add braintree-web-drop-in-react
# or
npm install braintree-web-drop-in-react
Requires Node.js v8+.
import React from "react";
import DropIn from "braintree-web-drop-in-react";
class Store extends React.Component {
instance;
state = {
clientToken: null
};
async componentDidMount() {
// Get a client token for authorization from your server
const response = await fetch("server.test/client_token");
const clientToken = await response.json(); // If returned as JSON string
this.setState({
clientToken
});
}
async buy() {
// Send the nonce to your server
const { nonce } = await this.instance.requestPaymentMethod();
await fetch(`server.test/purchase/${nonce}`);
}
render() {
if (!this.state.clientToken) {
return (
<div>
<h1>Loading...</h1>
</div>
);
} else {
return (
<div>
<DropIn
options={{ authorization: this.state.clientToken }}
onInstance={instance => (this.instance = instance)}
/>
<button onClick={this.buy.bind(this)}>Buy</button>
</div>
);
}
}
}
See example
.
options
(object
, required)Options to setup Braintree. See Drop-In options.
onInstance
(function: instance
)Called with the Braintree Drop-In instance when done initializing. You can call all regular Drop-In methods
The on
events are already listened to using onNoPaymentMethodRequestable
,
onPaymentMethodRequestable
, onPaymentOptionSelected
. See below.
isntance.requestPaymentMethod([callback])
: [Promise]
Requests a payment method object which includes the payment method nonce used by by the Braintree Server SDKs. The structure of this payment method object varies by type: a cardPaymentMethodPayload is returned when the payment method is a card, a paypalPaymentMethodPayload is returned when the payment method is a PayPal account.
If a payment method is not available, an error will appear in the UI. When a callback is used, an error will be passed to it. If no callback is used, the returned Promise will be rejected with an error.
Returns a Promise if no callback is provided.
instance.clearSelectedPaymentMethod()
: void
Removes the currently selected payment method and returns the customer to the payment options view. Does not remove vaulted payment methods.
instance.isPaymentMethodRequestable()
: boolean
Returns a boolean indicating if a payment method is available through requestPaymentMethod. Particularly useful for detecting if using a client token with a customer ID to show vaulted payment methods.
instance.updateConfiguration(property, key, value)
: void
Modify your configuration initially set in options
. Can be used for any paypal or paypalCredit property.
If updateConfiguration is called after a user completes the PayPal authorization flow, any PayPal accounts not stored in the Vault record will be removed.
onNoPaymentMethodRequestable
, onPaymentMethodRequestable
, onPaymentOptionSelected
(function: event
)Ran for events.
preselectVaultedPaymentMethod
(boolean
, default: true
)Whether or not to initialize with a vaulted payment method pre-selected. Only applicable when using a client token with a customer with saved payment methods.
FAQs
React component for Braintree Web Drop-In (v3)
The npm package braintree-web-drop-in-react receives a total of 4,001 weekly downloads. As such, braintree-web-drop-in-react popularity was classified as popular.
We found that braintree-web-drop-in-react demonstrated a not healthy version release cadence and project activity because the last version was released 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
Create React App is officially deprecated due to React 19 issues and lack of maintenance—developers should switch to Vite or other modern alternatives.
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.