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.2.0 to 1.3.1

babel.config.js

642

dist/build.full.js
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('braintree-web/client'), require('braintree-web/hosted-fields'), require('braintree-web/data-collector'), require('react'), require('prop-types')) :
typeof define === 'function' && define.amd ? define(['exports', 'braintree-web/client', 'braintree-web/hosted-fields', 'braintree-web/data-collector', 'react', 'prop-types'], factory) :
(factory((global['react-braintree-fields'] = {}),global.Braintree,global.BraintreeHostedFields,global.BraintreeDataCollector,global.React,global.PropTypes));
}(this, (function (exports,Braintree,HostedFields,BraintreeDataCollector,React,PropTypes) { 'use strict';
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));
}(this, (function (exports, React, PropTypes, Braintree$1, HostedFields, BraintreeDataCollector) { 'use strict';
Braintree = Braintree && Braintree.hasOwnProperty('default') ? Braintree['default'] : Braintree;
HostedFields = HostedFields && HostedFields.hasOwnProperty('default') ? HostedFields['default'] : HostedFields;
BraintreeDataCollector = BraintreeDataCollector && BraintreeDataCollector.hasOwnProperty('default') ? BraintreeDataCollector['default'] : BraintreeDataCollector;
React = React && React.hasOwnProperty('default') ? React['default'] : React;
PropTypes = PropTypes && PropTypes.hasOwnProperty('default') ? PropTypes['default'] : PropTypes;
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;
var classCallCheck = function (instance, Constructor) {
if (!(instance instanceof Constructor)) {
throw new TypeError("Cannot call a class as a function");
function _objectWithoutPropertiesLoose(source, excluded) {
if (source == null) return {};
var target = {};
var sourceKeys = Object.keys(source);
var key, i;
for (i = 0; i < sourceKeys.length; i++) {
key = sourceKeys[i];
if (excluded.indexOf(key) >= 0) continue;
target[key] = source[key];
}
};
var createClass = function () {
function defineProperties(target, props) {
for (var i = 0; i < props.length; i++) {
var descriptor = props[i];
descriptor.enumerable = descriptor.enumerable || false;
descriptor.configurable = true;
if ("value" in descriptor) descriptor.writable = true;
Object.defineProperty(target, descriptor.key, descriptor);
return target;
}
function _objectWithoutProperties(source, excluded) {
if (source == null) return {};
var target = _objectWithoutPropertiesLoose(source, excluded);
var key, i;
if (Object.getOwnPropertySymbols) {
var sourceSymbolKeys = Object.getOwnPropertySymbols(source);
for (i = 0; i < sourceSymbolKeys.length; i++) {
key = sourceSymbolKeys[i];
if (excluded.indexOf(key) >= 0) continue;
if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue;
target[key] = source[key];
}
}
return function (Constructor, protoProps, staticProps) {
if (protoProps) defineProperties(Constructor.prototype, protoProps);
if (staticProps) defineProperties(Constructor, staticProps);
return Constructor;
};
}();
return target;
}
var inherits = function (subClass, superClass) {
if (typeof superClass !== "function" && superClass !== null) {
throw new TypeError("Super expression must either be null or a function, not " + typeof superClass);
function cap(string) {
return string.charAt(0).toUpperCase() + string.slice(1);
}
class BraintreeClientApi {
constructor(_ref) {
var {
authorization,
styles,
onAuthorizationSuccess
} = _ref,
callbacks = _objectWithoutProperties(_ref, ["authorization", "styles", "onAuthorizationSuccess"]);
this.fields = {};
this._nextFieldId = 0;
this.fieldHandlers = {};
this.styles = styles || {};
this.wrapperHandlers = callbacks || {};
this.setAuthorization(authorization, onAuthorizationSuccess);
}
subClass.prototype = Object.create(superClass && superClass.prototype, {
constructor: {
value: subClass,
enumerable: false,
writable: true,
configurable: true
setAuthorization(authorization, onAuthorizationSuccess) {
if (!authorization && this.authorization) {
this.teardown();
} else if (authorization && authorization !== this.authorization) {
if (this.authorization) {
this.teardown();
}
this.authorization = authorization;
Braintree$1.create({
authorization
}, (err, clientInstance) => {
if (err) {
this.onError(err);
} else {
this.create(clientInstance, onAuthorizationSuccess);
if (this.wrapperHandlers.onDataCollectorInstanceReady) {
BraintreeDataCollector.create({
client: clientInstance,
kount: true
}, this.wrapperHandlers.onDataCollectorInstanceReady);
}
}
});
}
});
if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass;
};
}
var objectWithoutProperties = function (obj, keys) {
var target = {};
nextFieldId() {
this._nextFieldId += 1;
return this._nextFieldId;
}
for (var i in obj) {
if (keys.indexOf(i) >= 0) continue;
if (!Object.prototype.hasOwnProperty.call(obj, i)) continue;
target[i] = obj[i];
onError(err) {
if (!err) {
return;
}
if (this.wrapperHandlers.onError) {
this.wrapperHandlers.onError(err);
}
}
return target;
};
create(client, onAuthorizationSuccess) {
this.client = client;
HostedFields.create({
client,
styles: this.styles,
fields: this.fields
}, (err, hostedFields) => {
if (err) {
this.onError(err);
return;
}
var possibleConstructorReturn = function (self, call) {
if (!self) {
throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
this.hostedFields = hostedFields;
['blur', 'focus', 'empty', 'notEmpty', 'cardTypeChange', 'validityChange'].forEach(eventName => {
hostedFields.on(eventName, ev => this.onFieldEvent("on".concat(cap(eventName)), ev));
});
this.onError(err);
if (onAuthorizationSuccess) {
onAuthorizationSuccess();
}
});
}
return call && (typeof call === "object" || typeof call === "function") ? call : self;
};
teardown() {
if (this.hostedFields) {
this.hostedFields.teardown();
}
}
function cap(string) {
return string.charAt(0).toUpperCase() + string.slice(1);
}
checkInField(_ref2) {
var {
formatInput,
maxlength,
minlength,
placeholder,
select,
type,
prefill,
id = "braintree-field-wrapper-".concat(this.nextFieldId()),
rejectUnsupportedCards
} = _ref2,
handlers = _objectWithoutProperties(_ref2, ["formatInput", "maxlength", "minlength", "placeholder", "select", "type", "prefill", "id", "rejectUnsupportedCards"]);
var BraintreeClientApi = function () {
function BraintreeClientApi(_ref) {
var authorization = _ref.authorization,
styles = _ref.styles,
onAuthorizationSuccess = _ref.onAuthorizationSuccess,
callbacks = objectWithoutProperties(_ref, ['authorization', 'styles', 'onAuthorizationSuccess']);
classCallCheck(this, BraintreeClientApi);
this.fields = {};
this._nextFieldId = 0;
this.fieldHandlers = {};
this.fieldHandlers[type] = handlers;
this.fields[type] = {
formatInput,
maxlength,
minlength,
placeholder,
select,
prefill,
selector: "#".concat(id)
};
this.styles = styles || {};
this.wrapperHandlers = callbacks || {};
this.setAuthorization(authorization, onAuthorizationSuccess);
if ('number' === type && rejectUnsupportedCards) {
this.fields.number.rejectUnsupportedCards = true;
}
createClass(BraintreeClientApi, [{
key: 'setAuthorization',
value: function setAuthorization(authorization, onAuthorizationSuccess) {
var _this = this;
return id;
}
if (!authorization && this.authorization) {
this.teardown();
} else if (authorization && authorization !== this.authorization) {
if (this.authorization) {
this.teardown();
}
this.authorization = authorization;
Braintree.create({ authorization: authorization }, function (err, clientInstance) {
if (err) {
_this.onError(err);
} else {
_this.create(clientInstance, onAuthorizationSuccess);
focusField(fieldType, cb) {
this.hostedFields.focus(fieldType, cb);
}
if (_this.wrapperHandlers.onDataCollectorInstanceReady) {
BraintreeDataCollector.create({
client: clientInstance,
kount: true
}, _this.wrapperHandlers.onDataCollectorInstanceReady);
}
}
});
}
}
}, {
key: 'nextFieldId',
value: function nextFieldId() {
this._nextFieldId += 1;
return this._nextFieldId;
}
}, {
key: 'onError',
value: function onError(err) {
if (!err) {
return;
}
if (this.wrapperHandlers.onError) {
this.wrapperHandlers.onError(err);
}
}
}, {
key: 'create',
value: function create(client, onAuthorizationSuccess) {
var _this2 = this;
clearField(fieldType, cb) {
this.hostedFields.clear(fieldType, cb);
}
this.client = client;
HostedFields.create({
client: client,
styles: this.styles,
fields: this.fields
}, function (err, hostedFields) {
if (err) {
_this2.onError(err);
return;
}
_this2.hostedFields = hostedFields;
['blur', 'focus', 'empty', 'notEmpty', 'cardTypeChange', 'validityChange'].forEach(function (eventName) {
hostedFields.on(eventName, function (ev) {
return _this2.onFieldEvent('on' + cap(eventName), ev);
});
});
_this2.onError(err);
setAttribute(fieldType, name, value) {
this.hostedFields.setAttribute({
field: fieldType,
attribute: name,
value
});
}
if (onAuthorizationSuccess) {
onAuthorizationSuccess();
}
});
}
}, {
key: 'teardown',
value: function teardown() {
if (this.hostedFields) {
this.hostedFields.teardown();
}
}
}, {
key: 'checkInField',
value: function checkInField(_ref2) {
var formatInput = _ref2.formatInput,
maxlength = _ref2.maxlength,
minlength = _ref2.minlength,
placeholder = _ref2.placeholder,
select = _ref2.select,
type = _ref2.type,
prefill = _ref2.prefill,
_ref2$id = _ref2.id,
id = _ref2$id === undefined ? 'braintree-field-wrapper-' + this.nextFieldId() : _ref2$id,
rejectUnsupportedCards = _ref2.rejectUnsupportedCards,
handlers = objectWithoutProperties(_ref2, ['formatInput', 'maxlength', 'minlength', 'placeholder', 'select', 'type', 'prefill', 'id', 'rejectUnsupportedCards']);
onFieldEvent(eventName, event) {
var fieldHandlers = this.fieldHandlers[event.emittedBy];
this.fieldHandlers[type] = handlers;
this.fields[type] = {
formatInput: formatInput,
maxlength: maxlength,
minlength: minlength,
placeholder: placeholder,
select: select,
prefill: prefill,
selector: '#' + id
};
if ('number' === type && rejectUnsupportedCards) {
this.fields.number.rejectUnsupportedCards = true;
}
return id;
}
}, {
key: 'focusField',
value: function focusField(fieldType, cb) {
this.hostedFields.focus(fieldType, cb);
}
}, {
key: 'clearField',
value: function clearField(fieldType, cb) {
this.hostedFields.clear(fieldType, cb);
}
}, {
key: 'setAttribute',
value: function setAttribute(fieldType, name, value) {
this.hostedFields.setAttribute({
field: fieldType,
attribute: name,
value: value
});
}
}, {
key: 'onFieldEvent',
value: function onFieldEvent(eventName, event) {
var fieldHandlers = this.fieldHandlers[event.emittedBy];
if (fieldHandlers && fieldHandlers[eventName]) {
fieldHandlers[eventName](event.fields[event.emittedBy], event);
}
if (this.wrapperHandlers[eventName]) {
this.wrapperHandlers[eventName](event);
}
}
}, {
key: 'tokenize',
value: function tokenize() {
var _this3 = this;
if (fieldHandlers && fieldHandlers[eventName]) {
fieldHandlers[eventName](event.fields[event.emittedBy], event);
}
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
if (this.wrapperHandlers[eventName]) {
this.wrapperHandlers[eventName](event);
}
}
return new Promise(function (resolve, reject) {
_this3.hostedFields.tokenize(options, function (err, payload) {
if (err) {
_this3.onError(err);
reject(err);
} else {
resolve(payload);
}
});
});
tokenize() {
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
return new Promise((resolve, reject) => {
this.hostedFields.tokenize(options, (err, payload) => {
if (err) {
this.onError(err);
reject(err);
} else {
resolve(payload);
}
}]);
return BraintreeClientApi;
}();
});
});
}
var _class, _temp;
}
var Braintree$1 = (_temp = _class = function (_React$Component) {
inherits(Braintree$$1, _React$Component);
class Braintree extends React.Component {
constructor(props) {
super(props);
this.api = new BraintreeClientApi(props);
}
function Braintree$$1(props) {
classCallCheck(this, Braintree$$1);
componentDidMount() {
this.api.setAuthorization(this.props.authorization, this.props.onAuthorizationSuccess);
var _this = possibleConstructorReturn(this, (Braintree$$1.__proto__ || Object.getPrototypeOf(Braintree$$1)).call(this, props));
if (this.props.getTokenRef) {
this.props.getTokenRef(this.api.tokenize.bind(this.api));
}
}
_this.api = new BraintreeClientApi(props);
return _this;
componentWillUnmount() {
this.api.teardown();
}
componentWillReceiveProps(nextProps) {
this.api.setAuthorization(nextProps.authorization, this.props.onAuthorizationSuccess);
}
tokenize(options) {
return this.api.tokenize(options);
}
getChildContext() {
return {
braintreeApi: this.api
};
}
render() {
var {
className: providedClass,
tagName: Tag
} = this.props;
var className = 'braintree-hosted-fields-wrapper';
if (providedClass) {
className += " ".concat(providedClass);
}
createClass(Braintree$$1, [{
key: 'componentDidMount',
value: function componentDidMount() {
this.api.setAuthorization(this.props.authorization, this.props.onAuthorizationSuccess);
if (this.props.getTokenRef) {
this.props.getTokenRef(this.api.tokenize.bind(this.api));
}
}
}, {
key: 'componentWillUnmount',
value: function componentWillUnmount() {
this.api.teardown();
}
}, {
key: 'componentWillReceiveProps',
value: function componentWillReceiveProps(nextProps) {
this.api.setAuthorization(nextProps.authorization, this.props.onAuthorizationSuccess);
}
}, {
key: 'tokenize',
value: function tokenize(options) {
return this.api.tokenize(options);
}
}, {
key: 'getChildContext',
value: function getChildContext() {
return { braintreeApi: this.api };
}
}, {
key: 'render',
value: function render() {
var _props = this.props,
providedClass = _props.className,
Tag = _props.tagName;
return React.createElement(Tag, {
className: className
}, this.props.children);
}
var className = 'braintree-hosted-fields-wrapper';
if (providedClass) {
className += ' ' + providedClass;
}
return React.createElement(
Tag,
{ className: className },
this.props.children
);
}
}]);
return Braintree$$1;
}(React.Component), _class.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
}, _class.defaultProps = {
tagName: 'div'
}, _class.childContextTypes = {
braintreeApi: PropTypes.instanceOf(BraintreeClientApi)
}, _temp);
}
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
};
Braintree.defaultProps = {
tagName: 'div'
};
Braintree.childContextTypes = {
braintreeApi: PropTypes.instanceOf(BraintreeClientApi)
};
var _class$1, _temp$1;
class BraintreeHostedField extends React.Component {
focus() {
this.context.braintreeApi.focusField(this.props.type);
}
var BraintreeHostedField = (_temp$1 = _class$1 = function (_React$Component) {
inherits(BraintreeHostedField, _React$Component);
clear() {
this.context.braintreeApi.clearField(this.props.type);
}
function BraintreeHostedField() {
classCallCheck(this, BraintreeHostedField);
return possibleConstructorReturn(this, (BraintreeHostedField.__proto__ || Object.getPrototypeOf(BraintreeHostedField)).apply(this, arguments));
setPlaceholder(text) {
this.context.braintreeApi.setAttribute(this.props.type, 'placeholder', text);
}
componentWillMount() {
this.fieldId = this.context.braintreeApi.checkInField(this.props);
}
get className() {
var list = ['braintree-hosted-field'];
if (this.props.className) {
list.push(this.props.className);
}
createClass(BraintreeHostedField, [{
key: 'focus',
value: function focus() {
this.context.braintreeApi.focusField(this.props.type);
}
}, {
key: 'clear',
value: function clear() {
this.context.braintreeApi.clearField(this.props.type);
}
}, {
key: 'setPlaceholder',
value: function setPlaceholder(text) {
this.context.braintreeApi.setAttribute(this.props.type, 'placeholder', text);
}
}, {
key: 'componentWillMount',
value: function componentWillMount() {
this.fieldId = this.context.braintreeApi.checkInField(this.props);
}
}, {
key: 'render',
value: function render() {
return React.createElement('div', { id: this.fieldId, className: this.className });
}
}, {
key: 'className',
get: function get$$1() {
var list = ['braintree-hosted-field'];
if (this.props.className) {
list.push(this.props.className);
}
return list.join(' ');
}
}]);
return BraintreeHostedField;
}(React.Component), _class$1.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
}, _class$1.contextTypes = {
braintreeApi: PropTypes.instanceOf(BraintreeClientApi)
}, _temp$1);
return list.join(' ');
}
exports.Braintree = Braintree$1;
render() {
return React.createElement("div", {
id: this.fieldId,
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
};
BraintreeHostedField.contextTypes = {
braintreeApi: PropTypes.instanceOf(BraintreeClientApi)
};
exports.Braintree = Braintree;
exports.HostedField = BraintreeHostedField;

@@ -400,1 +345,2 @@

})));
//# sourceMappingURL=build.full.js.map

@@ -1,388 +0,334 @@

import Braintree from 'braintree-web/client';
import React from 'react';
import PropTypes from 'prop-types';
import Braintree$1 from 'braintree-web/client';
import HostedFields from 'braintree-web/hosted-fields';
import BraintreeDataCollector from 'braintree-web/data-collector';
import React from 'react';
import PropTypes from 'prop-types';
var classCallCheck = function (instance, Constructor) {
if (!(instance instanceof Constructor)) {
throw new TypeError("Cannot call a class as a function");
function _objectWithoutPropertiesLoose(source, excluded) {
if (source == null) return {};
var target = {};
var sourceKeys = Object.keys(source);
var key, i;
for (i = 0; i < sourceKeys.length; i++) {
key = sourceKeys[i];
if (excluded.indexOf(key) >= 0) continue;
target[key] = source[key];
}
};
var createClass = function () {
function defineProperties(target, props) {
for (var i = 0; i < props.length; i++) {
var descriptor = props[i];
descriptor.enumerable = descriptor.enumerable || false;
descriptor.configurable = true;
if ("value" in descriptor) descriptor.writable = true;
Object.defineProperty(target, descriptor.key, descriptor);
return target;
}
function _objectWithoutProperties(source, excluded) {
if (source == null) return {};
var target = _objectWithoutPropertiesLoose(source, excluded);
var key, i;
if (Object.getOwnPropertySymbols) {
var sourceSymbolKeys = Object.getOwnPropertySymbols(source);
for (i = 0; i < sourceSymbolKeys.length; i++) {
key = sourceSymbolKeys[i];
if (excluded.indexOf(key) >= 0) continue;
if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue;
target[key] = source[key];
}
}
return function (Constructor, protoProps, staticProps) {
if (protoProps) defineProperties(Constructor.prototype, protoProps);
if (staticProps) defineProperties(Constructor, staticProps);
return Constructor;
};
}();
return target;
}
var inherits = function (subClass, superClass) {
if (typeof superClass !== "function" && superClass !== null) {
throw new TypeError("Super expression must either be null or a function, not " + typeof superClass);
function cap(string) {
return string.charAt(0).toUpperCase() + string.slice(1);
}
class BraintreeClientApi {
constructor(_ref) {
var {
authorization,
styles,
onAuthorizationSuccess
} = _ref,
callbacks = _objectWithoutProperties(_ref, ["authorization", "styles", "onAuthorizationSuccess"]);
this.fields = {};
this._nextFieldId = 0;
this.fieldHandlers = {};
this.styles = styles || {};
this.wrapperHandlers = callbacks || {};
this.setAuthorization(authorization, onAuthorizationSuccess);
}
subClass.prototype = Object.create(superClass && superClass.prototype, {
constructor: {
value: subClass,
enumerable: false,
writable: true,
configurable: true
setAuthorization(authorization, onAuthorizationSuccess) {
if (!authorization && this.authorization) {
this.teardown();
} else if (authorization && authorization !== this.authorization) {
if (this.authorization) {
this.teardown();
}
this.authorization = authorization;
Braintree$1.create({
authorization
}, (err, clientInstance) => {
if (err) {
this.onError(err);
} else {
this.create(clientInstance, onAuthorizationSuccess);
if (this.wrapperHandlers.onDataCollectorInstanceReady) {
BraintreeDataCollector.create({
client: clientInstance,
kount: true
}, this.wrapperHandlers.onDataCollectorInstanceReady);
}
}
});
}
});
if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass;
};
}
var objectWithoutProperties = function (obj, keys) {
var target = {};
nextFieldId() {
this._nextFieldId += 1;
return this._nextFieldId;
}
for (var i in obj) {
if (keys.indexOf(i) >= 0) continue;
if (!Object.prototype.hasOwnProperty.call(obj, i)) continue;
target[i] = obj[i];
onError(err) {
if (!err) {
return;
}
if (this.wrapperHandlers.onError) {
this.wrapperHandlers.onError(err);
}
}
return target;
};
create(client, onAuthorizationSuccess) {
this.client = client;
HostedFields.create({
client,
styles: this.styles,
fields: this.fields
}, (err, hostedFields) => {
if (err) {
this.onError(err);
return;
}
var possibleConstructorReturn = function (self, call) {
if (!self) {
throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
this.hostedFields = hostedFields;
['blur', 'focus', 'empty', 'notEmpty', 'cardTypeChange', 'validityChange'].forEach(eventName => {
hostedFields.on(eventName, ev => this.onFieldEvent("on".concat(cap(eventName)), ev));
});
this.onError(err);
if (onAuthorizationSuccess) {
onAuthorizationSuccess();
}
});
}
return call && (typeof call === "object" || typeof call === "function") ? call : self;
};
teardown() {
if (this.hostedFields) {
this.hostedFields.teardown();
}
}
function cap(string) {
return string.charAt(0).toUpperCase() + string.slice(1);
}
checkInField(_ref2) {
var {
formatInput,
maxlength,
minlength,
placeholder,
select,
type,
prefill,
id = "braintree-field-wrapper-".concat(this.nextFieldId()),
rejectUnsupportedCards
} = _ref2,
handlers = _objectWithoutProperties(_ref2, ["formatInput", "maxlength", "minlength", "placeholder", "select", "type", "prefill", "id", "rejectUnsupportedCards"]);
var BraintreeClientApi = function () {
function BraintreeClientApi(_ref) {
var authorization = _ref.authorization,
styles = _ref.styles,
onAuthorizationSuccess = _ref.onAuthorizationSuccess,
callbacks = objectWithoutProperties(_ref, ['authorization', 'styles', 'onAuthorizationSuccess']);
classCallCheck(this, BraintreeClientApi);
this.fields = {};
this._nextFieldId = 0;
this.fieldHandlers = {};
this.fieldHandlers[type] = handlers;
this.fields[type] = {
formatInput,
maxlength,
minlength,
placeholder,
select,
prefill,
selector: "#".concat(id)
};
this.styles = styles || {};
this.wrapperHandlers = callbacks || {};
this.setAuthorization(authorization, onAuthorizationSuccess);
if ('number' === type && rejectUnsupportedCards) {
this.fields.number.rejectUnsupportedCards = true;
}
createClass(BraintreeClientApi, [{
key: 'setAuthorization',
value: function setAuthorization(authorization, onAuthorizationSuccess) {
var _this = this;
return id;
}
if (!authorization && this.authorization) {
this.teardown();
} else if (authorization && authorization !== this.authorization) {
if (this.authorization) {
this.teardown();
}
this.authorization = authorization;
Braintree.create({ authorization: authorization }, function (err, clientInstance) {
if (err) {
_this.onError(err);
} else {
_this.create(clientInstance, onAuthorizationSuccess);
focusField(fieldType, cb) {
this.hostedFields.focus(fieldType, cb);
}
if (_this.wrapperHandlers.onDataCollectorInstanceReady) {
BraintreeDataCollector.create({
client: clientInstance,
kount: true
}, _this.wrapperHandlers.onDataCollectorInstanceReady);
}
}
});
}
}
}, {
key: 'nextFieldId',
value: function nextFieldId() {
this._nextFieldId += 1;
return this._nextFieldId;
}
}, {
key: 'onError',
value: function onError(err) {
if (!err) {
return;
}
if (this.wrapperHandlers.onError) {
this.wrapperHandlers.onError(err);
}
}
}, {
key: 'create',
value: function create(client, onAuthorizationSuccess) {
var _this2 = this;
clearField(fieldType, cb) {
this.hostedFields.clear(fieldType, cb);
}
this.client = client;
HostedFields.create({
client: client,
styles: this.styles,
fields: this.fields
}, function (err, hostedFields) {
if (err) {
_this2.onError(err);
return;
}
_this2.hostedFields = hostedFields;
['blur', 'focus', 'empty', 'notEmpty', 'cardTypeChange', 'validityChange'].forEach(function (eventName) {
hostedFields.on(eventName, function (ev) {
return _this2.onFieldEvent('on' + cap(eventName), ev);
});
});
_this2.onError(err);
setAttribute(fieldType, name, value) {
this.hostedFields.setAttribute({
field: fieldType,
attribute: name,
value
});
}
if (onAuthorizationSuccess) {
onAuthorizationSuccess();
}
});
}
}, {
key: 'teardown',
value: function teardown() {
if (this.hostedFields) {
this.hostedFields.teardown();
}
}
}, {
key: 'checkInField',
value: function checkInField(_ref2) {
var formatInput = _ref2.formatInput,
maxlength = _ref2.maxlength,
minlength = _ref2.minlength,
placeholder = _ref2.placeholder,
select = _ref2.select,
type = _ref2.type,
prefill = _ref2.prefill,
_ref2$id = _ref2.id,
id = _ref2$id === undefined ? 'braintree-field-wrapper-' + this.nextFieldId() : _ref2$id,
rejectUnsupportedCards = _ref2.rejectUnsupportedCards,
handlers = objectWithoutProperties(_ref2, ['formatInput', 'maxlength', 'minlength', 'placeholder', 'select', 'type', 'prefill', 'id', 'rejectUnsupportedCards']);
onFieldEvent(eventName, event) {
var fieldHandlers = this.fieldHandlers[event.emittedBy];
this.fieldHandlers[type] = handlers;
this.fields[type] = {
formatInput: formatInput,
maxlength: maxlength,
minlength: minlength,
placeholder: placeholder,
select: select,
prefill: prefill,
selector: '#' + id
};
if ('number' === type && rejectUnsupportedCards) {
this.fields.number.rejectUnsupportedCards = true;
}
return id;
}
}, {
key: 'focusField',
value: function focusField(fieldType, cb) {
this.hostedFields.focus(fieldType, cb);
}
}, {
key: 'clearField',
value: function clearField(fieldType, cb) {
this.hostedFields.clear(fieldType, cb);
}
}, {
key: 'setAttribute',
value: function setAttribute(fieldType, name, value) {
this.hostedFields.setAttribute({
field: fieldType,
attribute: name,
value: value
});
}
}, {
key: 'onFieldEvent',
value: function onFieldEvent(eventName, event) {
var fieldHandlers = this.fieldHandlers[event.emittedBy];
if (fieldHandlers && fieldHandlers[eventName]) {
fieldHandlers[eventName](event.fields[event.emittedBy], event);
}
if (this.wrapperHandlers[eventName]) {
this.wrapperHandlers[eventName](event);
}
}
}, {
key: 'tokenize',
value: function tokenize() {
var _this3 = this;
if (fieldHandlers && fieldHandlers[eventName]) {
fieldHandlers[eventName](event.fields[event.emittedBy], event);
}
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
if (this.wrapperHandlers[eventName]) {
this.wrapperHandlers[eventName](event);
}
}
return new Promise(function (resolve, reject) {
_this3.hostedFields.tokenize(options, function (err, payload) {
if (err) {
_this3.onError(err);
reject(err);
} else {
resolve(payload);
}
});
});
tokenize() {
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
return new Promise((resolve, reject) => {
this.hostedFields.tokenize(options, (err, payload) => {
if (err) {
this.onError(err);
reject(err);
} else {
resolve(payload);
}
}]);
return BraintreeClientApi;
}();
});
});
}
var _class, _temp;
}
var Braintree$1 = (_temp = _class = function (_React$Component) {
inherits(Braintree$$1, _React$Component);
class Braintree extends React.Component {
constructor(props) {
super(props);
this.api = new BraintreeClientApi(props);
}
function Braintree$$1(props) {
classCallCheck(this, Braintree$$1);
componentDidMount() {
this.api.setAuthorization(this.props.authorization, this.props.onAuthorizationSuccess);
var _this = possibleConstructorReturn(this, (Braintree$$1.__proto__ || Object.getPrototypeOf(Braintree$$1)).call(this, props));
if (this.props.getTokenRef) {
this.props.getTokenRef(this.api.tokenize.bind(this.api));
}
}
_this.api = new BraintreeClientApi(props);
return _this;
componentWillUnmount() {
this.api.teardown();
}
componentWillReceiveProps(nextProps) {
this.api.setAuthorization(nextProps.authorization, this.props.onAuthorizationSuccess);
}
tokenize(options) {
return this.api.tokenize(options);
}
getChildContext() {
return {
braintreeApi: this.api
};
}
render() {
var {
className: providedClass,
tagName: Tag
} = this.props;
var className = 'braintree-hosted-fields-wrapper';
if (providedClass) {
className += " ".concat(providedClass);
}
createClass(Braintree$$1, [{
key: 'componentDidMount',
value: function componentDidMount() {
this.api.setAuthorization(this.props.authorization, this.props.onAuthorizationSuccess);
if (this.props.getTokenRef) {
this.props.getTokenRef(this.api.tokenize.bind(this.api));
}
}
}, {
key: 'componentWillUnmount',
value: function componentWillUnmount() {
this.api.teardown();
}
}, {
key: 'componentWillReceiveProps',
value: function componentWillReceiveProps(nextProps) {
this.api.setAuthorization(nextProps.authorization, this.props.onAuthorizationSuccess);
}
}, {
key: 'tokenize',
value: function tokenize(options) {
return this.api.tokenize(options);
}
}, {
key: 'getChildContext',
value: function getChildContext() {
return { braintreeApi: this.api };
}
}, {
key: 'render',
value: function render() {
var _props = this.props,
providedClass = _props.className,
Tag = _props.tagName;
return React.createElement(Tag, {
className: className
}, this.props.children);
}
var className = 'braintree-hosted-fields-wrapper';
if (providedClass) {
className += ' ' + providedClass;
}
return React.createElement(
Tag,
{ className: className },
this.props.children
);
}
}]);
return Braintree$$1;
}(React.Component), _class.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
}, _class.defaultProps = {
tagName: 'div'
}, _class.childContextTypes = {
braintreeApi: PropTypes.instanceOf(BraintreeClientApi)
}, _temp);
}
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
};
Braintree.defaultProps = {
tagName: 'div'
};
Braintree.childContextTypes = {
braintreeApi: PropTypes.instanceOf(BraintreeClientApi)
};
var _class$1, _temp$1;
class BraintreeHostedField extends React.Component {
focus() {
this.context.braintreeApi.focusField(this.props.type);
}
var BraintreeHostedField = (_temp$1 = _class$1 = function (_React$Component) {
inherits(BraintreeHostedField, _React$Component);
clear() {
this.context.braintreeApi.clearField(this.props.type);
}
function BraintreeHostedField() {
classCallCheck(this, BraintreeHostedField);
return possibleConstructorReturn(this, (BraintreeHostedField.__proto__ || Object.getPrototypeOf(BraintreeHostedField)).apply(this, arguments));
setPlaceholder(text) {
this.context.braintreeApi.setAttribute(this.props.type, 'placeholder', text);
}
componentWillMount() {
this.fieldId = this.context.braintreeApi.checkInField(this.props);
}
get className() {
var list = ['braintree-hosted-field'];
if (this.props.className) {
list.push(this.props.className);
}
createClass(BraintreeHostedField, [{
key: 'focus',
value: function focus() {
this.context.braintreeApi.focusField(this.props.type);
}
}, {
key: 'clear',
value: function clear() {
this.context.braintreeApi.clearField(this.props.type);
}
}, {
key: 'setPlaceholder',
value: function setPlaceholder(text) {
this.context.braintreeApi.setAttribute(this.props.type, 'placeholder', text);
}
}, {
key: 'componentWillMount',
value: function componentWillMount() {
this.fieldId = this.context.braintreeApi.checkInField(this.props);
}
}, {
key: 'render',
value: function render() {
return React.createElement('div', { id: this.fieldId, className: this.className });
}
}, {
key: 'className',
get: function get$$1() {
var list = ['braintree-hosted-field'];
if (this.props.className) {
list.push(this.props.className);
}
return list.join(' ');
}
}]);
return BraintreeHostedField;
}(React.Component), _class$1.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
}, _class$1.contextTypes = {
braintreeApi: PropTypes.instanceOf(BraintreeClientApi)
}, _temp$1);
return list.join(' ');
}
export { Braintree$1 as Braintree, BraintreeHostedField as HostedField };
render() {
return React.createElement("div", {
id: this.fieldId,
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
};
BraintreeHostedField.contextTypes = {
braintreeApi: PropTypes.instanceOf(BraintreeClientApi)
};
export { Braintree, BraintreeHostedField as HostedField };
//# sourceMappingURL=build.module.js.map
{
"name": "react-braintree-fields",
"version": "1.2.0",
"version": "1.3.1",
"description": "React component for braintree hosted fields",

@@ -13,8 +13,9 @@ "browser": "dist/build.full.js",

"peerDependencies": {
"prop-types": "^15.0",
"react": "^15.0 || ^16.0"
"prop-types": "^15.7",
"react": "^16.13"
},
"scripts": {
"test": "$(npm bin)/jest",
"test": "jest",
"build": "./script/build",
"demo": "$(npm bin)/webpack-dev-server",
"ci": "./script/cibuild",

@@ -29,46 +30,30 @@ "preversion": "./script/preversion"

"devDependencies": {
"babel": "^6.23.0",
"babel-core": "^6.26.3",
"babel-eslint": "^8.2.3",
"babel-loader": "^7.1.4",
"babel-plugin-external-helpers": "^6.22.0",
"babel-plugin-transform-class-properties": "^6.24.1",
"babel-plugin-transform-decorators-legacy": "^1.3.4",
"babel-plugin-transform-function-bind": "^6.22.0",
"babel-plugin-transform-object-rest-spread": "^6.26.0",
"babel-plugin-transform-react-jsx": "^6.24.1",
"babel-preset-es2015": "^6.24.1",
"babel-preset-es2015-rollup": "^3.0.0",
"babel-preset-react": "^6.24.1",
"babel-preset-stage-1": "^6.24.1",
"@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.0.0-bridge.0",
"babel-loader": "^8.0.6",
"babelrc-rollup": "^3.0.0",
"enzyme": "^3.3.0",
"enzyme-adapter-react-16": "^1.1.1",
"eslint": "^4.19.1",
"eslint-config-argosity": "^1.6.0",
"eslint-plugin-react": "^7.7.0",
"jest": "^22.4.3",
"jest-cli": "^22.4.3",
"prop-types": "^15.6",
"raf": "^3.4.0",
"react": "^16.3.2",
"react-dom": "^16.3.2",
"react-test-renderer": "^16.3.2",
"rollup": "^0.58.2",
"rollup-plugin-babel": "^3.0.4",
"webpack": "^4.30.0",
"webpack-cli": "^3.3.2",
"webpack-dev-server": "^3.1.4"
"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",
"prop-types": "^15.7.2",
"raf": "^3.4.1",
"react": "^16.13.0",
"react-dom": "^16.13.0",
"react-test-renderer": "^16.13.0",
"rollup": "^2.0.6",
"rollup-plugin-babel": "^4.4.0",
"webpack": "^4.42.0",
"webpack-cli": "^3.3.11",
"webpack-dev-server": "^3.10.3"
},
"dependencies": {
"braintree-web": "^3.33.0"
},
"jest": {
"testEnvironment": "jsdom",
"testURL": "http://localhost/",
"setupFiles": [
"raf/polyfill"
],
"setupTestFrameworkScriptFile": "./specs/setupTests.js"
"braintree-web": "^3.59.0"
}
}

@@ -41,3 +41,3 @@ # React components to integrate Braintree hosted fields

}
onDataCollectorInstanceReady(err, dataCollectorInstance) {

@@ -80,3 +80,3 @@ if(!err) this.device_data = dataCollectorInstance.deviceData

See [demo site](https://nathanstitt.github.io/react-braintree-fields/) for a working example. It renders [demo.jsx](demo.jsx)
See [demo site](https://nathanstitt.github.io/react-braintree-fields/) for a working example. It renders [demo/demo-class.jsx](demo/demo-class.jsx) There's also a [functional version](demo/demo-functional.jsx) available that illustrates how to work around the issue of storing a function reference using setState that was discovered in [issue #20](https://github.com/nathanstitt/react-braintree-fields/issues/20)

@@ -83,0 +83,0 @@ ## Braintree Component

@@ -8,12 +8,3 @@ import babel from 'rollup-plugin-babel';

const plugins = [
babel({
babelrc: true,
exclude: 'node_modules/**',
presets: [['es2015', { modules: false }], 'react', 'es2015-rollup'],
plugins: [
'transform-decorators-legacy',
'transform-class-properties',
'transform-object-rest-spread',
],
}),
babel(),
];

@@ -40,3 +31,3 @@

name: 'react-braintree-fields',
sourceMap: true,
sourcemap: true,
file: pkg.browser,

@@ -51,3 +42,3 @@ globals,

format: 'es',
sourceMap: true,
sourcemap: true,
file: pkg.module,

@@ -54,0 +45,0 @@ globals,

@@ -7,3 +7,3 @@ const webpack = require('webpack');

entry: {
demo: __dirname + '/demo.jsx',
demo: __dirname + '/demo/index.js',
},

@@ -21,14 +21,2 @@ output: {

exclude: /node_modules/,
options: {
plugins: [
'babel-plugin-transform-class-properties',
'babel-plugin-transform-function-bind',
'babel-plugin-transform-react-jsx',
].map(require.resolve),
presets: [
[require.resolve('babel-preset-es2015'), { modules: false }],
require.resolve('babel-preset-react'),
require.resolve('babel-preset-stage-1'),
],
},
},

@@ -35,0 +23,0 @@ ],

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

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