Skip to content
This repository has been archived by the owner on Mar 22, 2024. It is now read-only.

Commit

Permalink
Merge pull request #1 from Thinkei/chore/add-options-prop
Browse files Browse the repository at this point in the history
Add options props
  • Loading branch information
toan2406 authored Nov 22, 2018
2 parents 3815c14 + c1852f9 commit fb32e3d
Show file tree
Hide file tree
Showing 4 changed files with 124 additions and 86 deletions.
2 changes: 1 addition & 1 deletion .babelrc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"presets": ["env", "react"],
"plugins": ["transform-class-properties"]
"plugins": ["transform-class-properties", "transform-object-rest-spread"]
}
13 changes: 8 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@
"test": "./node_modules/jest/bin/jest.js",
"update-test": "npm run test -- -u",
"clean": "rm -rf dist",
"build": "npm run clean && mkdir dist && ./node_modules/babel-cli/bin/babel.js ./src/index.js --out-file ./dist/index.js",
"example": "./node_modules/webpack/bin/webpack.js && ./node_modules/webpack-dev-server/bin/webpack-dev-server.js"
"build":
"npm run clean && mkdir dist && ./node_modules/babel-cli/bin/babel.js ./src/index.js --out-file ./dist/index.js",
"example":
"./node_modules/webpack/bin/webpack.js && ./node_modules/webpack-dev-server/bin/webpack-dev-server.js"
},
"repository": {
"type": "git",
Expand All @@ -34,9 +36,10 @@
"babel-eslint": "^8.1.2",
"babel-loader": "^7.1.2",
"babel-plugin-transform-class-properties": "^6.24.1",
"babel-plugin-transform-object-rest-spread": "^6.26.0",
"babel-preset-env": "^1.6.1",
"babel-preset-react": "^6.24.1",
"braintree-web-drop-in": "^1.3.1",
"braintree-web-drop-in": "^1.13.0",
"enzyme": "^3.3.0",
"enzyme-adapter-react-16": "^1.1.1",
"enzyme-to-json": "^3.3.0",
Expand All @@ -58,7 +61,7 @@
},
"dependencies": {
"prop-types": "^15.6.0",
"react": "^16.2.0",
"react-dom": "^16.2.0"
"react": "^16.5.2",
"react-dom": "^16.5.2"
}
}
78 changes: 39 additions & 39 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,52 +53,51 @@ class BraintreeDropIn extends React.Component {
};

