Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

react-braintree-fields

Package Overview
Dependencies
Maintainers
1
Versions
23
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-braintree-fields - npm Package Compare versions

Comparing version 1.5.0 to 1.6.0

LICENSE

12

.eslintrc.js
module.exports = {
"extends": "argosity",
"extends": "eslint:recommended",
"parser": "babel-eslint",
"parserOptions": {
"ecmaVersion": 6,
"sourceType": "module"
},
"env": {
"browser": true,
"amd": true,
"node": true
},
rules: {

@@ -5,0 +15,0 @@ 'no-underscore-dangle': 0,

25

demo/demo-class.jsx

@@ -1,2 +0,1 @@

import { render } from 'react-dom';
import React from 'react';

@@ -33,15 +32,14 @@ import { Braintree, HostedField } from '../src/index';

if (1 === cards.length) {
const [card] = cards;
const [card] = cards;
this.setState({ card: card.type });
this.setState({ card: card.type });
if (card.code && card.code.name) {
this.cvvField.setPlaceholder(card.code.name);
} else {
if (card.code && card.code.name) {
this.cvvField.setPlaceholder(card.code.name);
} else {
this.cvvField.setPlaceholder('CVV');
}
} else {
this.setState({ card: '' });
this.cvvField.setPlaceholder('CVV');
}
} else {
this.setState({ card: '' });
this.cvvField.setPlaceholder('CVV');
}

@@ -69,3 +67,3 @@ }

onAuthorizationSuccess() {
this.numberField.current.focus();
this.numberField.current.focus();
}

@@ -109,2 +107,4 @@

<p>Card type: {this.state.card}</p>
Name:
<HostedField type="cardholderName" />
Date:

@@ -128,4 +128,5 @@ <HostedField type="expirationDate" />

}
}
export default Demo;

@@ -1,2 +0,1 @@

import { render } from 'react-dom';
import React from 'react';

@@ -6,42 +5,42 @@ import { Braintree, HostedField } from '../src/index';

const Demo = () => {
const [tokenize, setTokenizeFunc] = React.useState()
const [cardType, setCardType] = React.useState('')
const [error, setError] = React.useState(null)
const [token, setToken] = React.useState(null)
const [focusedFieldName, setFocusedField] = React.useState('')
const numberField = React.useRef()
const [tokenize, setTokenizeFunc] = React.useState();
const [cardType, setCardType] = React.useState('');
const [error, setError] = React.useState(null);
const [token, setToken] = React.useState(null);
const [focusedFieldName, setFocusedField] = React.useState('');
const numberField = React.useRef();
const cvvField = React.useRef();
const cardholderNameField = React.useRef();
const onAuthorizationSuccess = () => {
numberField.current.focus();
}
numberField.current.focus();
};
const onDataCollectorInstanceReady = (collector) => {
// DO SOMETHING with Braintree collector as needed
}
};
const handleError = (error) => {
setError(error.message || String(error));
}
const handleError = (newError) => {
setError(newError.message || String(newError));
};
const onFieldBlur = (field, event) => setFocusedField('')
const onFieldFocus = (field, event) => setFocusedField(event.emittedBy)
const onFieldBlur = (field, event) => setFocusedField('');
const onFieldFocus = (field, event) => setFocusedField(event.emittedBy);
const onCardTypeChange = ({ cards }) => {
if (1 === cards.length) {
const [card] = cards;
const [card] = cards;
setCardType(card.type);
setCardType(card.type);
if (card.code && card.code.name) {
cvvField.current.setPlaceholder(card.code.name);
} else {
cvvField.current.setPlaceholder('CVV');
}
if (card.code && card.code.name) {
cvvField.current.setPlaceholder(card.code.name);
} else {
cvvField.current.setPlaceholder('CVV');
}
} else {
setCardType('');
cvvField.current.setPlaceholder('CVV');
cvvField.current.setPlaceholder('CVV');
}
}
};

@@ -52,3 +51,3 @@ const getToken = () => {

.catch(handleError);
}
};

@@ -63,3 +62,3 @@ const renderResult = (title, obj) => {

);
}
};

