This is a React component that wraps braintree-web-drop-in (v3).
Install
yarn add braintree-web-drop-in-react
# or
npm install braintree-web-drop-in-react
Bash
Requires Node.js v8+.
Drop-In
Complete example
import React from"react";import DropIn from"braintree-web-drop-in-react";classStoreextendsReact.Component{
instance;
state ={
clientToken:null};asynccomponentDidMount(){// Get a client token for authorization from your serverconst response =awaitfetch("server.test/client_token");const clientToken =await response.json();// If returned as JSON stringthis.setState({
clientToken
});}asyncbuy(){// Send the nonce to your serverconst{ nonce }=awaitthis.instance.requestPaymentMethod();awaitfetch(`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>);}}}