Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
'use strict';
var EventEmitter = require('@braintree/event-emitter');
function EventedModel() {
EventEmitter.call(this);
this._attributes = this.resetAttributes();
}
EventEmitter.createChild(EventedModel);
EventedModel.prototype.get = function get(compoundKey) {
var i, key, keys;
var traversal = this._attributes;
if (compoundKey == null) { return traversal; }
keys = compoundKey.split('.');
for (i = 0; i < keys.length; i++) {
key = keys[i];
if (!traversal.hasOwnProperty(key)) {
return; // eslint-disable-line consistent-return
}
instance.teardown(function () {
methods(HostedFields.prototype).concat(methods(EventEmitter.prototype))
.forEach(function (method) {
var error;
try {
instance[method]();
} catch (err) {
error = err;
}
expect(error).to.be.an.instanceof(BraintreeError);
expect(error.type).to.equal(BraintreeError.types.MERCHANT);
expect(error.code).to.equal('METHOD_CALLED_AFTER_TEARDOWN');
expect(error.message).to.equal(method + ' cannot be called after teardown.');
});
done();
);
}
});
this._destructor.registerFunctionForTeardown(function () {
destroyFocusIntercept();
});
this._destructor.registerFunctionForTeardown(function () {
var methodNames = methods(HostedFields.prototype).concat(methods(EventEmitter.prototype));
convertMethodsToError(self, methodNames);
});
}
EventEmitter.createChild(HostedFields);
HostedFields.prototype._setupLabelFocus = function (type, container) {
var labels, i;
var shouldSkipLabelFocus = browserDetection.isIos();
var bus = this._bus;
if (shouldSkipLabelFocus) { return; }
if (container.id == null) { return; }
function triggerFocus() {
bus.emit(events.TRIGGER_INPUT_FOCUS, type);
}
labels = Array.prototype.slice.call(document.querySelectorAll('label[for="' + container.id + '"]'));
labels = labels.concat(findParentTags(container, 'label'));
function Dropin(options) {
this._client = options.client;
this._componentID = uuid();
this._dropinWrapper = document.createElement('div');
this._dropinWrapper.id = 'braintree--dropin__' + this._componentID;
this._dropinWrapper.setAttribute('data-braintree-id', 'wrapper');
this._dropinWrapper.style.display = 'none';
this._dropinWrapper.className = 'braintree-loading';
this._merchantConfiguration = options.merchantConfiguration;
EventEmitter.call(this);
}
debug: isDebug,
assetsUrl: assetsUrl,
name: 'Hosted Fields'
});
hostedFieldsUrl = composeUrl(assetsUrl, componentId, isDebug);
if (!options.fields || Object.keys(options.fields).length === 0) {
throw new BraintreeError({
type: sharedErrors.INSTANTIATION_OPTION_REQUIRED.type,
code: sharedErrors.INSTANTIATION_OPTION_REQUIRED.code,
message: 'options.fields is required when instantiating Hosted Fields.'
});
}
EventEmitter.call(this);
this._injectedNodes = [];
this._destructor = new Destructor();
this._fields = fields;
this._state = {
fields: {},
cards: getCardTypes('')
};
this._bus = new Bus({
channel: componentId,
merchantUrl: location.href
});
this._destructor.registerFunctionForTeardown(function () {
self._bus.teardown();
function PaymentRequestComponent(options) {
var enabledPaymentMethods = options.enabledPaymentMethods || {};
EventEmitter.call(this);
this._componentId = uuid();
this._client = options.client;
this._enabledPaymentMethods = {
basicCard: enabledPaymentMethods.basicCard !== false,
googlePay: enabledPaymentMethods.googlePay !== false
};
this._googlePayVersion = options.googlePayVersion === 2 ? 2 : 1;
this._googleMerchantId = BRAINTREE_GOOGLE_PAY_MERCHANT_ID;
this._supportedPaymentMethods = this._constructDefaultSupportedPaymentMethods();
this._defaultSupportedPaymentMethods = Object.keys(this._supportedPaymentMethods).map(function (key) {
return this._supportedPaymentMethods[key];
}.bind(this));
this._bus = new Bus({channel: this._componentId});
}
function DropinModel(options) {
this.componentID = options.componentID;
this.merchantConfiguration = options.merchantConfiguration;
this.isGuestCheckout = isGuestCheckout(options.client);
this.dependenciesInitializing = 0;
this.dependencySuccessCount = 0;
this.failedDependencies = {};
this._options = options;
this._setupComplete = false;
EventEmitter.call(this);
}
function EventedModel() {
EventEmitter.call(this);
this._attributes = this.resetAttributes();
}
function ThreeDSecure(options) {
var self = this;
var Framework = FRAMEWORKS[options.framework];
EventEmitter.call(this);
this._framework = new Framework(options);
this._framework.setUpEventListeners(function () {
self._emit.apply(self, arguments);
});
}
this._componentId = uuid();
this._client = options.client;
this._enabledPaymentMethods = {
basicCard: enabledPaymentMethods.basicCard !== false,
googlePay: enabledPaymentMethods.googlePay !== false
};
this._googlePayVersion = options.googlePayVersion === 2 ? 2 : 1;
this._googleMerchantId = BRAINTREE_GOOGLE_PAY_MERCHANT_ID;
this._supportedPaymentMethods = this._constructDefaultSupportedPaymentMethods();
this._defaultSupportedPaymentMethods = Object.keys(this._supportedPaymentMethods).map(function (key) {
return this._supportedPaymentMethods[key];
}.bind(this));
this._bus = new Bus({channel: this._componentId});
}
EventEmitter.createChild(PaymentRequestComponent);
PaymentRequestComponent.prototype._constructDefaultSupportedPaymentMethods = function () {
var configuration = this._client.getConfiguration();
var androidPayConfiguration = configuration.gatewayConfiguration.androidPay;
var cardConfiguration = configuration.gatewayConfiguration.creditCards;
var supportedPaymentMethods = {};
if (this._enabledPaymentMethods.basicCard && cardConfiguration && cardConfiguration.supportedCardTypes.length > 0) {
supportedPaymentMethods.basicCard = {
supportedMethods: 'basic-card',
data: {
supportedNetworks: cardConfiguration.supportedCardTypes.reduce(function (types, cardType) {
if (cardType in CARD_TYPE_MAPPINGS) {
types.push(CARD_TYPE_MAPPINGS[cardType]);
}