setup = () => {
this.props.braintree.create(
{
authorization: this.props.authorizationToken,
container: '.braintree-dropin-react-form',
locale: this.props.locale,
paypal: this.props.paypal,
paypalCredit: this.props.paypalCredit,
paymentOptionPriority: this.props.paymentOptionPriority,
card: this.props.card,
vaultManager: this.props.vaultManager,
},
(err, dropinInstance) => {
if (err) {
if (this.props.onError) {
this.props.onError(err);
}
return;
} else {
if (this.props.onCreate) {
this.props.onCreate(dropinInstance);
}
const options = {
locale: this.props.locale,
paypal: this.props.paypal,
paypalCredit: this.props.paypalCredit,
paymentOptionPriority: this.props.paymentOptionPriority,
card: this.props.card,
...this.props.options,
authorization: this.props.authorizationToken,
container: '.braintree-dropin-react-form',
vaultManager: this.props.vaultManager,
};
this.props.braintree.create(options, (err, dropinInstance) => {
if (err) {
if (this.props.onError) {
this.props.onError(err);
}

if (dropinInstance.isPaymentMethodRequestable()) {
this.setState({
isSubmitButtonDisabled: false,
});
return;
} else {
if (this.props.onCreate) {
this.props.onCreate(dropinInstance);
}
}

dropinInstance.on('paymentMethodRequestable', event => {
this.setState({
isSubmitButtonDisabled: false,
});
if (dropinInstance.isPaymentMethodRequestable()) {
this.setState({
isSubmitButtonDisabled: false,
});
}

dropinInstance.on('noPaymentMethodRequestable', () => {
this.setState({
isSubmitButtonDisabled: true,
});
dropinInstance.on('paymentMethodRequestable', event => {
this.setState({
isSubmitButtonDisabled: false,
});
});

dropinInstance.on('noPaymentMethodRequestable', () => {
this.setState({
dropInInstance: dropinInstance,
isSubmitButtonDisabled: true,
});
},
);
});

this.setState({
dropInInstance: dropinInstance,
});
});
};

tearDown = () => {
Expand All @@ -121,7 +120,7 @@ class BraintreeDropIn extends React.Component {

handleSubmit = event => {
if (this.state.dropInInstance && !this.state.isSubmitButtonDisabled) {
this.setState({isSubmitButtonDisabled: true}, () => {
this.setState({ isSubmitButtonDisabled: true }, () => {
this.state.dropInInstance.requestPaymentMethod((err, payload) => {
this.setState({
isSubmitButtonDisabled: false,
Expand Down Expand Up @@ -156,6 +155,7 @@ class BraintreeDropIn extends React.Component {

BraintreeDropIn.propTypes = {
braintree: PropTypes.object.isRequired,
options: PropTypes.object,
authorizationToken: PropTypes.string.isRequired,
handlePaymentMethod: PropTypes.func.isRequired,
onCreate: PropTypes.func,
Expand All @@ -173,7 +173,7 @@ BraintreeDropIn.propTypes = {
renderSubmitButton: PropTypes.func,
};

const renderSubmitButton = ({onClick, isDisabled, text}) => {
const renderSubmitButton = ({ onClick, isDisabled, text }) => {
return (
<button onClick={onClick} disabled={isDisabled}>
{text}
Expand Down
117 changes: 76 additions & 41 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -63,17 +63,27 @@
lodash "^4.2.0"
to-fast-properties "^2.0.0"

"@braintree/[email protected]":
version "0.2.0"
resolved "http://npm.mimosatek.com/@braintree%2fasset-loader/-/asset-loader-0.2.0.tgz#f30f039df98bb3662677a88828fa36dde082cea8"
dependencies:
promise-polyfill "^8.1.0"

"@braintree/[email protected]", "@braintree/browser-detection@^1.5.0":
version "1.7.0"
resolved "https://registry.yarnpkg.com/@braintree/browser-detection/-/browser-detection-1.7.0.tgz#895ba64b700c3f36cab5c54591caf71a41171dd8"

"@braintree/[email protected]":
version "0.1.0"
resolved "http://npm.mimosatek.com/@braintree%2fclass-list/-/class-list-0.1.0.tgz#d6c8606ce6a82b4b37f28e32eadd090abcf1adaa"

"@braintree/[email protected]":
version "1.0.3"
resolved "https://registry.yarnpkg.com/@braintree/iframer/-/iframer-1.0.3.tgz#21dd1fd4cebd4154aeab1efa4d5b0d5f4384364e"

"@braintree/sanitize-url@2.0.2":
version "2.0.2"
resolved "https://registry.yarnpkg.com/@braintree/sanitize-url/-/sanitize-url-2.0.2.tgz#2b37caa50687ac47370520a502f5226ee31a5ab1"
"@braintree/sanitize-url@2.1.0":
version "2.1.0"
resolved "http://npm.mimosatek.com/@braintree%2fsanitize-url/-/sanitize-url-2.1.0.tgz#549a9d1f923c9bc7953a585d3e9aa9429be8fe28"

"@braintree/[email protected]":
version "1.1.1"
Expand Down Expand Up @@ -576,9 +586,9 @@ babel-plugin-syntax-jsx@^6.3.13, babel-plugin-syntax-jsx@^6.8.0:
version "6.18.0"
resolved "https://registry.yarnpkg.com/babel-plugin-syntax-jsx/-/babel-plugin-syntax-jsx-6.18.0.tgz#0af32a9a6e13ca7a3fd5069e62d7b0f58d0d8946"

babel-plugin-syntax-object-rest-spread@^6.13.0:
babel-plugin-syntax-object-rest-spread@^6.13.0, babel-plugin-syntax-object-rest-spread@^6.8.0:
version "6.13.0"
resolved "https://registry.yarnpkg.com/babel-plugin-syntax-object-rest-spread/-/babel-plugin-syntax-object-rest-spread-6.13.0.tgz#fd6536f2bce13836ffa3a5458c4903a597bb3bf5"
resolved "http://npm.mimosatek.com/babel-plugin-syntax-object-rest-spread/-/babel-plugin-syntax-object-rest-spread-6.13.0.tgz#fd6536f2bce13836ffa3a5458c4903a597bb3bf5"

babel-plugin-syntax-trailing-function-commas@^6.22.0:
version "6.22.0"
Expand Down Expand Up @@ -784,6 +794,13 @@ babel-plugin-transform-flow-strip-types@^6.22.0:
babel-plugin-syntax-flow "^6.18.0"
babel-runtime "^6.22.0"

babel-plugin-transform-object-rest-spread@^6.26.0:
version "6.26.0"
resolved "http://npm.mimosatek.com/babel-plugin-transform-object-rest-spread/-/babel-plugin-transform-object-rest-spread-6.26.0.tgz#0f36692d50fef6b7e2d4b3ac1478137a963b7b06"
dependencies:
babel-plugin-syntax-object-rest-spread "^6.8.0"
babel-runtime "^6.26.0"

babel-plugin-transform-react-display-name@^6.23.0:
version "6.25.0"
resolved "https://registry.yarnpkg.com/babel-plugin-transform-react-display-name/-/babel-plugin-transform-react-display-name-6.25.0.tgz#67e2bf1f1e9c93ab08db96792e05392bf2cc28d1"
Expand Down Expand Up @@ -1055,28 +1072,32 @@ braces@^1.8.2:
preserve "^0.2.0"
repeat-element "^1.1.2"

braintree-web-drop-in@^1.3.1:
version "1.9.2"
resolved "https://registry.yarnpkg.com/braintree-web-drop-in/-/braintree-web-drop-in-1.9.2.tgz#8d39fcd97ee98363fa6690884009a551f69d701c"
braintree-web-drop-in@^1.13.0:
version "1.14.1"
resolved "http://npm.mimosatek.com/braintree-web-drop-in/-/braintree-web-drop-in-1.14.1.tgz#ac414c5f0c8ab14f233dbc43f27342b31d900917"
dependencies:
"@braintree/asset-loader" "0.2.0"
"@braintree/browser-detection" "1.7.0"
"@braintree/class-list" "0.1.0"
"@braintree/wrap-promise" "1.1.1"
braintree-web "3.26.0"
promise-polyfill "6.0.2"
braintree-web "3.39.0"
promise-polyfill "8.1.0"

braintree-web@3.26.0:
version "3.26.0"
resolved "https://registry.yarnpkg.com/braintree-web/-/braintree-web-3.26.0.tgz#97ebc66e0a61f64c429f53f4689fa9f733366f6e"
braintree-web@3.39.0:
version "3.39.0"
resolved "http://npm.mimosatek.com/braintree-web/-/braintree-web-3.39.0.tgz#b5dd494c8d1f0a730b52bf043cd14fc975e0f65d"
dependencies:
"@braintree/asset-loader" "0.2.0"
"@braintree/browser-detection" "1.7.0"
"@braintree/class-list" "0.1.0"
"@braintree/iframer" "1.0.3"
"@braintree/sanitize-url" "2.0.2"
"@braintree/sanitize-url" "2.1.0"
"@braintree/wrap-promise" "1.1.1"
card-validator "4.1.1"
credit-card-type "6.1.0"
framebus "2.0.8"
card-validator "6.0.0"
credit-card-type "8.0.0"
framebus "3.0.1"
inject-stylesheet "1.0.0"
promise-polyfill "6.0.2"
promise-polyfill "8.1.0"
restricted-input "1.2.7"

brorand@^1.0.1:
Expand Down Expand Up @@ -1227,11 +1248,11 @@ caniuse-lite@^1.0.30000780:
version "1.0.30000784"
resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30000784.tgz#129ced74e9a1280a441880b6cd2bce30ef59e6c0"

card-validator@4.1.1:
version "4.1.1"
resolved "https://registry.yarnpkg.com/card-validator/-/card-validator-4.1.1.tgz#f0683e0f5dbd29c02cfb1a1b665cdba430622faa"
card-validator@6.0.0:
version "6.0.0"
resolved "http://npm.mimosatek.com/card-validator/-/card-validator-6.0.0.tgz#ed35134e3545bfb9ab88204778f8007fc023ea80"
dependencies:
credit-card-type "^6.0.0"
credit-card-type "^8.0.0"

caseless@~0.12.0:
version "0.12.0"
Expand Down Expand Up @@ -1484,9 +1505,9 @@ create-hmac@^1.1.0, create-hmac@^1.1.2, create-hmac@^1.1.4:
safe-buffer "^5.0.1"
sha.js "^2.4.8"

credit-card-type@6.1.0, credit-card-type@^6.0.0:
version "6.1.0"
resolved "https://registry.yarnpkg.com/credit-card-type/-/credit-card-type-6.1.0.tgz#f1acd3d47cf8202a66b60a9c90cbf9738d57ef40"
credit-card-type@8.0.0, credit-card-type@^8.0.0:
version "8.0.0"
resolved "http://npm.mimosatek.com/credit-card-type/-/credit-card-type-8.0.0.tgz#e65347bcdb979b4deb3107cd43a1cd9da802cd50"

cross-spawn@^5.0.1, cross-spawn@^5.1.0:
version "5.1.0"
Expand Down Expand Up @@ -2431,9 +2452,9 @@ forwarded@~0.1.2:
version "0.1.2"
resolved "https://registry.yarnpkg.com/forwarded/-/forwarded-0.1.2.tgz#98c23dab1175657b8c0573e8ceccd91b0ff18c84"

framebus@2.0.8:
version "2.0.8"
resolved "https://registry.yarnpkg.com/framebus/-/framebus-2.0.8.tgz#01c7ee5f765beb3f9a2e0390ca0b7088b2bf76d3"
framebus@3.0.1:
version "3.0.1"
resolved "http://npm.mimosatek.com/framebus/-/framebus-3.0.1.tgz#dbabc3b08e39bf33d248e9af754bd8ffb05cfcce"

[email protected]:
version "0.5.2"
Expand Down Expand Up @@ -4309,9 +4330,9 @@ progress@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/progress/-/progress-2.0.0.tgz#8a1be366bf8fc23db2bd23f10c6fe920b4389d1f"

promise-polyfill@6.0.2:
version "6.0.2"
resolved "https://registry.yarnpkg.com/promise-polyfill/-/promise-polyfill-6.0.2.tgz#d9c86d3dc4dc2df9016e88946defd69b49b41162"
promise-polyfill@8.1.0, promise-polyfill@^8.1.0:
version "8.1.0"
resolved "http://npm.mimosatek.com/promise-polyfill/-/promise-polyfill-8.1.0.tgz#30059da54d1358ce905ac581f287e184aedf995d"

promise@^7.1.1:
version "7.3.1"
Expand All @@ -4327,6 +4348,13 @@ prop-types@^15.6.0:
loose-envify "^1.3.1"
object-assign "^4.1.1"

prop-types@^15.6.2:
version "15.6.2"
resolved "http://npm.mimosatek.com/prop-types/-/prop-types-15.6.2.tgz#05d5ca77b4453e985d60fc7ff8c859094a497102"
dependencies:
loose-envify "^1.3.1"
object-assign "^4.1.1"

proxy-addr@~2.0.2:
version "2.0.2"
resolved "https://registry.yarnpkg.com/proxy-addr/-/proxy-addr-2.0.2.tgz#6571504f47bb988ec8180253f85dd7e14952bdec"
Expand Down Expand Up @@ -4451,14 +4479,14 @@ react-addons-test-utils@^15.6.2:
version "15.6.2"
resolved "https://registry.yarnpkg.com/react-addons-test-utils/-/react-addons-test-utils-15.6.2.tgz#c12b6efdc2247c10da7b8770d185080a7b047156"

react-dom@^16.2.0:
version "16.2.0"
resolved "https://registry.yarnpkg.com/react-dom/-/react-dom-16.2.0.tgz#69003178601c0ca19b709b33a83369fe6124c044"
react-dom@^16.5.2:
version "16.6.3"
resolved "http://npm.mimosatek.com/react-dom/-/react-dom-16.6.3.tgz#8fa7ba6883c85211b8da2d0efeffc9d3825cccc0"
dependencies:
fbjs "^0.8.16"
loose-envify "^1.1.0"
object-assign "^4.1.1"
prop-types "^15.6.0"
prop-types "^15.6.2"
scheduler "^0.11.2"

react-reconciler@^0.7.0:
version "0.7.0"
Expand All @@ -4477,14 +4505,14 @@ react-test-renderer@^16.0.0-0, react-test-renderer@^16.2.0:
object-assign "^4.1.1"
prop-types "^15.6.0"

react@^16.2.0:
version "16.2.0"
resolved "https://registry.yarnpkg.com/react/-/react-16.2.0.tgz#a31bd2dab89bff65d42134fa187f24d054c273ba"
react@^16.5.2:
version "16.6.3"
resolved "http://npm.mimosatek.com/react/-/react-16.6.3.tgz#25d77c91911d6bbdd23db41e70fb094cc1e0871c"
dependencies:
fbjs "^0.8.16"
loose-envify "^1.1.0"
object-assign "^4.1.1"
prop-types "^15.6.0"
prop-types "^15.6.2"
scheduler "^0.11.2"

read-pkg-up@^1.0.1:
version "1.0.1"
Expand Down Expand Up @@ -4804,6 +4832,13 @@ sax@^1.2.1:
version "1.2.4"
resolved "https://registry.yarnpkg.com/sax/-/sax-1.2.4.tgz#2816234e2378bddc4e5354fab5caa895df7100d9"

scheduler@^0.11.2:
version "0.11.2"
resolved "http://npm.mimosatek.com/scheduler/-/scheduler-0.11.2.tgz#a8db5399d06eba5abac51b705b7151d2319d33d3"
dependencies:
loose-envify "^1.1.0"
object-assign "^4.1.1"

select-hose@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/select-hose/-/select-hose-2.0.0.tgz#625d8658f865af43ec962bfc376a37359a4994ca"
Expand Down

0 comments on commit fb32e3d

Please sign in to comment.