@@ -77,7 +76,7 @@ return (

styles={{
'input': {
input: {
'font-size': 'inherit',
},
':focus': {
'color': 'blue'
color: 'blue',
},

@@ -93,3 +92,3 @@ }}

type="number"
className={focusedFieldName == 'number' ? 'focused' : ''}
className={'number' === focusedFieldName ? 'focused' : ''}
onBlur={onFieldBlur}

@@ -101,2 +100,11 @@ onFocus={onFieldFocus}

<p>Card type: {cardType}</p>
Name:
<HostedField
type="cardholderName"
className={'cardholderName' === focusedFieldName ? 'focused' : ''}
onBlur={onFieldBlur}
onFocus={onFieldFocus}
placeholder="Name on Card"
ref={cardholderNameField}
/>
Date:

@@ -107,3 +115,3 @@ <HostedField

onFocus={onFieldFocus}
className={focusedFieldName == 'expirationDate' ? 'focused' : ''}
className={'expirationDate' === focusedFieldName ? 'focused' : ''}
/>

@@ -125,6 +133,5 @@ Month:

</div>
)
);
};
}
export default Demo;
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('react'), require('prop-types'), require('braintree-web/client'), require('braintree-web/hosted-fields'), require('braintree-web/data-collector')) :
typeof define === 'function' && define.amd ? define(['exports', 'react', 'prop-types', 'braintree-web/client', 'braintree-web/hosted-fields', 'braintree-web/data-collector'], factory) :
(global = global || self, factory(global['react-braintree-fields'] = {}, global.React, global.PropTypes, global.Braintree, global.BraintreeHostedFields, global.BraintreeDataCollector));
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global['react-braintree-fields'] = {}, global.React, global.PropTypes, global.Braintree, global.BraintreeHostedFields, global.BraintreeDataCollector));
}(this, (function (exports, React, PropTypes, Braintree$1, HostedFields, BraintreeDataCollector) { 'use strict';
React = React && Object.prototype.hasOwnProperty.call(React, 'default') ? React['default'] : React;
PropTypes = PropTypes && Object.prototype.hasOwnProperty.call(PropTypes, 'default') ? PropTypes['default'] : PropTypes;
Braintree$1 = Braintree$1 && Object.prototype.hasOwnProperty.call(Braintree$1, 'default') ? Braintree$1['default'] : Braintree$1;
HostedFields = HostedFields && Object.prototype.hasOwnProperty.call(HostedFields, 'default') ? HostedFields['default'] : HostedFields;
BraintreeDataCollector = BraintreeDataCollector && Object.prototype.hasOwnProperty.call(BraintreeDataCollector, 'default') ? BraintreeDataCollector['default'] : BraintreeDataCollector;
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
var PropTypes__default = /*#__PURE__*/_interopDefaultLegacy(PropTypes);
var Braintree__default = /*#__PURE__*/_interopDefaultLegacy(Braintree$1);
var HostedFields__default = /*#__PURE__*/_interopDefaultLegacy(HostedFields);
var BraintreeDataCollector__default = /*#__PURE__*/_interopDefaultLegacy(BraintreeDataCollector);
function _objectWithoutPropertiesLoose(source, excluded) {

@@ -88,3 +90,3 @@ if (source == null) return {};

this.authorization = authorization;
Braintree$1.create({
Braintree__default['default'].create({
authorization

@@ -98,3 +100,3 @@ }, (err, clientInstance) => {

if (this.wrapperHandlers.onDataCollectorInstanceReady) {
BraintreeDataCollector.create({
BraintreeDataCollector__default['default'].create({
client: clientInstance,

@@ -126,3 +128,3 @@ kount: true

this.client = client;
HostedFields.create({
HostedFields__default['default'].create({
client,

@@ -225,2 +227,3 @@ styles: this.styles,

return new Promise((resolve, reject) => {
// eslint-disable-line no-undef
this.hostedFields.tokenize(options, (err, payload) => {

@@ -239,3 +242,3 @@ if (err) {

class Braintree extends React.Component {
class Braintree extends React__default['default'].Component {
constructor(props) {

@@ -283,3 +286,3 @@ super(props);

return React.createElement(Tag, {
return /*#__PURE__*/React__default['default'].createElement(Tag, {
className: className

@@ -291,12 +294,12 @@ }, this.props.children);

Braintree.propTypes = {
children: PropTypes.node.isRequired,
onAuthorizationSuccess: PropTypes.func,
authorization: PropTypes.string,
getTokenRef: PropTypes.func,
onValidityChange: PropTypes.func,
onCardTypeChange: PropTypes.func,
onError: PropTypes.func,
styles: PropTypes.object,
className: PropTypes.string,
tagName: PropTypes.string
children: PropTypes__default['default'].node.isRequired,
onAuthorizationSuccess: PropTypes__default['default'].func,
authorization: PropTypes__default['default'].string,
getTokenRef: PropTypes__default['default'].func,
onValidityChange: PropTypes__default['default'].func,
onCardTypeChange: PropTypes__default['default'].func,
onError: PropTypes__default['default'].func,
styles: PropTypes__default['default'].object,
className: PropTypes__default['default'].string,
tagName: PropTypes__default['default'].string
};

@@ -307,6 +310,6 @@ Braintree.defaultProps = {

Braintree.childContextTypes = {
braintreeApi: PropTypes.instanceOf(BraintreeClientApi)
braintreeApi: PropTypes__default['default'].instanceOf(BraintreeClientApi)
};
class BraintreeHostedField extends React.Component {
class BraintreeHostedField extends React__default['default'].Component {
constructor() {

@@ -355,3 +358,3 @@ super(...arguments);

return React.createElement("div", {
return /*#__PURE__*/React__default['default'].createElement("div", {
id: fieldId,

@@ -364,16 +367,16 @@ className: this.className

BraintreeHostedField.propTypes = {
type: PropTypes.oneOf(['number', 'expirationDate', 'expirationMonth', 'expirationYear', 'cvv', 'postalCode']).isRequired,
id: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
placeholder: PropTypes.string,
className: PropTypes.string,
onCardTypeChange: PropTypes.func,
onValidityChange: PropTypes.func,
onNotEmpty: PropTypes.func,
onFocus: PropTypes.func,
onEmpty: PropTypes.func,
onBlur: PropTypes.func,
prefill: PropTypes.string
type: PropTypes__default['default'].oneOf(['number', 'expirationDate', 'expirationMonth', 'expirationYear', 'cvv', 'postalCode', 'cardholderName']).isRequired,
id: PropTypes__default['default'].oneOfType([PropTypes__default['default'].string, PropTypes__default['default'].number]),
placeholder: PropTypes__default['default'].string,
className: PropTypes__default['default'].string,
onCardTypeChange: PropTypes__default['default'].func,
onValidityChange: PropTypes__default['default'].func,
onNotEmpty: PropTypes__default['default'].func,
onFocus: PropTypes__default['default'].func,
onEmpty: PropTypes__default['default'].func,
onBlur: PropTypes__default['default'].func,
prefill: PropTypes__default['default'].string
};
BraintreeHostedField.contextTypes = {
braintreeApi: PropTypes.instanceOf(BraintreeClientApi)
braintreeApi: PropTypes__default['default'].instanceOf(BraintreeClientApi)
};

@@ -380,0 +383,0 @@

@@ -216,2 +216,3 @@ import React from 'react';

return new Promise((resolve, reject) => {
// eslint-disable-line no-undef
this.hostedFields.tokenize(options, (err, payload) => {

@@ -273,3 +274,3 @@ if (err) {

return React.createElement(Tag, {
return /*#__PURE__*/React.createElement(Tag, {
className: className

@@ -343,3 +344,3 @@ }, this.props.children);

return React.createElement("div", {
return /*#__PURE__*/React.createElement("div", {
id: fieldId,

@@ -352,3 +353,3 @@ className: this.className

BraintreeHostedField.propTypes = {
type: PropTypes.oneOf(['number', 'expirationDate', 'expirationMonth', 'expirationYear', 'cvv', 'postalCode']).isRequired,
type: PropTypes.oneOf(['number', 'expirationDate', 'expirationMonth', 'expirationYear', 'cvv', 'postalCode', 'cardholderName']).isRequired,
id: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),

@@ -355,0 +356,0 @@ placeholder: PropTypes.string,

{
"name": "react-braintree-fields",
"version": "1.5.0",
"version": "1.6.0",
"description": "React component for braintree hosted fields",

@@ -13,4 +13,3 @@ "browser": "dist/build.full.js",

"peerDependencies": {
"prop-types": "^15.7",
"react": "^16.13"
"react": "16 - 17"
},

@@ -30,16 +29,16 @@ "scripts": {

"devDependencies": {
"@babel/core": "^7.8.7",
"@babel/plugin-proposal-class-properties": "^7.8.3",
"@babel/preset-env": "^7.8.7",
"@babel/preset-react": "^7.8.3",
"@babel/core": "^7.13.15",
"@babel/plugin-proposal-class-properties": "^7.13.0",
"@babel/preset-env": "^7.13.15",
"@babel/preset-react": "^7.13.13",
"babel-core": "^7.0.0-bridge.0",
"babel-loader": "^8.0.6",
"babel-loader": "^8.2.2",
"babelrc-rollup": "^3.0.0",
"enzyme": "^3.11.0",
"enzyme-adapter-react-16": "^1.15.2",
"eslint": "^6.8.0",
"eslint-config-argosity": "^2.0.0",
"eslint-plugin-react": "^7.19.0",
"jest": "^25.1.0",
"jest-cli": "^25.1.0",
"enzyme-adapter-react-16": "^1.15.6",
"eslint": "^7.24.0",
"eslint-config-argosity": "^3.1.0",
"eslint-plugin-react": "^7.23.2",
"jest": "^26.6.3",
"jest-cli": "^26.6.3",
"prop-types": "^15.7.2",

@@ -50,11 +49,11 @@ "raf": "^3.4.1",

"react-test-renderer": "^16.13.0",
"rollup": "^2.0.6",
"rollup": "^2.45.2",
"rollup-plugin-babel": "^4.4.0",
"webpack": "^4.42.0",
"webpack-cli": "^3.3.11",
"webpack-dev-server": "^3.10.3"
"webpack": "^5.32.0",
"webpack-cli": "^4.6.0",
"webpack-dev-server": "^3.11.2"
},
"dependencies": {
"braintree-web": "^3.59.0"
"braintree-web": "^3.76.2"
}
}

@@ -14,7 +14,7 @@ module.exports = {

"console": false,
"jest": false
"jest": false,
},
"rules": {
"no-console": 0
}
};
"no-console": 0,
},
}

@@ -24,2 +24,3 @@ import React from 'react';

>
<HostedField type="cardholderName" placeholder="name" {...props.cardholderName} />
<HostedField type="number" placeholder="cc #" {...props.number} />

@@ -26,0 +27,0 @@ <HostedField type="expirationDate" placeholder="date" {...props.expirationDate} />

@@ -1,4 +0,4 @@

import { configure } from 'enzyme';
import ReactSixteenAdapter from 'enzyme-adapter-react-16';
import { configure } from 'enzyme'
import ReactSixteenAdapter from 'enzyme-adapter-react-16'
configure({ adapter: new ReactSixteenAdapter() });
configure({ adapter: new ReactSixteenAdapter() })

@@ -1,7 +0,7 @@

import Braintree from 'braintree-web/client';
import HostedFields from 'braintree-web/hosted-fields';
import BraintreeDataCollector from 'braintree-web/data-collector';
import Braintree from 'braintree-web/client'
import HostedFields from 'braintree-web/hosted-fields'
import BraintreeDataCollector from 'braintree-web/data-collector'
function cap(string) {
return string.charAt(0).toUpperCase() + string.slice(1);
return string.charAt(0).toUpperCase() + string.slice(1)
}

@@ -20,5 +20,5 @@

}) {
this.styles = styles || {};
this.wrapperHandlers = callbacks || {};
this.setAuthorization(authorization, onAuthorizationSuccess);
this.styles = styles || {}
this.wrapperHandlers = callbacks || {}
this.setAuthorization(authorization, onAuthorizationSuccess)
}

@@ -28,3 +28,3 @@

if (!authorization && this.authorization) {
this.teardown();
this.teardown()
} else if (authorization && authorization !== this.authorization) {

@@ -34,15 +34,15 @@ // fields have not yet checked in, delay setting so they can register

this.pendingAuthTimer = setTimeout(() => {
this.pendingAuthTimer = null;
this.setAuthorization(authorization, onAuthorizationSuccess);
}, 5);
return;
this.pendingAuthTimer = null
this.setAuthorization(authorization, onAuthorizationSuccess)
}, 5)
return
}
if (this.authorization) { this.teardown(); }
this.authorization = authorization;
if (this.authorization) { this.teardown() }
this.authorization = authorization
Braintree.create({ authorization }, (err, clientInstance) => {
if (err) {
this.onError(err);
this.onError(err)
} else {
this.create(clientInstance, onAuthorizationSuccess);
this.create(clientInstance, onAuthorizationSuccess)

@@ -53,6 +53,6 @@ if (this.wrapperHandlers.onDataCollectorInstanceReady) {

kount: true,
}, this.wrapperHandlers.onDataCollectorInstanceReady);
}, this.wrapperHandlers.onDataCollectorInstanceReady)
}
}
});
})
}

@@ -62,13 +62,13 @@ }

nextFieldId() {
this._nextFieldId += 1;
return this._nextFieldId;
this._nextFieldId += 1
return this._nextFieldId
}
onError(err) {
if (!err) { return; }
if (this.wrapperHandlers.onError) { this.wrapperHandlers.onError(err); }
if (!err) { return }
if (this.wrapperHandlers.onError) { this.wrapperHandlers.onError(err) }
}
create(client, onAuthorizationSuccess) {
this.client = client;
this.client = client
HostedFields.create({

@@ -80,4 +80,4 @@ client,

if (err) {
this.onError(err);
return;
this.onError(err)
return
}

@@ -89,17 +89,17 @@ this.hostedFields = hostedFields;

].forEach((eventName) => {
hostedFields.on(eventName, ev => this.onFieldEvent(`on${cap(eventName)}`, ev));
});
this.onError(err);
hostedFields.on(eventName, ev => this.onFieldEvent(`on${cap(eventName)}`, ev))
})
this.onError(err)
if (onAuthorizationSuccess) {
onAuthorizationSuccess();
onAuthorizationSuccess()
}
});
})
}
teardown() {
if (this.hostedFields) { this.hostedFields.teardown(); }
if (this.hostedFields) { this.hostedFields.teardown() }
if (this.pendingAuthTimer) {
clearTimeout(this.pendingAuthTimer);
this.pendingAuthTimer = null;
clearTimeout(this.pendingAuthTimer)
this.pendingAuthTimer = null
}

@@ -121,3 +121,3 @@ }

const onRenderComplete = () => {
this.fieldHandlers[type] = handlers;
this.fieldHandlers[type] = handlers
this.fields[type] = {

@@ -131,16 +131,16 @@ formatInput,

selector: `#${id}`,
};
}
if (('number' === type) && rejectUnsupportedCards) {
this.fields.number.rejectUnsupportedCards = true;
this.fields.number.rejectUnsupportedCards = true
}
};
return [id, onRenderComplete];
}
return [id, onRenderComplete]
}
focusField(fieldType, cb) {
this.hostedFields.focus(fieldType, cb);
this.hostedFields.focus(fieldType, cb)
}
clearField(fieldType, cb) {
this.hostedFields.clear(fieldType, cb);
this.hostedFields.clear(fieldType, cb)
}

@@ -153,12 +153,12 @@

value,
});
})
}
onFieldEvent(eventName, event) {
const fieldHandlers = this.fieldHandlers[event.emittedBy];
const fieldHandlers = this.fieldHandlers[event.emittedBy]
if (fieldHandlers && fieldHandlers[eventName]) {
fieldHandlers[eventName](event.fields[event.emittedBy], event);
fieldHandlers[eventName](event.fields[event.emittedBy], event)
}
if (this.wrapperHandlers[eventName]) {
this.wrapperHandlers[eventName](event);
this.wrapperHandlers[eventName](event)
}

@@ -168,14 +168,14 @@ }

tokenize(options = {}) {
return new Promise((resolve, reject) => {
return new Promise((resolve, reject) => { // eslint-disable-line no-undef
this.hostedFields.tokenize(options, (err, payload) => {
if (err) {
this.onError(err);
reject(err);
this.onError(err)
reject(err)
} else {
resolve(payload);
resolve(payload)
}
});
});
})
})
}
}

@@ -9,3 +9,3 @@ import React from 'react';

type: PropTypes.oneOf([
'number', 'expirationDate', 'expirationMonth', 'expirationYear', 'cvv', 'postalCode',
'number', 'expirationDate', 'expirationMonth', 'expirationYear', 'cvv', 'postalCode', 'cardholderName',
]).isRequired,

@@ -12,0 +12,0 @@ id: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),

@@ -1,3 +0,3 @@

import Braintree from './braintree.jsx';
import HostedField from './field.jsx';
import Braintree from './braintree.jsx'
import HostedField from './field.jsx'

@@ -7,2 +7,2 @@ export {

HostedField,
};
}
const webpack = require('webpack');
const path = require('path');

@@ -29,5 +28,2 @@ const config = {

],
node: {
fs: 'empty',
},
devServer: {

@@ -34,0 +30,0 @@ hot: false,

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc