diff --git a/target/braintree-1.3.10.js b/target/braintree-1.3.10.js index ac6fca9..afe7d3c 100644 --- a/target/braintree-1.3.10.js +++ b/target/braintree-1.3.10.js @@ -14,14 +14,16 @@ * Licensed under the ISC License. * http://opensource.org/licenses/ISC */ + (function () { + // ASN.1 JavaScript decoder // Copyright (c) 2008-2009 Lapo Luchini // Permission to use, copy, modify, and/or distribute this software for any // purpose with or without fee is hereby granted, provided that the above // copyright notice and this permission notice appear in all copies. -// +// // THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES // WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF // MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR @@ -380,6 +382,7 @@ ASN1.decode = function(stream) { stream.pos += len; // skip content return new ASN1(streamStart, header, len, tag, sub); } + var b64map="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; var b64padchar="="; @@ -452,6 +455,7 @@ function b64toBA(s) { } return a; } + // Copyright (c) 2005 Tom Wu // All Rights Reserved. // See "LICENSE" for details. @@ -1011,6 +1015,7 @@ BigInteger.prototype.modPowInt = bnModPowInt; // "constants" BigInteger.ZERO = nbv(0); BigInteger.ONE = nbv(1); + // Depends on jsbn.js and rng.js // Version 1.1: support utf-8 encoding in pkcs1pad2 @@ -1129,6 +1134,7 @@ RSAKey.prototype.doPublic = RSADoPublic; RSAKey.prototype.setPublic = RSASetPublic; RSAKey.prototype.encrypt = RSAEncrypt; //RSAKey.prototype.encrypt_b64 = RSAEncryptB64; + /** @fileOverview Javascript cryptography implementation. * * Crush to remove comments, shorten variable names and @@ -1153,13 +1159,13 @@ var sjcl = { /** @namespace Key exchange functions. Right now only SRP is implemented. */ keyexchange: {}, - + /** @namespace Block cipher modes of operation. */ mode: {}, /** @namespace Miscellaneous. HMAC and PBKDF2. */ misc: {}, - + /** * @namespace Bit array encoders and decoders. * @@ -1170,7 +1176,7 @@ var sjcl = { * the method names are "fromBits" and "toBits". */ codec: {}, - + /** @namespace Exceptions. */ exception: { /** @class Ciphertext is corrupt. */ @@ -1178,13 +1184,13 @@ var sjcl = { this.toString = function() { return "CORRUPT: "+this.message; }; this.message = message; }, - + /** @class Invalid parameter. */ invalid: function(message) { this.toString = function() { return "INVALID: "+this.message; }; this.message = message; }, - + /** @class Bug or missing feature in SJCL. */ bug: function(message) { this.toString = function() { return "BUG: "+this.message; }; @@ -1202,6 +1208,7 @@ var sjcl = { if(typeof module != 'undefined' && module.exports){ module.exports = sjcl; } + /** @fileOverview Low-level AES implementation. * * This file contains a low-level implementation of AES, optimized for @@ -1232,36 +1239,36 @@ sjcl.cipher.aes = function (key) { if (!this._tables[0][0][0]) { this._precompute(); } - + var i, j, tmp, encKey, decKey, sbox = this._tables[0][4], decTable = this._tables[1], keyLen = key.length, rcon = 1; - + if (keyLen !== 4 && keyLen !== 6 && keyLen !== 8) { throw new sjcl.exception.invalid("invalid aes key size"); } - + this._key = [encKey = key.slice(0), decKey = []]; - + // schedule encryption keys for (i = keyLen; i < 4 * keyLen + 28; i++) { tmp = encKey[i-1]; - + // apply sbox if (i%keyLen === 0 || (keyLen === 8 && i%keyLen === 4)) { tmp = sbox[tmp>>>24]<<24 ^ sbox[tmp>>16&255]<<16 ^ sbox[tmp>>8&255]<<8 ^ sbox[tmp&255]; - + // shift rows and add rcon if (i%keyLen === 0) { tmp = tmp<<8 ^ tmp>>>24 ^ rcon<<24; rcon = rcon<<1 ^ (rcon>>7)*283; } } - + encKey[i] = encKey[i-keyLen] ^ tmp; } - + // schedule decryption keys for (j = 0; i; j++, i--) { tmp = encKey[j&3 ? i : i - 4]; @@ -1283,21 +1290,21 @@ sjcl.cipher.aes.prototype = { blockSize: 4, keySizes: [4,6,8], */ - + /** * Encrypt an array of 4 big-endian words. * @param {Array} data The plaintext. * @return {Array} The ciphertext. */ encrypt:function (data) { return this._crypt(data,0); }, - + /** * Decrypt an array of 4 big-endian words. * @param {Array} data The ciphertext. * @return {Array} The plaintext. */ decrypt:function (data) { return this._crypt(data,1); }, - + /** * The expanded S-box and inverse S-box tables. These will be computed * on the client so that we don't have to send them down the wire. @@ -1326,32 +1333,32 @@ sjcl.cipher.aes.prototype = { for (i = 0; i < 256; i++) { th[( d[i] = i<<1 ^ (i>>7)*283 )^i]=i; } - + for (x = xInv = 0; !sbox[x]; x ^= x2 || 1, xInv = th[xInv] || 1) { // Compute sbox s = xInv ^ xInv<<1 ^ xInv<<2 ^ xInv<<3 ^ xInv<<4; s = s>>8 ^ s&255 ^ 99; sbox[x] = s; sboxInv[s] = x; - + // Compute MixColumns x8 = d[x4 = d[x2 = d[x]]]; tDec = x8*0x1010101 ^ x4*0x10001 ^ x2*0x101 ^ x*0x1010100; tEnc = d[s]*0x101 ^ s*0x1010100; - + for (i = 0; i < 4; i++) { encTable[i][x] = tEnc = tEnc<<24 ^ tEnc>>>8; decTable[i][s] = tDec = tDec<<24 ^ tDec>>>8; } } - + // Compactify. Considerable speedup on Firefox. for (i = 0; i < 5; i++) { encTable[i] = encTable[i].slice(0); decTable[i] = decTable[i].slice(0); } }, - + /** * Encryption and decryption core. * @param {Array} input Four words to be encrypted or decrypted. @@ -1363,7 +1370,7 @@ sjcl.cipher.aes.prototype = { if (input.length !== 4) { throw new sjcl.exception.invalid("invalid aes block size"); } - + var key = this._key[dir], // state variables a,b,c,d are loaded with pre-whitened data a = input[0] ^ key[0], @@ -1371,20 +1378,20 @@ sjcl.cipher.aes.prototype = { c = input[2] ^ key[2], d = input[dir ? 1 : 3] ^ key[3], a2, b2, c2, - + nInnerRounds = key.length/4 - 2, i, kIndex = 4, out = [0,0,0,0], table = this._tables[dir], - + // load up the tables t0 = table[0], t1 = table[1], t2 = table[2], t3 = table[3], sbox = table[4]; - + // Inner rounds. Cribbed from OpenSSL. for (i = 0; i < nInnerRounds; i++) { a2 = t0[a>>>24] ^ t1[b>>16 & 255] ^ t2[c>>8 & 255] ^ t3[d & 255] ^ key[kIndex]; @@ -1394,22 +1401,23 @@ sjcl.cipher.aes.prototype = { kIndex += 4; a=a2; b=b2; c=c2; } - + // Last round. for (i = 0; i < 4; i++) { out[dir ? 3&-i : i] = - sbox[a>>>24 ]<<24 ^ + sbox[a>>>24 ]<<24 ^ sbox[b>>16 & 255]<<16 ^ sbox[c>>8 & 255]<<8 ^ sbox[d & 255] ^ key[kIndex++]; a2=a; a=b; b=c; c=d; d=a2; } - + return out; } }; + /** @fileOverview Arrays of bits, encoded as arrays of Numbers. * * @author Emily Stark @@ -1485,7 +1493,7 @@ sjcl.bitArray = { if (a1.length === 0 || a2.length === 0) { return a1.concat(a2); } - + var out, i, last = a1[a1.length-1], shift = sjcl.bitArray.getPartial(last); if (shift === 32) { return a1.concat(a2); @@ -1571,7 +1579,7 @@ sjcl.bitArray = { _shiftRight: function (a, shift, carry, out) { var i, last2=0, shift2; if (out === undefined) { out = []; } - + for (; shift >= 32; shift -= 32) { out.push(carry); carry = 0; @@ -1579,7 +1587,7 @@ sjcl.bitArray = { if (shift === 0) { return out.concat(a); } - + for (i=0; i>>shift); carry = a[i] << (32-shift); @@ -1589,7 +1597,7 @@ sjcl.bitArray = { out.push(sjcl.bitArray.partial(shift+shift2 & 31, (shift + shift2 > 32) ? carry : out.pop(),1)); return out; }, - + /** xor a block of 4 words together. * @private */ @@ -1597,6 +1605,7 @@ sjcl.bitArray = { return [x[0]^y[0],x[1]^y[1],x[2]^y[2],x[3]^y[3]]; } }; + /** @fileOverview Bit array codec implementations. * * @author Emily Stark @@ -1627,13 +1636,14 @@ sjcl.codec.hex = { } }; + /** @fileOverview Bit array codec implementations. * * @author Emily Stark * @author Mike Hamburg * @author Dan Boneh */ - + /** @namespace UTF-8 strings */ sjcl.codec.utf8String = { /** Convert from a bitArray to a UTF-8 string. */ @@ -1648,7 +1658,7 @@ sjcl.codec.utf8String = { } return decodeURIComponent(escape(out)); }, - + /** Convert from a UTF-8 string to a bitArray. */ toBits: function (str) { str = unescape(encodeURIComponent(str)); @@ -1666,6 +1676,7 @@ sjcl.codec.utf8String = { return out; } }; + /** @fileOverview Bit array codec implementations. * * @author Emily Stark @@ -1679,7 +1690,7 @@ sjcl.codec.base64 = { * @private */ _chars: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/", - + /** Convert from a bitArray to a base64 string. */ fromBits: function (arr, _noEquals, _url) { var out = "", i, bits=0, c = sjcl.codec.base64._chars, ta=0, bl = sjcl.bitArray.bitLength(arr); @@ -1698,7 +1709,7 @@ sjcl.codec.base64 = { while ((out.length & 3) && !_noEquals) { out += "="; } return out; }, - + /** Convert from a base64 string to a bitArray */ toBits: function(str, _url) { str = str.replace(/\s|=/g,''); @@ -1729,6 +1740,7 @@ sjcl.codec.base64url = { fromBits: function (arr) { return sjcl.codec.base64.fromBits(arr,1,1); }, toBits: function (str) { return sjcl.codec.base64.toBits(str,1); } }; + /** @fileOverview CBC mode implementation * * @author Emily Stark @@ -1753,7 +1765,7 @@ sjcl.beware["CBC mode is dangerous because it doesn't protect message integrity. * @constant */ name: "cbc", - + /** Encrypt in CBC mode with PKCS#5 padding. * @param {Object} prp The block cipher. It must have a block size of 16 bytes. * @param {bitArray} plaintext The plaintext data. @@ -1779,13 +1791,13 @@ sjcl.beware["CBC mode is dangerous because it doesn't protect message integrity. if (bl&7) { throw new sjcl.exception.invalid("pkcs#5 padding only works for multiples of a byte"); } - + for (i=0; bp+128 <= bl; i+=4, bp+=128) { /* Encrypt a non-final block */ iv = prp.encrypt(xor(iv, plaintext.slice(i,i+4))); output.splice(i,0,iv[0],iv[1],iv[2],iv[3]); } - + /* Construct the pad. */ bl = (16 - ((bl >> 3) & 15)) * 0x1010101; @@ -1794,7 +1806,7 @@ sjcl.beware["CBC mode is dangerous because it doesn't protect message integrity. output.splice(i,0,iv[0],iv[1],iv[2],iv[3]); return output; }, - + /** Decrypt in CBC mode. * @param {Object} prp The block cipher. It must have a block size of 16 bytes. * @param {bitArray} ciphertext The ciphertext data. @@ -1819,9 +1831,9 @@ sjcl.beware["CBC mode is dangerous because it doesn't protect message integrity. xor = w._xor4, bi, bo, output = []; - + adata = adata || []; - + for (i=0; i bs) { key = Hash.hash(key); } - + for (i=0; i>>7 ^ a>>>18 ^ a>>>3 ^ a<<25 ^ a<<14) + + tmp = w[i&15] = ((a>>>7 ^ a>>>18 ^ a>>>3 ^ a<<25 ^ a<<14) + (b>>>17 ^ b>>>19 ^ b>>>10 ^ b<<15 ^ b<<13) + w[i&15] + w[(i+9) & 15]) | 0; } - + tmp = (tmp + h7 + (h4>>>6 ^ h4>>>11 ^ h4>>>25 ^ h4<<26 ^ h4<<21 ^ h4<<7) + (h6 ^ h4&(h5^h6)) + k[i]); // | 0; - + // shift register h7 = h6; h6 = h5; h5 = h4; h4 = h3 + tmp | 0; @@ -2100,6 +2114,7 @@ sjcl.hash.sha256.prototype = { }; + /** @fileOverview Random number generator. * * @author Emily Stark @@ -2147,30 +2162,30 @@ sjcl.random = { */ randomWords: function (nwords, paranoia) { var out = [], i, readiness = this.isReady(paranoia), g; - + if (readiness === this._NOT_READY) { throw new sjcl.exception.notReady("generator isn't seeded"); } else if (readiness & this._REQUIRES_RESEED) { this._reseedFromPools(!(readiness & this._READY)); } - + for (i=0; i= entropyRequired) { return (this._poolEntropy[0] > this._BITS_PER_RESEED && (new Date()).valueOf() > this._nextReseed) ? this._REQUIRES_RESEED | this._READY : @@ -2281,11 +2296,11 @@ sjcl.random = { this._NOT_READY; } }, - + /** Get the generator's progress toward readiness, as a fraction */ getProgress: function (paranoia) { var entropyRequired = this._PARANOIA_LEVELS[ paranoia ? paranoia : this._defaultParanoia ]; - + if (this._strength >= entropyRequired) { return 1.0; } else { @@ -2294,11 +2309,11 @@ sjcl.random = { this._poolStrength / entropyRequired; } }, - + /** start the built-in entropy collectors */ startCollectors: function () { if (this._collectorsStarted) { return; } - + if (window.addEventListener) { window.addEventListener("load", this._loadTimeCollector, false); window.addEventListener("mousemove", this._mouseCollector, false); @@ -2309,14 +2324,14 @@ sjcl.random = { else { throw new sjcl.exception.bug("can't attach event"); } - + this._collectorsStarted = true; }, - + /** stop the built-in entropy collectors */ stopCollectors: function () { if (!this._collectorsStarted) { return; } - + if (window.removeEventListener) { window.removeEventListener("load", this._loadTimeCollector, false); window.removeEventListener("mousemove", this._mouseCollector, false); @@ -2326,47 +2341,47 @@ sjcl.random = { } this._collectorsStarted = false; }, - + /* use a cookie to store entropy. useCookie: function (all_cookies) { throw new sjcl.exception.bug("random: useCookie is unimplemented"); },*/ - + /** add an event listener for progress or seeded-ness. */ addEventListener: function (name, callback) { this._callbacks[name][this._callbackI++] = callback; }, - + /** remove an event listener for progress or seeded-ness */ removeEventListener: function (name, cb) { var i, j, cbs=this._callbacks[name], jsTemp=[]; - + /* I'm not sure if this is necessary; in C++, iterating over a * collection and modifying it at the same time is a no-no. */ - + for (j in cbs) { if (cbs.hasOwnProperty(j) && cbs[j] === cb) { jsTemp.push(j); } } - + for (i=0; i= 1 << this._pools.length) { this._pools.push(new sjcl.hash.sha256()); this._poolEntropy.push(0); } - + /* how strong was this reseed? */ this._poolStrength -= strength; if (strength > this._strength) { this._strength = strength; } - + this._reseedCount ++; this._reseed(reseedData); }, - + _mouseCollector: function (ev) { var x = ev.x || ev.clientX || ev.offsetX || 0, y = ev.y || ev.clientY || ev.offsetY || 0; sjcl.random.addEntropy([x,y], 2, "mouse"); }, - + _loadTimeCollector: function (ev) { sjcl.random.addEntropy((new Date()).valueOf(), 2, "loadtime"); }, - + _fireEvent: function (name, arg) { var j, cbs=sjcl.random._callbacks[name], cbsTemp=[]; - /* TODO: there is a race condition between removing collectors and firing them */ + /* TODO: there is a race condition between removing collectors and firing them */ /* I'm not sure if this is necessary; in C++, iterating over a * collection and modifying it at the same time is a no-no. */ - + for (j in cbs) { if (cbs.hasOwnProperty(j)) { cbsTemp.push(cbs[j]); } } - + for (j=0; j> 4 ) & 0x3 ); + var b = ( ( b2 & 0xF ) << 4 ) | ( ( b3 >> 2 ) & 0xF ); + var c = ( ( b3 & 0x3 ) << 6 ) | ( b4 & 0x3F ); + + result += String.fromCharCode(a) + (b?String.fromCharCode(b):"") + (c?String.fromCharCode(c):""); + + } while( i < base64String.length ); + + return result; +}; + +global.atob = global.atob || atobPolyfill; + +module.exports = { + atobPolyfill: atobPolyfill +}; + +}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) +},{}],12:[function(require,module,exports){ +(function (global){ +'use strict'; + +var util = require('../util'); +var prepBody = require('./prep-body'); +var parseBody = require('./parse-body'); +var constants = require('../constants'); +var isXHRAvailable = global.XMLHttpRequest && 'withCredentials' in new global.XMLHttpRequest(); + +function getRequestObject() { + return isXHRAvailable ? new XMLHttpRequest() : new XDomainRequest(); +} + +function get(url, attrs, deserializer, callback, timeout) { + var urlParams = util.createURLParams(url, attrs); + makeRequest('GET', urlParams, null, deserializer, callback, timeout); +} + +function post(url, attrs, deserializer, callback, timeout) { + makeRequest('POST', url, attrs, deserializer, callback, timeout); +} + +function makeRequest(method, url, body, deserializer, callback, timeout) { + var status, resBody; + var req = getRequestObject(); + + callback = callback || function () {}; + + if (isXHRAvailable) { + req.onreadystatechange = function () { + if (req.readyState !== 4) { return; } + + status = req.status; + resBody = parseBody(req.responseText); + + if (status >= 400 || status === 0) { + callback.call(null, resBody || {errors: constants.errors.UNKNOWN_ERROR}, null); + } else if (status > 0) { + callback.call(null, null, deserializer(resBody)); + } + }; + } else { + req.onload = function () { + callback.call(null, null, deserializer(parseBody(req.responseText))); + }; + + req.onerror = function () { + callback.call(null, req.responseText, null); + }; + + // This must remain for IE9 to work + req.onprogress = function() {}; + + req.ontimeout = function () { + callback.call(null, {errors: constants.errors.UNKNOWN_ERROR}, null); + }; + } + + req.open(method, url, true); + req.timeout = timeout == null ? 60000 : timeout; + + if (isXHRAvailable && method === 'POST') { + req.setRequestHeader('Content-Type', 'application/json'); + } + + setTimeout(function () { + req.send(prepBody(method, body)); + }, 0); +} + +module.exports = { + get: get, + post: post +}; + +}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) +},{"../constants":4,"../util":20,"./parse-body":16,"./prep-body":17}],13:[function(require,module,exports){ +'use strict'; + +var JSONPDriver = require('./jsonp-driver'); +var AJAXDriver = require('./ajax-driver'); +var util = require('../util'); + +function chooseRequestDriver(options) { + var ua = util.getUserAgent(); + var isAJAXAvailable = !(util.isHTTP() && /(MSIE\s(8|9))|(Phantom)/.test(ua)); + + options = options || {}; + + if (options.enableCORS && isAJAXAvailable) { + return AJAXDriver; + } else { + return JSONPDriver; + } +} + +module.exports = chooseRequestDriver; + +},{"../util":20,"./ajax-driver":12,"./jsonp-driver":14}],14:[function(require,module,exports){ +'use strict'; + +var JSONP = require('./jsonp'); +var constants = require('../constants'); +var timeoutWatchers = []; + +function deserialize(response, mapper) { + if (response.status >= 400) { + return [response, null]; + } else { + return [null, mapper(response)]; + } +} + +function noop() {} + +function requestWithTimeout(url, attrs, deserializer, method, callback, timeout) { + var uniqueName; + + callback = callback || noop; + + if (timeout == null) { + timeout = 60000; + } + + uniqueName = method(url, attrs, function (data, name) { + if (timeoutWatchers[name]) { + clearTimeout(timeoutWatchers[name]); + callback.apply(null, deserialize(data, function (d) { return deserializer(d); })); + } + }); + + if (typeof timeout === 'number') { + timeoutWatchers[uniqueName] = setTimeout(function () { + timeoutWatchers[uniqueName] = null; + callback.apply(null, [{errors: constants.errors.UNKNOWN_ERROR}, null]); + }, timeout); + } else { + callback.apply(null, [{errors: constants.errors.INVALID_TIMEOUT}, null]); + } +} + +function post(url, attrs, deserializer, callback, timeout) { + attrs._method = 'POST'; + requestWithTimeout(url, attrs, deserializer, JSONP.get, callback, timeout); +} + +function get(url, attrs, deserializer, callback, timeout) { + requestWithTimeout(url, attrs, deserializer, JSONP.get, callback, timeout); +} + +module.exports = { + get: get, + post: post +}; + +},{"../constants":4,"./jsonp":15}],15:[function(require,module,exports){ +(function (global){ +'use strict'; + +var util = require('../util'); + +/* +* Lightweight JSONP fetcher +* Copyright 2010-2012 Erik Karlsson. All rights reserved. +* BSD licensed +*/ +var head, + window = global, + config = {}; + +function load(url, pfnError) { + var script = document.createElement('script'), + done = false; + script.src = url; + script.async = true; + + var errorHandler = pfnError || config.error; + if ( typeof errorHandler === 'function' ) { + script.onerror = function (ex){ + errorHandler({url: url, event: ex}); + }; + } + + script.onload = script.onreadystatechange = function () { + if ( !done && (!this.readyState || this.readyState === "loaded" || this.readyState === "complete") ) { + done = true; + script.onload = script.onreadystatechange = null; + if ( script && script.parentNode ) { + script.parentNode.removeChild( script ); + } + } + }; + + if ( !head ) { + head = document.getElementsByTagName('head')[0]; + } + head.appendChild( script ); +} + +function jsonp(url, params, callback, callbackName) { + var urlParams, key, uniqueName; + + callbackName = (callbackName||config['callbackName']||'callback'); + uniqueName = callbackName + "_json" + util.generateUUID(); + params[callbackName] = uniqueName; + urlParams = util.createURLParams(url, params) + + window[ uniqueName ] = function (data){ + callback(data, uniqueName); + try { + delete window[ uniqueName ]; + } catch (e) {} + window[ uniqueName ] = null; + }; + + load(urlParams); + return uniqueName; +} + +function setDefaults(obj){ + config = obj; +} + +module.exports = { + get: jsonp, + init: setDefaults +}; + +}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) +},{"../util":20}],16:[function(require,module,exports){ +'use strict'; + +module.exports = function (body) { + try { + body = JSON.parse(body); + } catch (e) {} + + return body; +}; + +},{}],17:[function(require,module,exports){ +'use strict'; + +var isString = require('lodash.isstring'); + +module.exports = function (method, body) { + if (!isString(method)) { + throw new Error('Method must be a string'); + } + + if (method.toLowerCase() !== 'get' && body != null) { + body = isString(body) ? body : JSON.stringify(body); + } + + return body; +}; + +},{"lodash.isstring":51}],18:[function(require,module,exports){ +'use strict'; + +function SEPAMandate(attributes) { + var i = 0; + var attribute; + var allAttributes = [ + 'accountHolderName', + 'bic', + 'longFormURL', + 'mandateReferenceNumber', + 'maskedIBAN', + 'shortForm' + ]; + + for (i = 0; i < allAttributes.length; i++) { + attribute = allAttributes[i]; + this[attribute] = attributes[attribute]; + } +} + +module.exports = SEPAMandate; + +},{}],19:[function(require,module,exports){ +'use strict'; + +module.exports = function (options) { + if (options.enableCORS != null) { + return options.enableCORS; + } + + if (options.merchantConfiguration) { + return options.merchantConfiguration.enableCORS; + } + + return false; +}; + +},{}],20:[function(require,module,exports){ +(function (global){ +'use strict'; + +var isEmpty = require('lodash.isempty'); +var isObject = require('lodash.isobject'); + +function joinUrlFragments(fragments) { + var strippedFragments = [], + strippedFragment, + i; + + for (i = 0; i < fragments.length; i++) { + strippedFragment = fragments[i]; + if (strippedFragment.charAt(strippedFragment.length - 1) === '/') { + strippedFragment = strippedFragment.substring(0, strippedFragment.length - 1); + } + if (strippedFragment.charAt(0) === '/') { + strippedFragment = strippedFragment.substring(1); + } + + strippedFragments.push(strippedFragment); + } + + return strippedFragments.join('/'); +} + +function isArray(value) { + return value && typeof value === 'object' && typeof value.length === 'number' && + Object.prototype.toString.call(value) === '[object Array]' || false; +} + +function generateUUID() { // RFC 4122 v4 (pseudo-random) UUID without hyphens + return 'xxxxxxxxxxxx4xxxyxxxxxxxxxxxxxxx'.replace(/[xy]/g, function (xORy) { + var randomHex = Math.floor(Math.random() * 16); + var uuidHex = xORy === 'x' ? randomHex : randomHex & 0x3 | 0x8; // jshint ignore:line + return uuidHex.toString(16); + }); +} + +function mergeOptions(obj1, obj2) { + var obj3 = {}; + var attrname; + for (attrname in obj1) { + if (obj1.hasOwnProperty(attrname)) { + obj3[attrname] = obj1[attrname]; + } + } + for (attrname in obj2) { + if (obj2.hasOwnProperty(attrname)) { + obj3[attrname] = obj2[attrname]; + } + } + return obj3; +} + +function stringify(params, namespace) { + var query = [], k, v, p; + + for (p in params) { + if (!params.hasOwnProperty(p)) { + continue; + } + + v = params[p]; + + if (namespace) { + if (isArray(params)) { + k = namespace + '[]'; + } else { + k = namespace + '[' + p + ']'; + } + } else { + k = p; + } + if (typeof v === 'object') { + query.push(stringify(v, k)); + } else { + query.push(encodeURIComponent(k) + '=' + encodeURIComponent(v)); + } + } + + return query.join('&'); +} + +function createURLParams(url, params) { + url = url || ''; + + if (!isEmpty(params) && isObject(params)) { + url += url.indexOf('?') === -1 ? '?' : ''; + url += url.indexOf('=') !== -1 ? '&' : ''; + url += stringify(params); + } + + return url; +} + +function getUserAgent() { + return global.navigator.userAgent; +} + +function isHTTP() { + return global.location.protocol === 'http:'; +} + +module.exports = { + joinUrlFragments: joinUrlFragments, + isArray: isArray, + generateUUID: generateUUID, + mergeOptions: mergeOptions, + stringify: stringify, + createURLParams: createURLParams, + getUserAgent: getUserAgent, + isHTTP: isHTTP +}; + +}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) +},{"lodash.isempty":44,"lodash.isobject":50}],21:[function(require,module,exports){ +'use strict'; + +var Client = require('./lib/client'); +var util = require('./lib/util'); +var parseClientToken = require('./lib/parse-client-token'); +var getConfiguration = require('./lib/get-configuration'); + +function configure(options) { + return new Client(options); +} + +module.exports = { + Client: Client, + configure: configure, + util: util, + parseClientToken: parseClientToken, + _getConfiguration: getConfiguration +}; + +},{"./lib/client":2,"./lib/get-configuration":7,"./lib/parse-client-token":9,"./lib/util":20}],22:[function(require,module,exports){ +'use strict'; + +function normalizeElement (element, errorMessage) { + errorMessage = errorMessage || '[' + element + '] is not a valid DOM Element'; + + if (element && element.nodeType && element.nodeType === 1) { + return element; + } + if (element && window.jQuery && (element instanceof jQuery || 'jquery' in Object(element)) && element.length !== 0) { + return element[0]; + } + + if (typeof element === 'string' && document.getElementById(element)) { + return document.getElementById(element); + } + + throw new Error(errorMessage); +} + +module.exports = { + normalizeElement: normalizeElement +}; + +},{}],23:[function(require,module,exports){ +'use strict'; + +function addEventListener(element, type, listener, useCapture) { + if (element.addEventListener) { + element.addEventListener(type, listener, useCapture); + } else if (element.attachEvent) { + element.attachEvent('on' + type, listener); + } +} + +function removeEventListener(element, type, listener, useCapture) { + if (element.removeEventListener) { + element.removeEventListener(type, listener, useCapture); + } else if (element.detachEvent) { + element.detachEvent('on' + type, listener); + } +} + +module.exports = { + addEventListener: addEventListener, + removeEventListener: removeEventListener +}; + +},{}],24:[function(require,module,exports){ +'use strict'; + +var toString = Object.prototype.toString; + +function isFunction(func) { + return toString.call(func) === '[object Function]'; +} + +function bind(func, context) { + return function () { + func.apply(context, arguments); + }; +} + +module.exports = { + bind: bind, + isFunction: isFunction +}; + +},{}],25:[function(require,module,exports){ +'use strict'; + +function isBrowserHttps() { + return window.location.protocol === 'https:'; +} + +function encode(str) { + switch (str) { + case null: + case undefined: + return ''; + case true: + return '1'; + case false: + return '0'; + default: + return encodeURIComponent(str); + } +} + +function makeQueryString(params, namespace) { + var query = [], k, p; + for (p in params) { + if (params.hasOwnProperty(p)) { + var v = params[p]; + if (namespace) { + k = namespace + '[' + p + ']'; + } else { + k = p; + } + if (typeof v === 'object') { + query.push(makeQueryString(v, k)); + } else if (v !== undefined && v !== null) { + query.push(encode(k) + '=' + encode(v)); + } + } + } + return query.join('&'); +} + +function decodeQueryString(queryString) { + var params = {}, + paramPairs = queryString.split('&'); + + for (var i = 0; i < paramPairs.length; i++) { + var paramPair = paramPairs[i].split('='); + var key = paramPair[0]; + var value = decodeURIComponent(paramPair[1]); + params[key] = value; + } + + return params; +} + +function getParams(url) { + var urlSegments = url.split('?'); + + if (urlSegments.length !== 2) { + return {}; + } + + return decodeQueryString(urlSegments[1]); +} + +module.exports = { + isBrowserHttps: isBrowserHttps, + makeQueryString: makeQueryString, + decodeQueryString: decodeQueryString, + getParams: getParams +}; + +},{}],26:[function(require,module,exports){ +var dom = require('./lib/dom'); +var url = require('./lib/url'); +var fn = require('./lib/fn'); +var events = require('./lib/events'); + +module.exports = { + normalizeElement: dom.normalizeElement, + isBrowserHttps: url.isBrowserHttps, + makeQueryString: url.makeQueryString, + decodeQueryString: url.decodeQueryString, + getParams: url.getParams, + removeEventListener: events.removeEventListener, + addEventListener: events.addEventListener, + bind: fn.bind, + isFunction: fn.isFunction +}; + +},{"./lib/dom":22,"./lib/events":23,"./lib/fn":24,"./lib/url":25}],27:[function(require,module,exports){ +'use strict'; + +var utils = require('braintree-utilities'); +var Receiver = require('../shared/receiver'); +var version = "1.3.0"; + +var htmlNode, bodyNode; + +function getElementStyle(element, style) { + var computedStyle = window.getComputedStyle ? getComputedStyle(element) : element.currentStyle; + + return computedStyle[style]; +} + +function getMerchantPageDefaultStyles() { + return { + html: { + height: htmlNode.style.height || '', + overflow: getElementStyle(htmlNode, 'overflow'), + position: getElementStyle(htmlNode, 'position') + }, + body: { + height: bodyNode.style.height || '', + overflow: getElementStyle(bodyNode, 'overflow') + } + }; +} + +function AuthenticationService (assetsUrl, container) { + this.assetsUrl = assetsUrl; + this.container = container || document.body; + this.iframe = null; + + htmlNode = document.documentElement; + bodyNode = document.body; + this.merchantPageDefaultStyles = getMerchantPageDefaultStyles(); +} + +AuthenticationService.prototype.get = function (response, callback) { + var self = this, + url = this.constructAuthorizationURL(response); + + if (this.container && utils.isFunction(this.container)) { + this.container(url + '&no_style=1'); + } else { + this.insertIframe(url); + } + + new Receiver(function (response) { + if (!utils.isFunction(self.container)) { + self.removeIframe(); + } + callback(response); + }); +}; + +AuthenticationService.prototype.removeIframe = function () { + if (this.container && this.container.nodeType && this.container.nodeType === 1) { + this.container.removeChild(this.iframe); + } else if (this.container && window.jQuery && this.container instanceof jQuery) { + $(this.iframe, this.container).remove(); + } else if (typeof this.container === 'string') { + document.getElementById(this.container).removeChild(this.iframe); + } + + this.unlockMerchantWindowSize(); +}; + +AuthenticationService.prototype.insertIframe = function (url) { + // TODO: Security - This takes a url and makes an iframe. Doesn't seem like this would be a problem. + var iframe = document.createElement('iframe'); + iframe.src = url; + this.applyStyles(iframe); + this.lockMerchantWindowSize(); + + if (this.container && this.container.nodeType && this.container.nodeType === 1) { + this.container.appendChild(iframe); + } else if (this.container && window.jQuery && this.container instanceof jQuery && this.container.length !== 0) { + this.container.append(iframe); + } else if (typeof this.container === 'string' && document.getElementById(this.container)) { + document.getElementById(this.container).appendChild(iframe); + } else { + throw new Error('Unable to find valid container for iframe.'); + } + this.iframe = iframe; +}; + +AuthenticationService.prototype.applyStyles = function (iframe) { + iframe.style.position = 'fixed'; + iframe.style.top = '0'; + iframe.style.left = '0'; + iframe.style.height = '100%'; + iframe.style.width = '100%'; + iframe.setAttribute('frameborder', '0'); + iframe.setAttribute('allowTransparency', 'true'); + iframe.style.border = '0'; + iframe.style.zIndex = '99999'; +}; + +AuthenticationService.prototype.lockMerchantWindowSize = function () { + htmlNode.style.overflow = 'hidden'; + bodyNode.style.overflow = 'hidden'; + bodyNode.style.height = '100%'; +}; + +AuthenticationService.prototype.unlockMerchantWindowSize = function () { + var defaultStyles = this.merchantPageDefaultStyles; + + bodyNode.style.height = defaultStyles.body.height; + bodyNode.style.overflow = defaultStyles.body.overflow; + + htmlNode.style.overflow = defaultStyles.html.overflow; +}; + +AuthenticationService.prototype.constructAuthorizationURL = function (response) { + var queryString, + parentURL = window.location.href; + + if (parentURL.indexOf('#') > -1) { + parentURL = parentURL.split('#')[0]; + } + + queryString = utils.makeQueryString({ + acsUrl: response.acsUrl, + pareq: response.pareq, + termUrl: response.termUrl + '&three_d_secure_version=' + version, + md: response.md, + parentUrl: parentURL + }); + return this.assetsUrl + '/3ds/' + version + '/html/style_frame?' + queryString; +}; + +module.exports = AuthenticationService; + +},{"../shared/receiver":34,"braintree-utilities":26}],28:[function(require,module,exports){ +'use strict'; + +var utils = require('braintree-utilities'); +var AuthenticationService = require('./authorization_service'); +var Loader = require('./loader'); + +function noop() {} + +function Client(api, options) { + options = options || {}; + this.clientToken = options.clientToken; + this.container = options.container; + this.api = api; + this.nonce = null; + + this._loader = null; + this._boundHandleUserClose = utils.bind(this._handleUserClose, this); +} + +Client.prototype.verify = function (data, callback) { + if (!utils.isFunction(callback)) { + this.api.sendAnalyticsEvents('3ds.web.no_callback'); + throw new Error('No suitable callback argument was given'); + } + if (utils.isFunction(data.onUserClose)) { + this._onUserClose = data.onUserClose; + } + if (utils.isFunction(data.onLookupComplete)) { + this._onLookupComplete = data.onLookupComplete; + } + if (data.useDefaultLoader === undefined || data.useDefaultLoader === true) { + this._createDefaultLoader(); + } + + var dataRecord = {nonce: '', amount: data.amount}; + var creditCardMetaData = data.creditCard; + + if (typeof creditCardMetaData === 'string') { + dataRecord.nonce = creditCardMetaData; + this.api.sendAnalyticsEvents('3ds.web.verify.nonce'); + this.startVerification(dataRecord, callback); + } else { + var self = this; + var boundHandleTokenizeCard = function (err, nonce) { + if (err) { + self._removeDefaultLoader(); + + return callback(err); + } + dataRecord.nonce = nonce; + self.startVerification(dataRecord, callback); + }; + this.api.sendAnalyticsEvents('3ds.web.verify.credit_card'); + this.api.tokenizeCard(creditCardMetaData, boundHandleTokenizeCard); + } +}; + +Client.prototype.startVerification = function (data, merchantCallback) { + this.api.lookup3DS(data, utils.bind(this.handleLookupResponse(merchantCallback), this)); +}; + +Client.prototype.handleLookupResponse = function (merchantCallback) { + var self = this; + return function (errorResponse, lookupResponse) { + var authenticationService; + + this._onLookupComplete(); + + if (errorResponse) { + merchantCallback(errorResponse.error); + } else if (lookupResponse.lookup && lookupResponse.lookup.acsUrl && lookupResponse.lookup.acsUrl.length > 0) { + self.nonce = lookupResponse.paymentMethod.nonce; + authenticationService = new AuthenticationService(this.clientToken.assetsUrl, this.container); + authenticationService.get(lookupResponse.lookup, utils.bind(this.handleAuthenticationResponse(merchantCallback), this)); + + this._detachListeners(); + this._attachListeners(); + } else { + self.nonce = lookupResponse.paymentMethod.nonce; + merchantCallback(null, { + nonce: self.nonce, + verificationDetails: lookupResponse.threeDSecureInfo + }); + } + }; +}; + +Client.prototype.handleAuthenticationResponse = function (merchantCallback) { + return function (authResponseQueryString) { + var authResponse, + queryParams = utils.decodeQueryString(authResponseQueryString); + + if (queryParams.user_closed) { + return; + } + + authResponse = JSON.parse(queryParams.auth_response); + + if (authResponse.success) { + merchantCallback(null, { + nonce: authResponse.paymentMethod.nonce, + verificationDetails: authResponse.threeDSecureInfo + }); + } else if (authResponse.threeDSecureInfo && authResponse.threeDSecureInfo.liabilityShiftPossible) { + merchantCallback(null, { + nonce: this.nonce, + verificationDetails: authResponse.threeDSecureInfo + }); + } else { + merchantCallback(authResponse.error); + } + }; +}; + +Client.prototype._attachListeners = function () { + utils.addEventListener(window, 'message', this._boundHandleUserClose); +}; + +Client.prototype._detachListeners = function () { + utils.removeEventListener(window, 'message', this._boundHandleUserClose); +}; + +Client.prototype._createDefaultLoader = function () { + this._loader = new Loader(); + + document.body.appendChild(this._loader.getElement()); +}; + +Client.prototype._removeDefaultLoader = function () { + if (!this._loader) { + return; + } + + var loaderElement = this._loader.getElement(); + var parentElement = loaderElement.parentNode; + + if (parentElement) { + parentElement.removeChild(loaderElement); + } + + this._loader.dispose(); + this._loader = null; +}; + +Client.prototype._handleUserClose = function (event) { + if (event.data === 'user_closed=true') { + this._onUserClose(); + } +}; + +Client.prototype._onUserClose = noop; + +Client.prototype._onLookupComplete = function () { + this._removeDefaultLoader(); +}; + +module.exports = Client; + +},{"./authorization_service":27,"./loader":30,"braintree-utilities":26}],29:[function(require,module,exports){ +'use strict'; + +var Client = require('./client'); + +module.exports = { + create: function (clientToken, options) { + var client = new Client(clientToken, options); + return client; + } +}; + +},{"./client":28}],30:[function(require,module,exports){ +'use strict'; + +var LoaderDisplay = require('./loader_display'); +var LoaderMessage = require('./loader_message'); +var LoaderSpinner = require('./loader_spinner'); + +function Loader() { + this._element = document.createElement('div'); + this._element.style.cssText = this._cssDeclarations; + + this._display = null; + + this._initialize(); +} + +Loader.prototype._cssDeclarations = [ + 'filter:progid:DXImageTransform.Microsoft.Gradient(StartColorStr=#7F000000, EndColorStr=#7F000000)', + 'background-color: rgba(0, 0, 0, 0.5)', + 'display: table', + 'height: 100%', + 'left: 0', + 'position: fixed', + 'right: 0', + 'top: 0', + 'width: 100%', + 'z-index: 99999' +].join(';'); + +Loader.prototype.getElement = function () { + return this._element; +}; + +Loader.prototype.dispose = function () { + this._display.dispose(); + this._display = null; + + this._element = null; +}; + +Loader.prototype._initialize = function () { + var displayObject = new LoaderSpinner(); + var supportsSvgAnimations = (window.SVGElement && window.SVGAnimateElement && + window.SVGAnimateTransformElement); + + if (!(supportsSvgAnimations)) { + displayObject = new LoaderMessage('Loading...'); + } + + this._display = new LoaderDisplay(displayObject); + this.getElement().appendChild(this._display.getElement()); +}; + +module.exports = Loader; + +},{"./loader_display":31,"./loader_message":32,"./loader_spinner":33}],31:[function(require,module,exports){ +'use strict'; + +function LoaderDisplay(displayObject) { + this._element = document.createElement('div'); + this._element.style.cssText = this._cssDeclarations; + + this._displayObject = displayObject; + + this._initialize(); +} + +LoaderDisplay.prototype._cssDeclarations = [ + 'display: table-cell', + 'vertical-align: middle' +].join(';'); + +LoaderDisplay.prototype.getElement = function () { + return this._element; +}; + +LoaderDisplay.prototype.dispose = function () { + this._displayObject.dispose(); + this._displayObject = null; + + this._element = null; +}; + +LoaderDisplay.prototype._initialize = function () { + this.getElement().appendChild(this._displayObject.getElement()); +}; + +module.exports = LoaderDisplay; + +},{}],32:[function(require,module,exports){ +'use strict'; + +function LoaderMessage(text) { + this._element = document.createElement('div'); + this._element.style.cssText = this._cssDeclarations; + this._element.innerHTML = text; +} + +LoaderMessage.prototype._cssDeclarations = [ + 'color: #fff', + 'font-family: Helvetica, sans-serif', + 'font-size: 12px', + 'text-align: center' +].join(';'); + +LoaderMessage.prototype.getElement = function () { + return this._element; +}; + +LoaderMessage.prototype.dispose = function () { + this._element = null; +}; + +module.exports = LoaderMessage; + +},{}],33:[function(require,module,exports){ +'use strict'; + +function LoaderSpinner() { + this._element = document.createElement('div'); + this._element.style.cssText = this._cssDeclarations; + this._element.innerHTML = this._markup; +} + +LoaderSpinner.prototype._cssDeclarations = [ + 'height: 36px', + 'margin-left: auto', + 'margin-right: auto', + 'width: 36px' +].join(';'); + +LoaderSpinner.prototype._markup = [ + '', + ' ', + ' ', + ' ', + '' +].join(''); + +LoaderSpinner.prototype.getElement = function () { + return this._element; +}; + +LoaderSpinner.prototype.dispose = function () { + this._element = null; +}; + +module.exports = LoaderSpinner; + +},{}],34:[function(require,module,exports){ +'use strict'; + +var utils = require('braintree-utilities'); + +function Receiver (callback) { + this.postMessageReceiver(callback); + this.hashChangeReceiver(callback); +} + +Receiver.prototype.postMessageReceiver = function (callback) { + var self = this; + + this.wrappedCallback = function (event) { + var data = event.data; + + if (/^(auth_response=)/.test(data) || data === 'user_closed=true') { + callback(data); + self.stopListening(); + } + }; + + utils.addEventListener(window, 'message', this.wrappedCallback); +}; + +Receiver.prototype.hashChangeReceiver = function (callback) { + var hash, + originalHash = window.location.hash, + self = this; + + this.poll = setInterval(function () { + hash = window.location.hash; + + if (hash.length > 0 && (hash !== originalHash)) { + self.stopListening(); + + hash = hash.substring(1, hash.length); + callback(hash); + + if (originalHash.length > 0) { + window.location.hash = originalHash; + } else { + window.location.hash = ''; + } + } + }, 10); +}; + +Receiver.prototype.stopListening = function () { + clearTimeout(this.poll); + + utils.removeEventListener(window, 'message', this.wrappedCallback); +}; + +module.exports = Receiver; + +},{"braintree-utilities":26}],35:[function(require,module,exports){ +'use strict'; + +var nativeIndexOf = Array.prototype.indexOf; + +var indexOf; +if (nativeIndexOf) { + indexOf = function (haystack, needle) { + return haystack.indexOf(needle); + }; +} else { + indexOf = function indexOf(haystack, needle) { + for (var i = 0, len = haystack.length; i < len; i++) { + if (haystack[i] === needle) { + return i; + } + } + return -1; + }; +} + +module.exports = { + indexOf: indexOf +}; + +},{}],36:[function(require,module,exports){ +'use strict'; + +function _escape(string) { + var i, hex; + var escaped = ''; + + for (i = 0; i < string.length; i++) { + escaped += '%'; + hex = string[i].charCodeAt(0).toString(16).toUpperCase(); + + if (hex.length < 2) { + escaped += '0'; + } + + escaped += hex; + } + + return escaped; +} + +function decodeUtf8(b64) { + return decodeURIComponent(_escape(atob(b64))); +} + +module.exports = { + decodeUtf8: decodeUtf8 +}; + +},{}],37:[function(require,module,exports){ +arguments[4][22][0].apply(exports,arguments) +},{"dup":22}],38:[function(require,module,exports){ +'use strict'; + +function addEventListener(element, type, listener, useCapture) { + if (element.addEventListener) { + element.addEventListener(type, listener, useCapture || false); + } else if (element.attachEvent) { + element.attachEvent('on' + type, listener); + } +} + +function removeEventListener(element, type, listener, useCapture) { + if (element.removeEventListener) { + element.removeEventListener(type, listener, useCapture || false); + } else if (element.detachEvent) { + element.detachEvent('on' + type, listener); + } +} + +function preventDefault(event) { + if (event.preventDefault) { + event.preventDefault(); + } else { + event.returnValue = false; + } +} + +module.exports = { + addEventListener: addEventListener, + removeEventListener: removeEventListener, + preventDefault: preventDefault +}; + +},{}],39:[function(require,module,exports){ +'use strict'; + +var toString = Object.prototype.toString; + +function isFunction(func) { + return toString.call(func) === '[object Function]'; +} + +function bind(func, context) { + return function () { + return func.apply(context, arguments); + }; +} + +module.exports = { + bind: bind, + isFunction: isFunction +}; + +},{}],40:[function(require,module,exports){ +'use strict'; + +function getMaxCharLength(width) { + var max, i, range, len; + var ranges = [ + { min: 0, max: 180, chars: 7 }, + { min: 181, max: 620, chars: 14 }, + { min: 621, max: 960, chars: 22 } + ]; + + len = ranges.length; + + width = width || window.innerWidth; + + for (i = 0; i < len; i++) { + range = ranges[i]; + + if (width >= range.min && width <= range.max) { + max = range.chars; + } + } + + return max || 60; +} + +function truncateEmail(email, maxLength) { + var address, domain; + + if (email.indexOf('@') === -1) { + return email; + } + + email = email.split('@'); + address = email[0]; + domain = email[1]; + + if (address.length > maxLength) { + address = address.slice(0, maxLength) + '...'; + } + + if (domain.length > maxLength) { + domain = '...' + domain.slice(-maxLength); + } + + return address + '@' + domain; +} + +module.exports = { + truncateEmail: truncateEmail, + getMaxCharLength: getMaxCharLength +}; + +},{}],41:[function(require,module,exports){ +'use strict'; + +var array = require('./array'); + +function isBrowserHttps() { + return window.location.protocol === 'https:'; +} + +function encode(str) { + switch (str) { + case null: + case undefined: + return ''; + case true: + return '1'; + case false: + return '0'; + default: + return encodeURIComponent(str); + } +} + +function makeQueryString(params, namespace) { + var query = [], k, p; + for (p in params) { + if (params.hasOwnProperty(p)) { + var v = params[p]; + if (namespace) { + k = namespace + '[' + p + ']'; + } else { + k = p; + } + if (typeof v === 'object') { + query.push(makeQueryString(v, k)); + } else if (v !== undefined && v !== null) { + query.push(encode(k) + '=' + encode(v)); + } + } + } + return query.join('&'); +} + +function decodeQueryString(queryString) { + var params = {}, + paramPairs = queryString.split('&'); + + for (var i = 0; i < paramPairs.length; i++) { + var paramPair = paramPairs[i].split('='); + var key = paramPair[0]; + var value = decodeURIComponent(paramPair[1]); + params[key] = value; + } + + return params; +} + +function getParams(url) { + var urlSegments = url.split('?'); + + if (urlSegments.length !== 2) { + return {}; + } + + return decodeQueryString(urlSegments[1]); +} + +var parser = document.createElement('a'); +var legalHosts = [ + 'paypal.com', + 'braintreepayments.com', + 'braintreegateway.com', + 'localhost' +]; + +function isWhitelistedDomain(url) { + url = url.toLowerCase(); + + if (!/^http/.test(url)) { + return false; + } + + parser.href = url; + + var pieces = parser.hostname.split('.'); + var topLevelDomain = pieces.slice(-2).join('.'); + + if (array.indexOf(legalHosts, topLevelDomain) === -1) { + return false; + } + + return true; +} + +module.exports = { + isBrowserHttps: isBrowserHttps, + makeQueryString: makeQueryString, + decodeQueryString: decodeQueryString, + getParams: getParams, + isWhitelistedDomain: isWhitelistedDomain +}; + +},{"./array":35}],42:[function(require,module,exports){ +'use strict'; + +// RFC 4122 v4 (pseudo-random) UUID +function generate() { + return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) { + var r = Math.random() * 16 | 0; + var v = c === 'x' ? r : r & 0x3 | 0x8; + return v.toString(16); + }); +} + +module.exports = generate; + +},{}],43:[function(require,module,exports){ +var dom = require('./lib/dom'); +var url = require('./lib/url'); +var fn = require('./lib/fn'); +var events = require('./lib/events'); +var string = require('./lib/string'); +var array = require('./lib/array'); +var base64 = require('./lib/base64'); +var uuid = require('./lib/uuid'); + +module.exports = { + string: string, + array: array, + normalizeElement: dom.normalizeElement, + isBrowserHttps: url.isBrowserHttps, + makeQueryString: url.makeQueryString, + decodeQueryString: url.decodeQueryString, + getParams: url.getParams, + isWhitelistedDomain: url.isWhitelistedDomain, + removeEventListener: events.removeEventListener, + addEventListener: events.addEventListener, + preventDefault: events.preventDefault, + bind: fn.bind, + isFunction: fn.isFunction, + base64ToUtf8: base64.decodeUtf8, + uuid: uuid +}; + +},{"./lib/array":35,"./lib/base64":36,"./lib/dom":37,"./lib/events":38,"./lib/fn":39,"./lib/string":40,"./lib/url":41,"./lib/uuid":42}],44:[function(require,module,exports){ +/** + * lodash 3.0.4 (Custom Build) + * Build: `lodash modern modularize exports="npm" -o ./` + * Copyright 2012-2015 The Dojo Foundation + * Based on Underscore.js 1.8.3 + * Copyright 2009-2015 Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors + * Available under MIT license + */ +var isArguments = require('lodash.isarguments'), + isArray = require('lodash.isarray'), + isFunction = require('lodash.isfunction'), + isString = require('lodash.isstring'), + keys = require('lodash.keys'); + +/** + * Checks if `value` is object-like. + * + * @private + * @param {*} value The value to check. + * @returns {boolean} Returns `true` if `value` is object-like, else `false`. + */ +function isObjectLike(value) { + return !!value && typeof value == 'object'; +} + +/** + * Used as the [maximum length](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-number.max_safe_integer) + * of an array-like value. + */ +var MAX_SAFE_INTEGER = 9007199254740991; + +/** + * The base implementation of `_.property` without support for deep paths. + * + * @private + * @param {string} key The key of the property to get. + * @returns {Function} Returns the new function. + */ +function baseProperty(key) { + return function(object) { + return object == null ? undefined : object[key]; + }; +} + +/** + * Gets the "length" property value of `object`. + * + * **Note:** This function is used to avoid a [JIT bug](https://bugs.webkit.org/show_bug.cgi?id=142792) + * that affects Safari on at least iOS 8.1-8.3 ARM64. + * + * @private + * @param {Object} object The object to query. + * @returns {*} Returns the "length" value. + */ +var getLength = baseProperty('length'); + +/** + * Checks if `value` is array-like. + * + * @private + * @param {*} value The value to check. + * @returns {boolean} Returns `true` if `value` is array-like, else `false`. + */ +function isArrayLike(value) { + return value != null && isLength(getLength(value)); +} + +/** + * Checks if `value` is a valid array-like length. + * + * **Note:** This function is based on [`ToLength`](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-tolength). + * + * @private + * @param {*} value The value to check. + * @returns {boolean} Returns `true` if `value` is a valid length, else `false`. + */ +function isLength(value) { + return typeof value == 'number' && value > -1 && value % 1 == 0 && value <= MAX_SAFE_INTEGER; +} + +/** + * Checks if `value` is empty. A value is considered empty unless it is an + * `arguments` object, array, string, or jQuery-like collection with a length + * greater than `0` or an object with own enumerable properties. + * + * @static + * @memberOf _ + * @category Lang + * @param {Array|Object|string} value The value to inspect. + * @returns {boolean} Returns `true` if `value` is empty, else `false`. + * @example + * + * _.isEmpty(null); + * // => true + * + * _.isEmpty(true); + * // => true + * + * _.isEmpty(1); + * // => true + * + * _.isEmpty([1, 2, 3]); + * // => false + * + * _.isEmpty({ 'a': 1 }); + * // => false + */ +function isEmpty(value) { + if (value == null) { + return true; + } + if (isArrayLike(value) && (isArray(value) || isString(value) || isArguments(value) || + (isObjectLike(value) && isFunction(value.splice)))) { + return !value.length; + } + return !keys(value).length; +} + +module.exports = isEmpty; + +},{"lodash.isarguments":45,"lodash.isarray":46,"lodash.isfunction":47,"lodash.isstring":51,"lodash.keys":48}],45:[function(require,module,exports){ +/** + * lodash 3.0.4 (Custom Build) + * Build: `lodash modern modularize exports="npm" -o ./` + * Copyright 2012-2015 The Dojo Foundation + * Based on Underscore.js 1.8.3 + * Copyright 2009-2015 Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors + * Available under MIT license + */ + +/** + * Checks if `value` is object-like. + * + * @private + * @param {*} value The value to check. + * @returns {boolean} Returns `true` if `value` is object-like, else `false`. + */ +function isObjectLike(value) { + return !!value && typeof value == 'object'; +} + +/** Used for native method references. */ +var objectProto = Object.prototype; + +/** Used to check objects for own properties. */ +var hasOwnProperty = objectProto.hasOwnProperty; + +/** Native method references. */ +var propertyIsEnumerable = objectProto.propertyIsEnumerable; + +/** + * Used as the [maximum length](http://ecma-international.org/ecma-262/6.0/#sec-number.max_safe_integer) + * of an array-like value. + */ +var MAX_SAFE_INTEGER = 9007199254740991; + +/** + * The base implementation of `_.property` without support for deep paths. + * + * @private + * @param {string} key The key of the property to get. + * @returns {Function} Returns the new function. + */ +function baseProperty(key) { + return function(object) { + return object == null ? undefined : object[key]; + }; +} + +/** + * Gets the "length" property value of `object`. + * + * **Note:** This function is used to avoid a [JIT bug](https://bugs.webkit.org/show_bug.cgi?id=142792) + * that affects Safari on at least iOS 8.1-8.3 ARM64. + * + * @private + * @param {Object} object The object to query. + * @returns {*} Returns the "length" value. + */ +var getLength = baseProperty('length'); + +/** + * Checks if `value` is array-like. + * + * @private + * @param {*} value The value to check. + * @returns {boolean} Returns `true` if `value` is array-like, else `false`. + */ +function isArrayLike(value) { + return value != null && isLength(getLength(value)); +} + +/** + * Checks if `value` is a valid array-like length. + * + * **Note:** This function is based on [`ToLength`](http://ecma-international.org/ecma-262/6.0/#sec-tolength). + * + * @private + * @param {*} value The value to check. + * @returns {boolean} Returns `true` if `value` is a valid length, else `false`. + */ +function isLength(value) { + return typeof value == 'number' && value > -1 && value % 1 == 0 && value <= MAX_SAFE_INTEGER; +} + +/** + * Checks if `value` is classified as an `arguments` object. + * + * @static + * @memberOf _ + * @category Lang + * @param {*} value The value to check. + * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`. + * @example + * + * _.isArguments(function() { return arguments; }()); + * // => true + * + * _.isArguments([1, 2, 3]); + * // => false + */ +function isArguments(value) { + return isObjectLike(value) && isArrayLike(value) && + hasOwnProperty.call(value, 'callee') && !propertyIsEnumerable.call(value, 'callee'); +} + +module.exports = isArguments; + +},{}],46:[function(require,module,exports){ +/** + * lodash 3.0.4 (Custom Build) + * Build: `lodash modern modularize exports="npm" -o ./` + * Copyright 2012-2015 The Dojo Foundation + * Based on Underscore.js 1.8.3 + * Copyright 2009-2015 Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors + * Available under MIT license + */ + +/** `Object#toString` result references. */ +var arrayTag = '[object Array]', + funcTag = '[object Function]'; + +/** Used to detect host constructors (Safari > 5). */ +var reIsHostCtor = /^\[object .+?Constructor\]$/; + +/** + * Checks if `value` is object-like. + * + * @private + * @param {*} value The value to check. + * @returns {boolean} Returns `true` if `value` is object-like, else `false`. + */ +function isObjectLike(value) { + return !!value && typeof value == 'object'; +} + +/** Used for native method references. */ +var objectProto = Object.prototype; + +/** Used to resolve the decompiled source of functions. */ +var fnToString = Function.prototype.toString; + +/** Used to check objects for own properties. */ +var hasOwnProperty = objectProto.hasOwnProperty; + +/** + * Used to resolve the [`toStringTag`](http://ecma-international.org/ecma-262/6.0/#sec-object.prototype.tostring) + * of values. + */ +var objToString = objectProto.toString; + +/** Used to detect if a method is native. */ +var reIsNative = RegExp('^' + + fnToString.call(hasOwnProperty).replace(/[\\^$.*+?()[\]{}|]/g, '\\$&') + .replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g, '$1.*?') + '$' +); + +/* Native method references for those with the same name as other `lodash` methods. */ +var nativeIsArray = getNative(Array, 'isArray'); + +/** + * Used as the [maximum length](http://ecma-international.org/ecma-262/6.0/#sec-number.max_safe_integer) + * of an array-like value. + */ +var MAX_SAFE_INTEGER = 9007199254740991; + +/** + * Gets the native function at `key` of `object`. + * + * @private + * @param {Object} object The object to query. + * @param {string} key The key of the method to get. + * @returns {*} Returns the function if it's native, else `undefined`. + */ +function getNative(object, key) { + var value = object == null ? undefined : object[key]; + return isNative(value) ? value : undefined; +} + +/** + * Checks if `value` is a valid array-like length. + * + * **Note:** This function is based on [`ToLength`](http://ecma-international.org/ecma-262/6.0/#sec-tolength). + * + * @private + * @param {*} value The value to check. + * @returns {boolean} Returns `true` if `value` is a valid length, else `false`. + */ +function isLength(value) { + return typeof value == 'number' && value > -1 && value % 1 == 0 && value <= MAX_SAFE_INTEGER; +} + +/** + * Checks if `value` is classified as an `Array` object. + * + * @static + * @memberOf _ + * @category Lang + * @param {*} value The value to check. + * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`. + * @example + * + * _.isArray([1, 2, 3]); + * // => true + * + * _.isArray(function() { return arguments; }()); + * // => false + */ +var isArray = nativeIsArray || function(value) { + return isObjectLike(value) && isLength(value.length) && objToString.call(value) == arrayTag; +}; + +/** + * Checks if `value` is classified as a `Function` object. + * + * @static + * @memberOf _ + * @category Lang + * @param {*} value The value to check. + * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`. + * @example + * + * _.isFunction(_); + * // => true + * + * _.isFunction(/abc/); + * // => false + */ +function isFunction(value) { + // The use of `Object#toString` avoids issues with the `typeof` operator + // in older versions of Chrome and Safari which return 'function' for regexes + // and Safari 8 equivalents which return 'object' for typed array constructors. + return isObject(value) && objToString.call(value) == funcTag; +} + +/** + * Checks if `value` is the [language type](https://es5.github.io/#x8) of `Object`. + * (e.g. arrays, functions, objects, regexes, `new Number(0)`, and `new String('')`) + * + * @static + * @memberOf _ + * @category Lang + * @param {*} value The value to check. + * @returns {boolean} Returns `true` if `value` is an object, else `false`. + * @example + * + * _.isObject({}); + * // => true + * + * _.isObject([1, 2, 3]); + * // => true + * + * _.isObject(1); + * // => false + */ +function isObject(value) { + // Avoid a V8 JIT bug in Chrome 19-20. + // See https://code.google.com/p/v8/issues/detail?id=2291 for more details. + var type = typeof value; + return !!value && (type == 'object' || type == 'function'); +} + +/** + * Checks if `value` is a native function. + * + * @static + * @memberOf _ + * @category Lang + * @param {*} value The value to check. + * @returns {boolean} Returns `true` if `value` is a native function, else `false`. + * @example + * + * _.isNative(Array.prototype.push); + * // => true + * + * _.isNative(_); + * // => false + */ +function isNative(value) { + if (value == null) { + return false; + } + if (isFunction(value)) { + return reIsNative.test(fnToString.call(value)); + } + return isObjectLike(value) && reIsHostCtor.test(value); +} + +module.exports = isArray; + +},{}],47:[function(require,module,exports){ +/** + * lodash 3.0.6 (Custom Build) + * Build: `lodash modern modularize exports="npm" -o ./` + * Copyright 2012-2015 The Dojo Foundation + * Based on Underscore.js 1.8.3 + * Copyright 2009-2015 Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors + * Available under MIT license + */ + +/** `Object#toString` result references. */ +var funcTag = '[object Function]'; + +/** Used for native method references. */ +var objectProto = Object.prototype; + +/** + * Used to resolve the [`toStringTag`](http://ecma-international.org/ecma-262/6.0/#sec-object.prototype.tostring) + * of values. + */ +var objToString = objectProto.toString; + +/** + * Checks if `value` is classified as a `Function` object. + * + * @static + * @memberOf _ + * @category Lang + * @param {*} value The value to check. + * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`. + * @example + * + * _.isFunction(_); + * // => true + * + * _.isFunction(/abc/); + * // => false + */ +function isFunction(value) { + // The use of `Object#toString` avoids issues with the `typeof` operator + // in older versions of Chrome and Safari which return 'function' for regexes + // and Safari 8 equivalents which return 'object' for typed array constructors. + return isObject(value) && objToString.call(value) == funcTag; +} + +/** + * Checks if `value` is the [language type](https://es5.github.io/#x8) of `Object`. + * (e.g. arrays, functions, objects, regexes, `new Number(0)`, and `new String('')`) + * + * @static + * @memberOf _ + * @category Lang + * @param {*} value The value to check. + * @returns {boolean} Returns `true` if `value` is an object, else `false`. + * @example + * + * _.isObject({}); + * // => true + * + * _.isObject([1, 2, 3]); + * // => true + * + * _.isObject(1); + * // => false + */ +function isObject(value) { + // Avoid a V8 JIT bug in Chrome 19-20. + // See https://code.google.com/p/v8/issues/detail?id=2291 for more details. + var type = typeof value; + return !!value && (type == 'object' || type == 'function'); +} + +module.exports = isFunction; + +},{}],48:[function(require,module,exports){ +/** + * lodash 3.1.2 (Custom Build) + * Build: `lodash modern modularize exports="npm" -o ./` + * Copyright 2012-2015 The Dojo Foundation + * Based on Underscore.js 1.8.3 + * Copyright 2009-2015 Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors + * Available under MIT license + */ +var getNative = require('lodash._getnative'), + isArguments = require('lodash.isarguments'), + isArray = require('lodash.isarray'); + +/** Used to detect unsigned integer values. */ +var reIsUint = /^\d+$/; + +/** Used for native method references. */ +var objectProto = Object.prototype; + +/** Used to check objects for own properties. */ +var hasOwnProperty = objectProto.hasOwnProperty; + +/* Native method references for those with the same name as other `lodash` methods. */ +var nativeKeys = getNative(Object, 'keys'); + +/** + * Used as the [maximum length](http://ecma-international.org/ecma-262/6.0/#sec-number.max_safe_integer) + * of an array-like value. + */ +var MAX_SAFE_INTEGER = 9007199254740991; + +/** + * The base implementation of `_.property` without support for deep paths. + * + * @private + * @param {string} key The key of the property to get. + * @returns {Function} Returns the new function. + */ +function baseProperty(key) { + return function(object) { + return object == null ? undefined : object[key]; + }; +} + +/** + * Gets the "length" property value of `object`. + * + * **Note:** This function is used to avoid a [JIT bug](https://bugs.webkit.org/show_bug.cgi?id=142792) + * that affects Safari on at least iOS 8.1-8.3 ARM64. + * + * @private + * @param {Object} object The object to query. + * @returns {*} Returns the "length" value. + */ +var getLength = baseProperty('length'); + +/** + * Checks if `value` is array-like. + * + * @private + * @param {*} value The value to check. + * @returns {boolean} Returns `true` if `value` is array-like, else `false`. + */ +function isArrayLike(value) { + return value != null && isLength(getLength(value)); +} + +/** + * Checks if `value` is a valid array-like index. + * + * @private + * @param {*} value The value to check. + * @param {number} [length=MAX_SAFE_INTEGER] The upper bounds of a valid index. + * @returns {boolean} Returns `true` if `value` is a valid index, else `false`. + */ +function isIndex(value, length) { + value = (typeof value == 'number' || reIsUint.test(value)) ? +value : -1; + length = length == null ? MAX_SAFE_INTEGER : length; + return value > -1 && value % 1 == 0 && value < length; +} + +/** + * Checks if `value` is a valid array-like length. + * + * **Note:** This function is based on [`ToLength`](http://ecma-international.org/ecma-262/6.0/#sec-tolength). + * + * @private + * @param {*} value The value to check. + * @returns {boolean} Returns `true` if `value` is a valid length, else `false`. + */ +function isLength(value) { + return typeof value == 'number' && value > -1 && value % 1 == 0 && value <= MAX_SAFE_INTEGER; +} + +/** + * A fallback implementation of `Object.keys` which creates an array of the + * own enumerable property names of `object`. + * + * @private + * @param {Object} object The object to query. + * @returns {Array} Returns the array of property names. + */ +function shimKeys(object) { + var props = keysIn(object), + propsLength = props.length, + length = propsLength && object.length; + + var allowIndexes = !!length && isLength(length) && + (isArray(object) || isArguments(object)); + + var index = -1, + result = []; + + while (++index < propsLength) { + var key = props[index]; + if ((allowIndexes && isIndex(key, length)) || hasOwnProperty.call(object, key)) { + result.push(key); + } + } + return result; +} + +/** + * Checks if `value` is the [language type](https://es5.github.io/#x8) of `Object`. + * (e.g. arrays, functions, objects, regexes, `new Number(0)`, and `new String('')`) + * + * @static + * @memberOf _ + * @category Lang + * @param {*} value The value to check. + * @returns {boolean} Returns `true` if `value` is an object, else `false`. + * @example + * + * _.isObject({}); + * // => true + * + * _.isObject([1, 2, 3]); + * // => true + * + * _.isObject(1); + * // => false + */ +function isObject(value) { + // Avoid a V8 JIT bug in Chrome 19-20. + // See https://code.google.com/p/v8/issues/detail?id=2291 for more details. + var type = typeof value; + return !!value && (type == 'object' || type == 'function'); +} + +/** + * Creates an array of the own enumerable property names of `object`. + * + * **Note:** Non-object values are coerced to objects. See the + * [ES spec](http://ecma-international.org/ecma-262/6.0/#sec-object.keys) + * for more details. + * + * @static + * @memberOf _ + * @category Object + * @param {Object} object The object to query. + * @returns {Array} Returns the array of property names. + * @example + * + * function Foo() { + * this.a = 1; + * this.b = 2; + * } + * + * Foo.prototype.c = 3; + * + * _.keys(new Foo); + * // => ['a', 'b'] (iteration order is not guaranteed) + * + * _.keys('hi'); + * // => ['0', '1'] + */ +var keys = !nativeKeys ? shimKeys : function(object) { + var Ctor = object == null ? undefined : object.constructor; + if ((typeof Ctor == 'function' && Ctor.prototype === object) || + (typeof object != 'function' && isArrayLike(object))) { + return shimKeys(object); + } + return isObject(object) ? nativeKeys(object) : []; +}; + +/** + * Creates an array of the own and inherited enumerable property names of `object`. + * + * **Note:** Non-object values are coerced to objects. + * + * @static + * @memberOf _ + * @category Object + * @param {Object} object The object to query. + * @returns {Array} Returns the array of property names. + * @example + * + * function Foo() { + * this.a = 1; + * this.b = 2; + * } + * + * Foo.prototype.c = 3; + * + * _.keysIn(new Foo); + * // => ['a', 'b', 'c'] (iteration order is not guaranteed) + */ +function keysIn(object) { + if (object == null) { + return []; + } + if (!isObject(object)) { + object = Object(object); + } + var length = object.length; + length = (length && isLength(length) && + (isArray(object) || isArguments(object)) && length) || 0; + + var Ctor = object.constructor, + index = -1, + isProto = typeof Ctor == 'function' && Ctor.prototype === object, + result = Array(length), + skipIndexes = length > 0; + + while (++index < length) { + result[index] = (index + ''); + } + for (var key in object) { + if (!(skipIndexes && isIndex(key, length)) && + !(key == 'constructor' && (isProto || !hasOwnProperty.call(object, key)))) { + result.push(key); + } + } + return result; +} + +module.exports = keys; + +},{"lodash._getnative":49,"lodash.isarguments":45,"lodash.isarray":46}],49:[function(require,module,exports){ +/** + * lodash 3.9.1 (Custom Build) + * Build: `lodash modern modularize exports="npm" -o ./` + * Copyright 2012-2015 The Dojo Foundation + * Based on Underscore.js 1.8.3 + * Copyright 2009-2015 Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors + * Available under MIT license + */ + +/** `Object#toString` result references. */ +var funcTag = '[object Function]'; + +/** Used to detect host constructors (Safari > 5). */ +var reIsHostCtor = /^\[object .+?Constructor\]$/; + +/** + * Checks if `value` is object-like. + * + * @private + * @param {*} value The value to check. + * @returns {boolean} Returns `true` if `value` is object-like, else `false`. + */ +function isObjectLike(value) { + return !!value && typeof value == 'object'; +} + +/** Used for native method references. */ +var objectProto = Object.prototype; + +/** Used to resolve the decompiled source of functions. */ +var fnToString = Function.prototype.toString; + +/** Used to check objects for own properties. */ +var hasOwnProperty = objectProto.hasOwnProperty; + +/** + * Used to resolve the [`toStringTag`](http://ecma-international.org/ecma-262/6.0/#sec-object.prototype.tostring) + * of values. + */ +var objToString = objectProto.toString; + +/** Used to detect if a method is native. */ +var reIsNative = RegExp('^' + + fnToString.call(hasOwnProperty).replace(/[\\^$.*+?()[\]{}|]/g, '\\$&') + .replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g, '$1.*?') + '$' +); + +/** + * Gets the native function at `key` of `object`. + * + * @private + * @param {Object} object The object to query. + * @param {string} key The key of the method to get. + * @returns {*} Returns the function if it's native, else `undefined`. + */ +function getNative(object, key) { + var value = object == null ? undefined : object[key]; + return isNative(value) ? value : undefined; +} + +/** + * Checks if `value` is classified as a `Function` object. + * + * @static + * @memberOf _ + * @category Lang + * @param {*} value The value to check. + * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`. + * @example + * + * _.isFunction(_); + * // => true + * + * _.isFunction(/abc/); + * // => false + */ +function isFunction(value) { + // The use of `Object#toString` avoids issues with the `typeof` operator + // in older versions of Chrome and Safari which return 'function' for regexes + // and Safari 8 equivalents which return 'object' for typed array constructors. + return isObject(value) && objToString.call(value) == funcTag; +} + +/** + * Checks if `value` is the [language type](https://es5.github.io/#x8) of `Object`. + * (e.g. arrays, functions, objects, regexes, `new Number(0)`, and `new String('')`) + * + * @static + * @memberOf _ + * @category Lang + * @param {*} value The value to check. + * @returns {boolean} Returns `true` if `value` is an object, else `false`. + * @example + * + * _.isObject({}); + * // => true + * + * _.isObject([1, 2, 3]); + * // => true + * + * _.isObject(1); + * // => false + */ +function isObject(value) { + // Avoid a V8 JIT bug in Chrome 19-20. + // See https://code.google.com/p/v8/issues/detail?id=2291 for more details. + var type = typeof value; + return !!value && (type == 'object' || type == 'function'); +} + +/** + * Checks if `value` is a native function. + * + * @static + * @memberOf _ + * @category Lang + * @param {*} value The value to check. + * @returns {boolean} Returns `true` if `value` is a native function, else `false`. + * @example + * + * _.isNative(Array.prototype.push); + * // => true + * + * _.isNative(_); + * // => false + */ +function isNative(value) { + if (value == null) { + return false; + } + if (isFunction(value)) { + return reIsNative.test(fnToString.call(value)); + } + return isObjectLike(value) && reIsHostCtor.test(value); +} + +module.exports = getNative; + +},{}],50:[function(require,module,exports){ +/** + * lodash 3.0.2 (Custom Build) + * Build: `lodash modern modularize exports="npm" -o ./` + * Copyright 2012-2015 The Dojo Foundation + * Based on Underscore.js 1.8.3 + * Copyright 2009-2015 Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors + * Available under MIT license + */ + +/** + * Checks if `value` is the [language type](https://es5.github.io/#x8) of `Object`. + * (e.g. arrays, functions, objects, regexes, `new Number(0)`, and `new String('')`) + * + * @static + * @memberOf _ + * @category Lang + * @param {*} value The value to check. + * @returns {boolean} Returns `true` if `value` is an object, else `false`. + * @example + * + * _.isObject({}); + * // => true + * + * _.isObject([1, 2, 3]); + * // => true + * + * _.isObject(1); + * // => false + */ +function isObject(value) { + // Avoid a V8 JIT bug in Chrome 19-20. + // See https://code.google.com/p/v8/issues/detail?id=2291 for more details. + var type = typeof value; + return !!value && (type == 'object' || type == 'function'); +} + +module.exports = isObject; + +},{}],51:[function(require,module,exports){ +/** + * lodash 3.0.1 (Custom Build) + * Build: `lodash modern modularize exports="npm" -o ./` + * Copyright 2012-2015 The Dojo Foundation + * Based on Underscore.js 1.8.2 + * Copyright 2009-2015 Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors + * Available under MIT license + */ + +/** `Object#toString` result references. */ +var stringTag = '[object String]'; + +/** + * Checks if `value` is object-like. + * + * @private + * @param {*} value The value to check. + * @returns {boolean} Returns `true` if `value` is object-like, else `false`. + */ +function isObjectLike(value) { + return !!value && typeof value == 'object'; +} + +/** Used for native method references. */ +var objectProto = Object.prototype; + +/** + * Used to resolve the [`toStringTag`](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-object.prototype.tostring) + * of values. + */ +var objToString = objectProto.toString; + +/** + * Checks if `value` is classified as a `String` primitive or object. + * + * @static + * @memberOf _ + * @category Lang + * @param {*} value The value to check. + * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`. + * @example + * + * _.isString('abc'); + * // => true + * + * _.isString(1); + * // => false + */ +function isString(value) { + return typeof value == 'string' || (isObjectLike(value) && objToString.call(value) == stringTag); +} + +module.exports = isString; + +},{}],52:[function(require,module,exports){ +'use strict'; + +var bus = require('framebus'); +var events = require('./lib/events'); +var checkOrigin = require('./lib/check-origin').checkOrigin; + +function BraintreeBus(options) { + options = options || {}; + + this.channel = options.channel; + if (!this.channel) { + throw new Error('Channel ID must be specified'); + } + + this.merchantUrl = options.merchantUrl; + + this._isDestroyed = false; + this._isVerbose = false; + + this._listeners = []; + + this._log('new bus on channel ' + this.channel, [location.href]); +} + +BraintreeBus.prototype.on = function (eventName, originalHandler) { + var namespacedEvent, args; + var handler = originalHandler; + var self = this; + + if (this._isDestroyed) { return; } + + if (this.merchantUrl) { + handler = function () { + if (checkOrigin(this.origin, self.merchantUrl)) { + originalHandler.apply(this, arguments); + } + }; + } + + namespacedEvent = this._namespaceEvent(eventName); + args = Array.prototype.slice.call(arguments); + args[0] = namespacedEvent; + args[1] = handler; + + this._log('on', args); + bus.on.apply(bus, args); + + this._listeners.push({ + eventName: eventName, + handler: handler, + originalHandler: originalHandler + }); +}; + +BraintreeBus.prototype.emit = function (eventName, payload, reply) { + var args; + + if (this._isDestroyed) { return; } + + args = Array.prototype.slice.call(arguments); + args[0] = this._namespaceEvent(eventName); + + this._log('emit', args); + bus.emit.apply(bus, args); +}; + +BraintreeBus.prototype._offDirect = function (eventName, handler) { + var args = Array.prototype.slice.call(arguments); + + if (this._isDestroyed) { return; } + + args[0] = this._namespaceEvent(eventName); + + this._log('off', args); + bus.off.apply(bus, args); +}; + +BraintreeBus.prototype.off = function (eventName, originalHandler) { + var i, listener; + var handler = originalHandler; + + if (this._isDestroyed) { return; } + + if (this.merchantUrl) { + for (i = 0; i < this._listeners.length; i++) { + listener = this._listeners[i]; + + if (listener.originalHandler === originalHandler) { + handler = listener.handler; + } + } + } + + this._offDirect.call(this, eventName, handler); +}; + +BraintreeBus.prototype._namespaceEvent = function (eventName) { + return ['braintree', this.channel, eventName].join(':'); +}; + +BraintreeBus.prototype.teardown = function () { + var listener, i; + + for (i = 0; i < this._listeners.length; i++) { + listener = this._listeners[i]; + this._offDirect(listener.eventName, listener.handler); + } + + this._listeners.length = 0; + + this._isDestroyed = true; +}; + +BraintreeBus.prototype._log = function (functionName, args) { + if (this._isVerbose) { + console.log(functionName, args); + } +}; + +BraintreeBus.events = events; + +module.exports = BraintreeBus; + +},{"./lib/check-origin":53,"./lib/events":54,"framebus":55}],53:[function(require,module,exports){ +'use strict'; + +var BT_ORIGIN_REGEX = /^https:\/\/([a-zA-Z0-9-]+\.)*(braintreepayments|braintreegateway|paypal)\.com(:\d{1,5})?$/; + +function checkOrigin(postMessageOrigin, merchantUrl) { + var merchantOrigin, merchantHost; + var a = document.createElement('a'); + + a.href = merchantUrl; + + if (a.protocol === 'https:') { + merchantHost = a.host.replace(/:443$/, ''); + } else if (a.protocol === 'http:') { + merchantHost = a.host.replace(/:80$/, ''); + } else { + merchantHost = a.host; + } + + merchantOrigin = a.protocol + '//' + merchantHost; + + return merchantOrigin === postMessageOrigin || BT_ORIGIN_REGEX.test(postMessageOrigin); +} + +module.exports = { + checkOrigin: checkOrigin +}; + +},{}],54:[function(require,module,exports){ +'use strict'; + +var i, evnt; +var eventList = [ + 'PAYMENT_METHOD_REQUEST', + 'PAYMENT_METHOD_RECEIVED', + 'PAYMENT_METHOD_GENERATED', + 'PAYMENT_METHOD_NOT_GENERATED', + 'PAYMENT_METHOD_CANCELLED', + 'PAYMENT_METHOD_ERROR', + 'CONFIGURATION_REQUEST', + 'ROOT_METADATA_REQUEST', + 'ERROR', + 'WARNING', + 'UI_POPUP_DID_OPEN', + 'UI_POPUP_DID_CLOSE', + 'UI_POPUP_FORCE_CLOSE', + 'ASYNC_DEPENDENCY_INITIALIZING', + 'ASYNC_DEPENDENCY_READY', + 'USER_FORM_SUBMIT_REQUEST', + 'SEND_ANALYTICS_EVENTS' +]; +var eventEnum = {}; + +for (i = 0; i < eventList.length; i++) { + evnt = eventList[i]; + eventEnum[evnt] = evnt; +} + +module.exports = eventEnum; + +},{}],55:[function(require,module,exports){ +'use strict'; +(function (root, factory) { + if (typeof exports === 'object' && typeof module !== 'undefined') { + module.exports = factory(); + } else if (typeof define === 'function' && define.amd) { + define([], factory); + } else { + root.framebus = factory(); + } +})(this, function () { + var win, framebus; + var popups = []; + var subscribers = {}; + var prefix = '/*framebus*/'; + + function include(popup) { + if (popup == null) { return false; } + if (popup.Window == null) { return false; } + if (popup.constructor !== popup.Window) { return false; } + + popups.push(popup); + return true; + } + + function target(origin) { + var key; + var targetedFramebus = {}; + + for (key in framebus) { + if (!framebus.hasOwnProperty(key)) { continue; } + + targetedFramebus[key] = framebus[key]; + } + + targetedFramebus._origin = origin || '*'; + + return targetedFramebus; + } + + function publish(event) { + var payload, args; + var origin = _getOrigin(this); + + if (_isntString(event)) { return false; } + if (_isntString(origin)) { return false; } + + args = Array.prototype.slice.call(arguments, 1); + + payload = _packagePayload(event, args, origin); + if (payload === false) { return false; } + + _broadcast(win.top, payload, origin); + + return true; + } + + function subscribe(event, fn) { + var origin = _getOrigin(this); + + if (_subscriptionArgsInvalid(event, fn, origin)) { return false; } + + subscribers[origin] = subscribers[origin] || {}; + subscribers[origin][event] = subscribers[origin][event] || []; + subscribers[origin][event].push(fn); + + return true; + } + + function unsubscribe(event, fn) { + var i, subscriberList; + var origin = _getOrigin(this); + + if (_subscriptionArgsInvalid(event, fn, origin)) { return false; } + + subscriberList = subscribers[origin] && subscribers[origin][event]; + if (!subscriberList) { return false; } + + for (i = 0; i < subscriberList.length; i++) { + if (subscriberList[i] === fn) { + subscriberList.splice(i, 1); + return true; + } + } + + return false; + } + + function _getOrigin(scope) { + return scope && scope._origin || '*'; + } + + function _isntString(string) { + return typeof string !== 'string'; + } + + function _packagePayload(event, args, origin) { + var packaged = false; + var payload = { + event: event, + origin: origin + }; + var reply = args[args.length - 1]; + + if (typeof reply === 'function') { + payload.reply = _subscribeReplier(reply, origin); + args = args.slice(0, -1); + } + + payload.args = args; + + try { + packaged = prefix + JSON.stringify(payload); + } catch (e) { + throw new Error('Could not stringify event: ' + e.message); + } + return packaged; + } + + function _unpackPayload(e) { + var payload, replyOrigin, replySource, replyEvent; + + if (e.data.slice(0, prefix.length) !== prefix) { return false; } + + try { + payload = JSON.parse(e.data.slice(prefix.length)); + } catch (err) { + return false; + } + + if (payload.reply != null) { + replyOrigin = e.origin; + replySource = e.source; + replyEvent = payload.reply; + + payload.reply = function reply(data) { + var replyPayload = _packagePayload(replyEvent, [data], replyOrigin); + if (replyPayload === false) { return false; } + + replySource.postMessage(replyPayload, replyOrigin); + }; + + payload.args.push(payload.reply); + } + + return payload; + } + + function _attach(w) { + if (win) { return; } + win = w || window; + + if (win.addEventListener) { + win.addEventListener('message', _onmessage, false); + } else if (win.attachEvent) { + win.attachEvent('onmessage', _onmessage); + } else if (win.onmessage === null) { + win.onmessage = _onmessage; + } else { + win = null; + } + } + + function _uuid() { + return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) { + var r = Math.random() * 16 | 0; + var v = c === 'x' ? r : r & 0x3 | 0x8; + return v.toString(16); + }); + } + + function _onmessage(e) { + var payload; + if (_isntString(e.data)) { return; } + + payload = _unpackPayload(e); + if (!payload) { return; } + + _dispatch('*', payload.event, payload.args, e); + _dispatch(e.origin, payload.event, payload.args, e); + _broadcastPopups(e.data, payload.origin, e.source); + } + + function _dispatch(origin, event, args, e) { + var i; + if (!subscribers[origin]) { return; } + if (!subscribers[origin][event]) { return; } + + for (i = 0; i < subscribers[origin][event].length; i++) { + subscribers[origin][event][i].apply(e, args); + } + } + + function _broadcast(frame, payload, origin) { + var i; + + try { + frame.postMessage(payload, origin); + } catch (_) { return; } + + if (frame.opener && frame.opener !== frame && !frame.opener.closed && frame.opener !== win) { + _broadcast(frame.opener.top, payload, origin); + } + + for (i = 0; i < frame.frames.length; i++) { + _broadcast(frame.frames[i], payload, origin); + } + } + + function _broadcastPopups(payload, origin, source) { + var i, popup; + + for (i = popups.length - 1; i >= 0; i--) { + popup = popups[i]; + + if (popup.closed === true) { + popups = popups.slice(i, 1); + } else if (source !== popup) { + _broadcast(popup.top, payload, origin); + } + } + } + + function _subscribeReplier(fn, origin) { + var uuid = _uuid(); + + function replier(d, o) { + fn(d, o); + framebus.target(origin).unsubscribe(uuid, replier); + } + + framebus.target(origin).subscribe(uuid, replier); + return uuid; + } + + function _subscriptionArgsInvalid(event, fn, origin) { + if (_isntString(event)) { return true; } + if (typeof fn !== 'function') { return true; } + if (_isntString(origin)) { return true; } + + return false; + } + + _attach(); + + framebus = { + target: target, + include: include, + publish: publish, + pub: publish, + trigger: publish, + emit: publish, + subscribe: subscribe, + sub: subscribe, + on: subscribe, + unsubscribe: unsubscribe, + unsub: unsubscribe, + off: unsubscribe + }; + + return framebus; +}); + +},{}],56:[function(require,module,exports){ +'use strict'; + +var Coinbase = require('./lib/coinbase'); + +function create(options) { + return new Coinbase(options); +} + +module.exports = {create: create}; + +},{"./lib/coinbase":59}],57:[function(require,module,exports){ +(function (global){ +'use strict'; + +function iOSSafariVersion(userAgent) { + userAgent = userAgent || global.navigator.userAgent; + if (!/AppleWebKit\//.test(userAgent)) { + return null; + } + if (!/Mobile\//.test(userAgent)) { + return null; + } + + return userAgent.replace(/.* OS ([0-9_]+) like Mac OS X.*/, '$1').replace(/_/g, '.'); +} + +function ieVersion(userAgent) { + userAgent = userAgent || global.navigator.userAgent; + var result = null; + var match = /MSIE.(\d+)/.exec(userAgent); + + if (/Trident/.test(userAgent)) { + result = 11; + } + + if (match) { + result = parseInt(match[1], 10); + } + + return result; +} + +function androidVersion(UA) { + UA = UA || global.navigator.userAgent; + if (!/Android/.test(UA)) { return null; } + + return UA.replace(/^.* Android ([0-9\.]+).*$/,'$1'); +} + +module.exports = { + ieVersion: ieVersion, + iOSSafariVersion: iOSSafariVersion, + androidVersion: androidVersion +}; + +}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) +},{}],58:[function(require,module,exports){ +'use strict'; + +var busEvents = require('braintree-bus').events; + +function tokenize(err, payload, coinbase) { + if (err) { + // TODO: make payload in line with onError() + coinbase.bus.emit(busEvents.ERROR, err.error); + coinbase._sendAnalyticsEvent('generate.nonce.failed'); + return; + } + + coinbase.bus.emit(busEvents.PAYMENT_METHOD_GENERATED, payload); + coinbase._sendAnalyticsEvent('generate.nonce.succeeded'); +} + +module.exports = {tokenize: tokenize}; + +},{"braintree-bus":67}],59:[function(require,module,exports){ +(function (global){ +'use strict'; + +var utils = require('braintree-utilities'); +var Destructor = require('destructor'); +var DOMComposer = require('./dom/composer'); +var urlComposer = require('./url-composer'); +var callbacks = require('./callbacks'); +var constants = require('./constants'); +var detector = require('./detector'); +var Bus = require('braintree-bus'); + +function _getPopupParams(options) { + return { + clientId: options.configuration.coinbase.clientId, + redirectUrl: options.configuration.coinbase.redirectUrl, + scopes: options.configuration.coinbase.scopes || constants.SCOPES, + meta: { + authorizations_merchant_account: options.configuration.coinbase.merchantAccount || '' + } + }; +} + +function _error(bus) { + return function (message, type) { + bus.emit(Bus.events.ERROR, {type: type, message: message}); + } +} + +function _optionsAreValid(options, bus) { + var cbOptions = (options || {}).coinbase; + var busError = _error(bus); + + if (options.apiClient == null) { + busError('settings.apiClient is required for coinbase', constants.CONFIGURATION_ERROR); + } else if (!options.configuration.coinbaseEnabled) { + busError('Coinbase is not enabled for your merchant account', constants.CONFIGURATION_ERROR); + } else if (!cbOptions || (!cbOptions.container && !cbOptions.button)) { + busError('Either options.coinbase.container or options.coinbase.button is required for Coinbase integrations', constants.CONFIGURATION_ERROR); + } else if (cbOptions.container && cbOptions.button) { + busError('options.coinbase.container and options.coinbase.button are mutually exclusive', constants.CONFIGURATION_ERROR); + } else if (!detector.isSupportedBrowser()) { + busError('Coinbase is not supported by your browser. Please consider upgrading', constants.UNSUPPORTED_BROWSER_ERROR); + } else { + return true; + } + + return false; +} + +function Coinbase(options) { + var context, busOptions; + + this.destructor = new Destructor(); + + this.channel = options.channel; + + busOptions = {channel: this.channel}; + + try { + if (options.coinbase.container) { + busOptions.merchantUrl = global.location.href; + } + } catch (e) {} + + this.bus = options.bus || new Bus(busOptions); + + this.canCreateIntegration = _optionsAreValid(options, this.bus); + if (!this.canCreateIntegration) { + return; + } + + this.buttonId = options.coinbase.button || constants.BUTTON_ID; + this.apiClient = options.apiClient; + this.assetsUrl = options.configuration.assetsUrl; + this.environment = options.configuration.coinbase.environment; + this._onOAuthSuccess = utils.bind(this._onOAuthSuccess, this); + this._handleButtonClick = utils.bind(this._handleButtonClick, this); + this.popupParams = _getPopupParams(options); + this.redirectDoneInterval = null; + + if (options.coinbase.container) { + context = utils.normalizeElement(options.coinbase.container); + this._insertFrame(context); + } else { + global.braintreeCoinbasePopupCallback = this._onOAuthSuccess; + + context = document.body; + utils.addEventListener(context, 'click', this._handleButtonClick); + + this._sendAnalyticsEvent('initialized'); + + this.destructor.registerFunctionForTeardown(utils.bind(function () { + this._closePopup(); + }, this)); + + this.bus.on(constants.TEARDOWN_EVENT, utils.bind(this.destructor.teardown, this.destructor)); + } +} + +Coinbase.prototype._sendAnalyticsEvent = function (eventName) { + var namespace = this.apiClient.integration + '.web.coinbase.'; + this.apiClient.sendAnalyticsEvents(namespace + eventName); +}; + +Coinbase.prototype._insertFrame = function (container) { + var frame = DOMComposer.createFrame({channel: this.channel}); + + this.bus.emit(Bus.events.ASYNC_DEPENDENCY_INITIALIZING); + + container.appendChild(frame); + this.destructor.registerFunctionForTeardown(function () { + container.removeChild(frame); + }); + + // Delayed to make sure browser caches are busted. + setTimeout(utils.bind(function () { + frame.src = this.assetsUrl + '/coinbase/' + constants.VERSION + '/coinbase-frame.html#' + this.channel; + }, this), 0); +}; + +Coinbase.prototype._onOAuthSuccess = function (data) { + if (!data.code) { + this._sendAnalyticsEvent('popup.denied'); + this._closePopup(); + return; + } + + this.bus.emit('coinbase:view:navigate', 'loading'); + this._sendAnalyticsEvent('popup.authorized'); + + this.apiClient.tokenizeCoinbase({ code: data.code, query: urlComposer.getQueryString() }, utils.bind(function (err, payload) { + callbacks.tokenize.apply(null, [err, payload, this]); + }, this)); + + this._closePopup(); +}; + +Coinbase.prototype._clearPollForRedirectDone = function () { + if (this.redirectDoneInterval) { + clearInterval(this.redirectDoneInterval); + this.redirectDoneInterval = null; + } +}; + +Coinbase.prototype._closePopup = function (popup) { + popup = popup || this.popup; + + if (popup == null) { return; } + + if (detector.shouldCloseFromParent()) { + popup.close(); + } + + this._popupCleanup(); +}; + +Coinbase.prototype._popupCleanup = function () { + this._clearPollForRedirectDone(); + this.bus.emit(Bus.events.UI_POPUP_DID_CLOSE, {source: constants.INTEGRATION_NAME}); +}; + +Coinbase.prototype._pollForRedirectDone = function (popup) { + var interval = setInterval(utils.bind(function () { + var code; + + if (popup == null || popup.closed) { + this._sendAnalyticsEvent('popup.aborted'); + this._popupCleanup(); + return; + } + + try { + if (popup.location.href === 'about:blank') { throw new Error('Not finished loading'); } + code = utils.decodeQueryString(popup.location.search.replace(/^\?/, '')).code; + } catch (e) { + return; + } + + this._onOAuthSuccess({ code: code }); + }, this), 100); + + this.redirectDoneInterval = interval; + return interval; +}; + +Coinbase.prototype._openPopup = function () { + var popup; + + this._sendAnalyticsEvent('popup.started'); + + popup = DOMComposer.createPopup(urlComposer.compose(this._getOAuthBaseUrl(), this.popupParams)); + popup.focus(); + + this._pollForRedirectDone(popup); + + this.bus.emit(Bus.events.UI_POPUP_DID_OPEN, {source: constants.INTEGRATION_NAME}); + this.bus.on(Bus.events.UI_POPUP_FORCE_CLOSE, function (payload) { + if (payload.target === constants.INTEGRATION_NAME) { + popup.close(); + } + }); + + this.popup = popup; +}; + +Coinbase.prototype._getOAuthBaseUrl = function () { + var baseUrl; + + if (this.environment === 'shared_sandbox') { + baseUrl = constants.SANDBOX_OAUTH_BASE_URL; + } else { + baseUrl = constants.PRODUCTION_OAUTH_BASE_URL; + } + + return baseUrl; +}; + +Coinbase.prototype._handleButtonClick = function (event) { + var target = event.target || event.srcElement; + + while (true) { + if (target == null) { return; } + if (target === event.currentTarget) { return; } + if (target.id === this.buttonId) { break; } + + target = target.parentNode; + } + + if (event && event.preventDefault) { + event.preventDefault(); + } else { + event.returnValue = false; + } + + this._openPopup(); +}; + +Coinbase.prototype.teardown = function (done) { + var self = this; + + if (!this.canCreateIntegration) { + done(null); + return; + } + + this.bus.emit(constants.TEARDOWN_EVENT, function () { + self.destructor.teardown(function (err) { + if (err) { return done(err); } + + self.bus.teardown(); + done(null); + }); + }); +}; + +module.exports = Coinbase; + +}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) +},{"./callbacks":58,"./constants":60,"./detector":61,"./dom/composer":63,"./url-composer":66,"braintree-bus":67,"braintree-utilities":79,"destructor":80}],60:[function(require,module,exports){ +'use strict'; + +module.exports = { + PRODUCTION_OAUTH_BASE_URL: 'https://coinbase.com', + SANDBOX_OAUTH_BASE_URL: 'https://sandbox.coinbase.com', + ORIGIN_URL: 'https://www.coinbase.com', + FRAME_NAME: 'braintree-coinbase-frame', + POPUP_NAME: 'coinbase', + BUTTON_ID: 'bt-coinbase-button', + SCOPES: 'send', + VERSION: "0.3.1", + INTEGRATION_NAME: 'Coinbase', + CONFIGURATION_ERROR: 'CONFIGURATION', + UNSUPPORTED_BROWSER_ERROR: 'UNSUPPORTED_BROWSER', + TEARDOWN_EVENT: 'coinbase:TEARDOWN' +}; + +},{}],61:[function(require,module,exports){ +'use strict'; + +var browser = require('./browser'); + +function isSupportedBrowser() { + var version = browser.ieVersion(); + return !version || (version > 8); +} + +function shouldDisplayLollipopClose() { + var version = browser.androidVersion(); + if (version == null) { return false; } + + return /^5/.test(version); +} + +function shouldCloseFromParent() { + return !(shouldDisplayLollipopClose() || shouldDisplayIOSClose()); +} + +function shouldDisplayIOSClose() { + var version = browser.iOSSafariVersion(); + if (version == null) { return false; } + + return /^8\.0/.test(version) || /^8\.1$/.test(version); +} + +module.exports = { + isSupportedBrowser: isSupportedBrowser, + shouldCloseFromParent: shouldCloseFromParent, + shouldDisplayIOSClose: shouldDisplayIOSClose, + shouldDisplayLollipopClose: shouldDisplayLollipopClose +}; + +},{"./browser":57}],62:[function(require,module,exports){ +'use strict'; + +function createButton(config) { + var button = document.createElement('button'); + + config = config || {}; + + button.id = config.id || 'coinbase-button'; + button.style.backgroundColor = config.backgroundColor || '#EEE'; + button.style.color = config.color || '#4597C3'; + button.style.border = config.border || '0'; + button.style.borderRadius = config.borderRadius || '6px'; + button.style.padding = config.padding || '12px'; + button.innerHTML = config.innerHTML || 'coinbase'; + + return button; +} + +module.exports = { create: createButton }; + +},{}],63:[function(require,module,exports){ +'use strict'; + +var popup = require('./popup'); +var button = require('./button'); +var frame = require('./frame'); + +module.exports = { + createButton: button.create, + createPopup: popup.create, + createFrame: frame.create +}; + +},{"./button":62,"./frame":64,"./popup":65}],64:[function(require,module,exports){ +'use strict'; + +var constants = require('../constants'); +var iframer = require('iframer'); + +function createFrame(config) { + return iframer({ + name: constants.FRAME_NAME, + height: '70px', + width: '100%', + style: { + padding: 0, + margin: 0, + border: 0, + outline: 'none' + } + }); +} + +module.exports = { create: createFrame }; + +},{"../constants":60,"iframer":83}],65:[function(require,module,exports){ +(function (global){ +'use strict'; + +var constants = require('../constants'); + +function _stringifyParams(payload) { + var params = []; + + for (var param in payload) { + if (payload.hasOwnProperty(param)) { + params.push([param, payload[param]].join('=')); + } + } + + return params.join(','); +} + +function _getParams() { + var baseWidth = 850; + var baseHeight = 600; + + return _stringifyParams({ + width: baseWidth, + height: baseHeight, + left: (screen.width - baseWidth) / 2, + top: (screen.height - baseHeight) / 4 + }); +} + +function createPopup(url) { + return global.open(url, constants.POPUP_NAME, _getParams()); +} + +module.exports = { create: createPopup }; + +}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) +},{"../constants":60}],66:[function(require,module,exports){ +'use strict'; + +var constants = require('./constants'); + +function getQueryString() { + return 'version=' + constants.VERSION; +} + +function compose(baseUrl, params) { + var url = baseUrl + '/oauth/authorize?response_type=code'; + var redirectUri = params.redirectUrl + '?' + getQueryString(); + + url += '&redirect_uri=' + encodeURIComponent(redirectUri); + url += '&client_id=' + params.clientId; + + if (params.scopes) { + url += '&scope=' + encodeURIComponent(params.scopes); + } + + if (params.meta) { + for (var key in params.meta) { + if (params.meta.hasOwnProperty(key)) { + url += '&meta[' + encodeURIComponent(key) + ']=' + encodeURIComponent(params.meta[key]); + } + } + } + + return url; +} + +module.exports = { + compose: compose, + getQueryString: getQueryString +}; + +},{"./constants":60}],67:[function(require,module,exports){ +arguments[4][52][0].apply(exports,arguments) +},{"./lib/check-origin":68,"./lib/events":69,"dup":52,"framebus":70}],68:[function(require,module,exports){ +arguments[4][53][0].apply(exports,arguments) +},{"dup":53}],69:[function(require,module,exports){ +arguments[4][54][0].apply(exports,arguments) +},{"dup":54}],70:[function(require,module,exports){ +arguments[4][55][0].apply(exports,arguments) +},{"dup":55}],71:[function(require,module,exports){ +arguments[4][35][0].apply(exports,arguments) +},{"dup":35}],72:[function(require,module,exports){ +arguments[4][36][0].apply(exports,arguments) +},{"dup":36}],73:[function(require,module,exports){ +arguments[4][22][0].apply(exports,arguments) +},{"dup":22}],74:[function(require,module,exports){ +arguments[4][38][0].apply(exports,arguments) +},{"dup":38}],75:[function(require,module,exports){ +arguments[4][39][0].apply(exports,arguments) +},{"dup":39}],76:[function(require,module,exports){ +arguments[4][40][0].apply(exports,arguments) +},{"dup":40}],77:[function(require,module,exports){ +arguments[4][41][0].apply(exports,arguments) +},{"./array":71,"dup":41}],78:[function(require,module,exports){ +arguments[4][42][0].apply(exports,arguments) +},{"dup":42}],79:[function(require,module,exports){ +arguments[4][43][0].apply(exports,arguments) +},{"./lib/array":71,"./lib/base64":72,"./lib/dom":73,"./lib/events":74,"./lib/fn":75,"./lib/string":76,"./lib/url":77,"./lib/uuid":78,"dup":43}],80:[function(require,module,exports){ +'use strict'; + +var batchExecuteFunctions = require('batch-execute-functions'); +// Reach into lib for isFunction. This lib requires a DOM and cannot be +// tested otherwise +var fnUtil = require('braintree-utilities/lib/fn'); + +function Destructor() { + this._teardownRegistry = []; +} + +Destructor.prototype.registerFunctionForTeardown = function (fn) { + if (fnUtil.isFunction(fn)) { + this._teardownRegistry.push(fn); + } +}; + +Destructor.prototype.teardown = function (callback) { + batchExecuteFunctions(this._teardownRegistry, fnUtil.bind(function (err) { + this._teardownRegistry = []; + + if (fnUtil.isFunction(callback)) { + callback(err); + } + }, this)); +}; + +module.exports = Destructor; + +},{"batch-execute-functions":81,"braintree-utilities/lib/fn":82}],81:[function(require,module,exports){ +'use strict'; + +function call(fn, callback) { + var isSync = fn.length === 0; + var wrappedCallback; + + if (isSync) { + fn(); + callback(null); + } else { + wrappedCallback = once(callback); + fn(wrappedCallback); + } +} + +function once(fn) { + var called = false; + return function () { + if (!called) { + called = true; + fn.apply(this, arguments); + } + }; +} + +module.exports = function (functions, callback) { + var length = functions.length; + var remaining = length; + + if (length === 0) { + callback(null); + return; + } + + for (var i = 0; i < length; i++) { + call(functions[i], function (err) { + if (err) { + callback(err); + return; + } + + remaining -= 1; + if (remaining === 0) { + callback(null); + } + }); + } +}; + +},{}],82:[function(require,module,exports){ +arguments[4][39][0].apply(exports,arguments) +},{"dup":39}],83:[function(require,module,exports){ +'use strict'; + +var assign = require('lodash.assign'); +var isString = require('lodash.isstring'); +var setAttributes = require('setattributes'); +var defaultAttributes = require('./lib/default-attributes'); + +module.exports = function createFrame(options) { + var iframe = document.createElement('iframe'); + var config = assign({}, defaultAttributes, options); + + if (config.style && !isString(config.style)) { + assign(iframe.style, config.style); + delete config.style; + } + + setAttributes(iframe, config); + + if (!iframe.getAttribute('id')) { + iframe.id = iframe.name; + } + + return iframe; +}; + +},{"./lib/default-attributes":84,"lodash.assign":85,"lodash.isstring":96,"setattributes":97}],84:[function(require,module,exports){ +module.exports={ + "src": "about:blank", + "frameBorder": 0, + "allowtransparency": true, + "scrolling": "no" +} + +},{}],85:[function(require,module,exports){ +/** + * lodash 3.2.0 (Custom Build) + * Build: `lodash modern modularize exports="npm" -o ./` + * Copyright 2012-2015 The Dojo Foundation + * Based on Underscore.js 1.8.3 + * Copyright 2009-2015 Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors + * Available under MIT license + */ +var baseAssign = require('lodash._baseassign'), + createAssigner = require('lodash._createassigner'), + keys = require('lodash.keys'); + +/** + * A specialized version of `_.assign` for customizing assigned values without + * support for argument juggling, multiple sources, and `this` binding `customizer` + * functions. + * + * @private + * @param {Object} object The destination object. + * @param {Object} source The source object. + * @param {Function} customizer The function to customize assigned values. + * @returns {Object} Returns `object`. + */ +function assignWith(object, source, customizer) { + var index = -1, + props = keys(source), + length = props.length; + + while (++index < length) { + var key = props[index], + value = object[key], + result = customizer(value, source[key], key, object, source); + + if ((result === result ? (result !== value) : (value === value)) || + (value === undefined && !(key in object))) { + object[key] = result; + } + } + return object; +} + +/** + * Assigns own enumerable properties of source object(s) to the destination + * object. Subsequent sources overwrite property assignments of previous sources. + * If `customizer` is provided it is invoked to produce the assigned values. + * The `customizer` is bound to `thisArg` and invoked with five arguments: + * (objectValue, sourceValue, key, object, source). + * + * **Note:** This method mutates `object` and is based on + * [`Object.assign`](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-object.assign). + * + * @static + * @memberOf _ + * @alias extend + * @category Object + * @param {Object} object The destination object. + * @param {...Object} [sources] The source objects. + * @param {Function} [customizer] The function to customize assigned values. + * @param {*} [thisArg] The `this` binding of `customizer`. + * @returns {Object} Returns `object`. + * @example + * + * _.assign({ 'user': 'barney' }, { 'age': 40 }, { 'user': 'fred' }); + * // => { 'user': 'fred', 'age': 40 } + * + * // using a customizer callback + * var defaults = _.partialRight(_.assign, function(value, other) { + * return _.isUndefined(value) ? other : value; + * }); + * + * defaults({ 'user': 'barney' }, { 'age': 36 }, { 'user': 'fred' }); + * // => { 'user': 'barney', 'age': 36 } + */ +var assign = createAssigner(function(object, source, customizer) { + return customizer + ? assignWith(object, source, customizer) + : baseAssign(object, source); +}); + +module.exports = assign; + +},{"lodash._baseassign":86,"lodash._createassigner":88,"lodash.keys":92}],86:[function(require,module,exports){ +/** + * lodash 3.2.0 (Custom Build) + * Build: `lodash modern modularize exports="npm" -o ./` + * Copyright 2012-2015 The Dojo Foundation + * Based on Underscore.js 1.8.3 + * Copyright 2009-2015 Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors + * Available under MIT license + */ +var baseCopy = require('lodash._basecopy'), + keys = require('lodash.keys'); + +/** + * The base implementation of `_.assign` without support for argument juggling, + * multiple sources, and `customizer` functions. + * + * @private + * @param {Object} object The destination object. + * @param {Object} source The source object. + * @returns {Object} Returns `object`. + */ +function baseAssign(object, source) { + return source == null + ? object + : baseCopy(source, keys(source), object); +} + +module.exports = baseAssign; + +},{"lodash._basecopy":87,"lodash.keys":92}],87:[function(require,module,exports){ +/** + * lodash 3.0.1 (Custom Build) + * Build: `lodash modern modularize exports="npm" -o ./` + * Copyright 2012-2015 The Dojo Foundation + * Based on Underscore.js 1.8.3 + * Copyright 2009-2015 Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors + * Available under MIT license + */ + +/** + * Copies properties of `source` to `object`. + * + * @private + * @param {Object} source The object to copy properties from. + * @param {Array} props The property names to copy. + * @param {Object} [object={}] The object to copy properties to. + * @returns {Object} Returns `object`. + */ +function baseCopy(source, props, object) { + object || (object = {}); + + var index = -1, + length = props.length; + + while (++index < length) { + var key = props[index]; + object[key] = source[key]; + } + return object; +} + +module.exports = baseCopy; + +},{}],88:[function(require,module,exports){ +/** + * lodash 3.1.1 (Custom Build) + * Build: `lodash modern modularize exports="npm" -o ./` + * Copyright 2012-2015 The Dojo Foundation + * Based on Underscore.js 1.8.3 + * Copyright 2009-2015 Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors + * Available under MIT license + */ +var bindCallback = require('lodash._bindcallback'), + isIterateeCall = require('lodash._isiterateecall'), + restParam = require('lodash.restparam'); + +/** + * Creates a function that assigns properties of source object(s) to a given + * destination object. + * + * **Note:** This function is used to create `_.assign`, `_.defaults`, and `_.merge`. + * + * @private + * @param {Function} assigner The function to assign values. + * @returns {Function} Returns the new assigner function. + */ +function createAssigner(assigner) { + return restParam(function(object, sources) { + var index = -1, + length = object == null ? 0 : sources.length, + customizer = length > 2 ? sources[length - 2] : undefined, + guard = length > 2 ? sources[2] : undefined, + thisArg = length > 1 ? sources[length - 1] : undefined; + + if (typeof customizer == 'function') { + customizer = bindCallback(customizer, thisArg, 5); + length -= 2; + } else { + customizer = typeof thisArg == 'function' ? thisArg : undefined; + length -= (customizer ? 1 : 0); + } + if (guard && isIterateeCall(sources[0], sources[1], guard)) { + customizer = length < 3 ? undefined : customizer; + length = 1; + } + while (++index < length) { + var source = sources[index]; + if (source) { + assigner(object, source, customizer); + } + } + return object; + }); +} + +module.exports = createAssigner; + +},{"lodash._bindcallback":89,"lodash._isiterateecall":90,"lodash.restparam":91}],89:[function(require,module,exports){ +/** + * lodash 3.0.1 (Custom Build) + * Build: `lodash modern modularize exports="npm" -o ./` + * Copyright 2012-2015 The Dojo Foundation + * Based on Underscore.js 1.8.3 + * Copyright 2009-2015 Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors + * Available under MIT license + */ + +/** + * A specialized version of `baseCallback` which only supports `this` binding + * and specifying the number of arguments to provide to `func`. + * + * @private + * @param {Function} func The function to bind. + * @param {*} thisArg The `this` binding of `func`. + * @param {number} [argCount] The number of arguments to provide to `func`. + * @returns {Function} Returns the callback. + */ +function bindCallback(func, thisArg, argCount) { + if (typeof func != 'function') { + return identity; + } + if (thisArg === undefined) { + return func; + } + switch (argCount) { + case 1: return function(value) { + return func.call(thisArg, value); + }; + case 3: return function(value, index, collection) { + return func.call(thisArg, value, index, collection); + }; + case 4: return function(accumulator, value, index, collection) { + return func.call(thisArg, accumulator, value, index, collection); + }; + case 5: return function(value, other, key, object, source) { + return func.call(thisArg, value, other, key, object, source); + }; + } + return function() { + return func.apply(thisArg, arguments); + }; +} + +/** + * This method returns the first argument provided to it. + * + * @static + * @memberOf _ + * @category Utility + * @param {*} value Any value. + * @returns {*} Returns `value`. + * @example + * + * var object = { 'user': 'fred' }; + * + * _.identity(object) === object; + * // => true + */ +function identity(value) { + return value; +} + +module.exports = bindCallback; + +},{}],90:[function(require,module,exports){ +/** + * lodash 3.0.9 (Custom Build) + * Build: `lodash modern modularize exports="npm" -o ./` + * Copyright 2012-2015 The Dojo Foundation + * Based on Underscore.js 1.8.3 + * Copyright 2009-2015 Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors + * Available under MIT license + */ + +/** Used to detect unsigned integer values. */ +var reIsUint = /^\d+$/; + +/** + * Used as the [maximum length](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-number.max_safe_integer) + * of an array-like value. + */ +var MAX_SAFE_INTEGER = 9007199254740991; + +/** + * The base implementation of `_.property` without support for deep paths. + * + * @private + * @param {string} key The key of the property to get. + * @returns {Function} Returns the new function. + */ +function baseProperty(key) { + return function(object) { + return object == null ? undefined : object[key]; + }; +} + +/** + * Gets the "length" property value of `object`. + * + * **Note:** This function is used to avoid a [JIT bug](https://bugs.webkit.org/show_bug.cgi?id=142792) + * that affects Safari on at least iOS 8.1-8.3 ARM64. + * + * @private + * @param {Object} object The object to query. + * @returns {*} Returns the "length" value. + */ +var getLength = baseProperty('length'); + +/** + * Checks if `value` is array-like. + * + * @private + * @param {*} value The value to check. + * @returns {boolean} Returns `true` if `value` is array-like, else `false`. + */ +function isArrayLike(value) { + return value != null && isLength(getLength(value)); +} + +/** + * Checks if `value` is a valid array-like index. + * + * @private + * @param {*} value The value to check. + * @param {number} [length=MAX_SAFE_INTEGER] The upper bounds of a valid index. + * @returns {boolean} Returns `true` if `value` is a valid index, else `false`. + */ +function isIndex(value, length) { + value = (typeof value == 'number' || reIsUint.test(value)) ? +value : -1; + length = length == null ? MAX_SAFE_INTEGER : length; + return value > -1 && value % 1 == 0 && value < length; +} + +/** + * Checks if the provided arguments are from an iteratee call. + * + * @private + * @param {*} value The potential iteratee value argument. + * @param {*} index The potential iteratee index or key argument. + * @param {*} object The potential iteratee object argument. + * @returns {boolean} Returns `true` if the arguments are from an iteratee call, else `false`. + */ +function isIterateeCall(value, index, object) { + if (!isObject(object)) { + return false; + } + var type = typeof index; + if (type == 'number' + ? (isArrayLike(object) && isIndex(index, object.length)) + : (type == 'string' && index in object)) { + var other = object[index]; + return value === value ? (value === other) : (other !== other); + } + return false; +} + +/** + * Checks if `value` is a valid array-like length. + * + * **Note:** This function is based on [`ToLength`](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-tolength). + * + * @private + * @param {*} value The value to check. + * @returns {boolean} Returns `true` if `value` is a valid length, else `false`. + */ +function isLength(value) { + return typeof value == 'number' && value > -1 && value % 1 == 0 && value <= MAX_SAFE_INTEGER; +} + +/** + * Checks if `value` is the [language type](https://es5.github.io/#x8) of `Object`. + * (e.g. arrays, functions, objects, regexes, `new Number(0)`, and `new String('')`) + * + * @static + * @memberOf _ + * @category Lang + * @param {*} value The value to check. + * @returns {boolean} Returns `true` if `value` is an object, else `false`. + * @example + * + * _.isObject({}); + * // => true + * + * _.isObject([1, 2, 3]); + * // => true + * + * _.isObject(1); + * // => false + */ +function isObject(value) { + // Avoid a V8 JIT bug in Chrome 19-20. + // See https://code.google.com/p/v8/issues/detail?id=2291 for more details. + var type = typeof value; + return !!value && (type == 'object' || type == 'function'); +} + +module.exports = isIterateeCall; + +},{}],91:[function(require,module,exports){ +/** + * lodash 3.6.1 (Custom Build) + * Build: `lodash modern modularize exports="npm" -o ./` + * Copyright 2012-2015 The Dojo Foundation + * Based on Underscore.js 1.8.3 + * Copyright 2009-2015 Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors + * Available under MIT license + */ + +/** Used as the `TypeError` message for "Functions" methods. */ +var FUNC_ERROR_TEXT = 'Expected a function'; + +/* Native method references for those with the same name as other `lodash` methods. */ +var nativeMax = Math.max; + +/** + * Creates a function that invokes `func` with the `this` binding of the + * created function and arguments from `start` and beyond provided as an array. + * + * **Note:** This method is based on the [rest parameter](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/rest_parameters). + * + * @static + * @memberOf _ + * @category Function + * @param {Function} func The function to apply a rest parameter to. + * @param {number} [start=func.length-1] The start position of the rest parameter. + * @returns {Function} Returns the new function. + * @example + * + * var say = _.restParam(function(what, names) { + * return what + ' ' + _.initial(names).join(', ') + + * (_.size(names) > 1 ? ', & ' : '') + _.last(names); + * }); + * + * say('hello', 'fred', 'barney', 'pebbles'); + * // => 'hello fred, barney, & pebbles' + */ +function restParam(func, start) { + if (typeof func != 'function') { + throw new TypeError(FUNC_ERROR_TEXT); + } + start = nativeMax(start === undefined ? (func.length - 1) : (+start || 0), 0); + return function() { + var args = arguments, + index = -1, + length = nativeMax(args.length - start, 0), + rest = Array(length); + + while (++index < length) { + rest[index] = args[start + index]; + } + switch (start) { + case 0: return func.call(this, rest); + case 1: return func.call(this, args[0], rest); + case 2: return func.call(this, args[0], args[1], rest); + } + var otherArgs = Array(start + 1); + index = -1; + while (++index < start) { + otherArgs[index] = args[index]; + } + otherArgs[start] = rest; + return func.apply(this, otherArgs); + }; +} + +module.exports = restParam; + +},{}],92:[function(require,module,exports){ +arguments[4][48][0].apply(exports,arguments) +},{"dup":48,"lodash._getnative":93,"lodash.isarguments":94,"lodash.isarray":95}],93:[function(require,module,exports){ +arguments[4][49][0].apply(exports,arguments) +},{"dup":49}],94:[function(require,module,exports){ +arguments[4][45][0].apply(exports,arguments) +},{"dup":45}],95:[function(require,module,exports){ +arguments[4][46][0].apply(exports,arguments) +},{"dup":46}],96:[function(require,module,exports){ +arguments[4][51][0].apply(exports,arguments) +},{"dup":51}],97:[function(require,module,exports){ +module.exports = function setAttributes(element, attributes) { + var value; + + for (var key in attributes) { + if (attributes.hasOwnProperty(key)) { + value = attributes[key]; + + if (value == null) { + element.removeAttribute(key); + } else { + element.setAttribute(key, value); + } + } + } +}; + +},{}],98:[function(require,module,exports){ +arguments[4][2][0].apply(exports,arguments) +},{"./coinbase-account":99,"./constants":100,"./credit-card":101,"./europe-bank-account":102,"./normalize-api-fields":104,"./parse-client-token":105,"./paypal-account":106,"./request/choose-driver":109,"./sepa-mandate":114,"./should-enable-cors":115,"./util":116,"braintree-3ds":125,"braintree-utilities":139,"dup":2}],99:[function(require,module,exports){ +arguments[4][3][0].apply(exports,arguments) +},{"dup":3}],100:[function(require,module,exports){ +arguments[4][4][0].apply(exports,arguments) +},{"dup":4}],101:[function(require,module,exports){ +arguments[4][5][0].apply(exports,arguments) +},{"dup":5}],102:[function(require,module,exports){ +arguments[4][6][0].apply(exports,arguments) +},{"dup":6}],103:[function(require,module,exports){ +arguments[4][7][0].apply(exports,arguments) +},{"./constants":100,"./parse-client-token":105,"./request/choose-driver":109,"./should-enable-cors":115,"./util":116,"dup":7}],104:[function(require,module,exports){ +arguments[4][8][0].apply(exports,arguments) +},{"dup":8}],105:[function(require,module,exports){ +arguments[4][9][0].apply(exports,arguments) +},{"./polyfill":107,"braintree-utilities":139,"dup":9}],106:[function(require,module,exports){ +arguments[4][10][0].apply(exports,arguments) +},{"dup":10}],107:[function(require,module,exports){ +arguments[4][11][0].apply(exports,arguments) +},{"dup":11}],108:[function(require,module,exports){ +arguments[4][12][0].apply(exports,arguments) +},{"../constants":100,"../util":116,"./parse-body":112,"./prep-body":113,"dup":12}],109:[function(require,module,exports){ +arguments[4][13][0].apply(exports,arguments) +},{"../util":116,"./ajax-driver":108,"./jsonp-driver":110,"dup":13}],110:[function(require,module,exports){ +arguments[4][14][0].apply(exports,arguments) +},{"../constants":100,"./jsonp":111,"dup":14}],111:[function(require,module,exports){ +arguments[4][15][0].apply(exports,arguments) +},{"../util":116,"dup":15}],112:[function(require,module,exports){ +arguments[4][16][0].apply(exports,arguments) +},{"dup":16}],113:[function(require,module,exports){ +arguments[4][17][0].apply(exports,arguments) +},{"dup":17,"lodash.isstring":147}],114:[function(require,module,exports){ +arguments[4][18][0].apply(exports,arguments) +},{"dup":18}],115:[function(require,module,exports){ +arguments[4][19][0].apply(exports,arguments) +},{"dup":19}],116:[function(require,module,exports){ +arguments[4][20][0].apply(exports,arguments) +},{"dup":20,"lodash.isempty":140,"lodash.isobject":146}],117:[function(require,module,exports){ +arguments[4][21][0].apply(exports,arguments) +},{"./lib/client":98,"./lib/get-configuration":103,"./lib/parse-client-token":105,"./lib/util":116,"dup":21}],118:[function(require,module,exports){ +arguments[4][22][0].apply(exports,arguments) +},{"dup":22}],119:[function(require,module,exports){ +arguments[4][23][0].apply(exports,arguments) +},{"dup":23}],120:[function(require,module,exports){ +arguments[4][24][0].apply(exports,arguments) +},{"dup":24}],121:[function(require,module,exports){ +arguments[4][25][0].apply(exports,arguments) +},{"dup":25}],122:[function(require,module,exports){ +arguments[4][26][0].apply(exports,arguments) +},{"./lib/dom":118,"./lib/events":119,"./lib/fn":120,"./lib/url":121,"dup":26}],123:[function(require,module,exports){ +arguments[4][27][0].apply(exports,arguments) +},{"../shared/receiver":130,"braintree-utilities":122,"dup":27}],124:[function(require,module,exports){ +arguments[4][28][0].apply(exports,arguments) +},{"./authorization_service":123,"./loader":126,"braintree-utilities":122,"dup":28}],125:[function(require,module,exports){ +arguments[4][29][0].apply(exports,arguments) +},{"./client":124,"dup":29}],126:[function(require,module,exports){ +arguments[4][30][0].apply(exports,arguments) +},{"./loader_display":127,"./loader_message":128,"./loader_spinner":129,"dup":30}],127:[function(require,module,exports){ +arguments[4][31][0].apply(exports,arguments) +},{"dup":31}],128:[function(require,module,exports){ +arguments[4][32][0].apply(exports,arguments) +},{"dup":32}],129:[function(require,module,exports){ +arguments[4][33][0].apply(exports,arguments) +},{"dup":33}],130:[function(require,module,exports){ +arguments[4][34][0].apply(exports,arguments) +},{"braintree-utilities":122,"dup":34}],131:[function(require,module,exports){ +arguments[4][35][0].apply(exports,arguments) +},{"dup":35}],132:[function(require,module,exports){ +arguments[4][36][0].apply(exports,arguments) +},{"dup":36}],133:[function(require,module,exports){ +arguments[4][22][0].apply(exports,arguments) +},{"dup":22}],134:[function(require,module,exports){ +arguments[4][38][0].apply(exports,arguments) +},{"dup":38}],135:[function(require,module,exports){ +arguments[4][39][0].apply(exports,arguments) +},{"dup":39}],136:[function(require,module,exports){ +arguments[4][40][0].apply(exports,arguments) +},{"dup":40}],137:[function(require,module,exports){ +arguments[4][41][0].apply(exports,arguments) +},{"./array":131,"dup":41}],138:[function(require,module,exports){ +arguments[4][42][0].apply(exports,arguments) +},{"dup":42}],139:[function(require,module,exports){ +arguments[4][43][0].apply(exports,arguments) +},{"./lib/array":131,"./lib/base64":132,"./lib/dom":133,"./lib/events":134,"./lib/fn":135,"./lib/string":136,"./lib/url":137,"./lib/uuid":138,"dup":43}],140:[function(require,module,exports){ +arguments[4][44][0].apply(exports,arguments) +},{"dup":44,"lodash.isarguments":141,"lodash.isarray":142,"lodash.isfunction":143,"lodash.isstring":147,"lodash.keys":144}],141:[function(require,module,exports){ +arguments[4][45][0].apply(exports,arguments) +},{"dup":45}],142:[function(require,module,exports){ +arguments[4][46][0].apply(exports,arguments) +},{"dup":46}],143:[function(require,module,exports){ +arguments[4][47][0].apply(exports,arguments) +},{"dup":47}],144:[function(require,module,exports){ +arguments[4][48][0].apply(exports,arguments) +},{"dup":48,"lodash._getnative":145,"lodash.isarguments":141,"lodash.isarray":142}],145:[function(require,module,exports){ +arguments[4][49][0].apply(exports,arguments) +},{"dup":49}],146:[function(require,module,exports){ +arguments[4][50][0].apply(exports,arguments) +},{"dup":50}],147:[function(require,module,exports){ +arguments[4][51][0].apply(exports,arguments) +},{"dup":51}],148:[function(require,module,exports){ +arguments[4][52][0].apply(exports,arguments) +},{"./lib/check-origin":149,"./lib/events":150,"dup":52,"framebus":151}],149:[function(require,module,exports){ +arguments[4][53][0].apply(exports,arguments) +},{"dup":53}],150:[function(require,module,exports){ +arguments[4][54][0].apply(exports,arguments) +},{"dup":54}],151:[function(require,module,exports){ +arguments[4][55][0].apply(exports,arguments) +},{"dup":55}],152:[function(require,module,exports){ +arguments[4][52][0].apply(exports,arguments) +},{"./lib/check-origin":153,"./lib/events":154,"dup":52,"framebus":155}],153:[function(require,module,exports){ +arguments[4][53][0].apply(exports,arguments) +},{"dup":53}],154:[function(require,module,exports){ +arguments[4][54][0].apply(exports,arguments) +},{"dup":54}],155:[function(require,module,exports){ +arguments[4][55][0].apply(exports,arguments) +},{"dup":55}],156:[function(require,module,exports){ +arguments[4][35][0].apply(exports,arguments) +},{"dup":35}],157:[function(require,module,exports){ +arguments[4][36][0].apply(exports,arguments) +},{"dup":36}],158:[function(require,module,exports){ +arguments[4][22][0].apply(exports,arguments) +},{"dup":22}],159:[function(require,module,exports){ +arguments[4][38][0].apply(exports,arguments) +},{"dup":38}],160:[function(require,module,exports){ +arguments[4][39][0].apply(exports,arguments) +},{"dup":39}],161:[function(require,module,exports){ +arguments[4][40][0].apply(exports,arguments) +},{"dup":40}],162:[function(require,module,exports){ +arguments[4][41][0].apply(exports,arguments) +},{"./array":156,"dup":41}],163:[function(require,module,exports){ +arguments[4][42][0].apply(exports,arguments) +},{"dup":42}],164:[function(require,module,exports){ +arguments[4][43][0].apply(exports,arguments) +},{"./lib/array":156,"./lib/base64":157,"./lib/dom":158,"./lib/events":159,"./lib/fn":160,"./lib/string":161,"./lib/url":162,"./lib/uuid":163,"dup":43}],165:[function(require,module,exports){ +arguments[4][80][0].apply(exports,arguments) +},{"batch-execute-functions":166,"braintree-utilities/lib/fn":167,"dup":80}],166:[function(require,module,exports){ +arguments[4][81][0].apply(exports,arguments) +},{"dup":81}],167:[function(require,module,exports){ +arguments[4][39][0].apply(exports,arguments) +},{"dup":39}],168:[function(require,module,exports){ +arguments[4][83][0].apply(exports,arguments) +},{"./lib/default-attributes":169,"dup":83,"lodash.assign":170,"lodash.isstring":181,"setattributes":182}],169:[function(require,module,exports){ +arguments[4][84][0].apply(exports,arguments) +},{"dup":84}],170:[function(require,module,exports){ +arguments[4][85][0].apply(exports,arguments) +},{"dup":85,"lodash._baseassign":171,"lodash._createassigner":173,"lodash.keys":177}],171:[function(require,module,exports){ +arguments[4][86][0].apply(exports,arguments) +},{"dup":86,"lodash._basecopy":172,"lodash.keys":177}],172:[function(require,module,exports){ +arguments[4][87][0].apply(exports,arguments) +},{"dup":87}],173:[function(require,module,exports){ +arguments[4][88][0].apply(exports,arguments) +},{"dup":88,"lodash._bindcallback":174,"lodash._isiterateecall":175,"lodash.restparam":176}],174:[function(require,module,exports){ +arguments[4][89][0].apply(exports,arguments) +},{"dup":89}],175:[function(require,module,exports){ +arguments[4][90][0].apply(exports,arguments) +},{"dup":90}],176:[function(require,module,exports){ +arguments[4][91][0].apply(exports,arguments) +},{"dup":91}],177:[function(require,module,exports){ +arguments[4][48][0].apply(exports,arguments) +},{"dup":48,"lodash._getnative":178,"lodash.isarguments":179,"lodash.isarray":180}],178:[function(require,module,exports){ +arguments[4][49][0].apply(exports,arguments) +},{"dup":49}],179:[function(require,module,exports){ +arguments[4][45][0].apply(exports,arguments) +},{"dup":45}],180:[function(require,module,exports){ +arguments[4][46][0].apply(exports,arguments) +},{"dup":46}],181:[function(require,module,exports){ +arguments[4][51][0].apply(exports,arguments) +},{"dup":51}],182:[function(require,module,exports){ +arguments[4][97][0].apply(exports,arguments) +},{"dup":97}],183:[function(require,module,exports){ +(function (global){ +'use strict'; + +var braintreeUtil = require('braintree-utilities'); +var browser = require('../../shared/util/browser'); +var Destructor = require('destructor'); +var Bus = require('braintree-bus'); +var constants = require('../../shared/constants'); +var PopupView = require('./popup-view'); +var ModalView = require('./modal-view'); + +function AppView(options) { + this.options = options || {}; + + this.destructor = new Destructor(); + + this.bus = new Bus({ + merchantUrl: global.location.href, + channel: this.options.channel + }); + + this.destructor.registerFunctionForTeardown(braintreeUtil.bind(function () { + this.bus.teardown(); + }, this)); + + this._initialize(); +} + +AppView.prototype._initialize = function () { + if (browser.isPopupSupported()) { + this.app = new PopupView({ + src: this._buildUrl(), + isHermes: this.options.isHermes, + channel: this.options.channel + }); + } else { + this.app = new ModalView({ + src: this._buildUrl(), + headless: this.options.headless, + isHermes: this.options.isHermes, + insertFrameFunction: this.options.insertFrameFunction, + channel: this.options.channel + }); + } + + this.destructor.registerFunctionForTeardown(braintreeUtil.bind(function () { + this.app.teardown(); + }, this)); + + this.bus.on(constants.events.CLOSE_APP, braintreeUtil.bind(this.close, this)); + this.bus.on(constants.events.FOCUS_APP, braintreeUtil.bind(this.focus, this)); + this.bus.on(Bus.events.PAYMENT_METHOD_GENERATED, braintreeUtil.bind(this._handlePaymentMethodGenerated, this)); + this.bus.on(Bus.events.UI_POPUP_FORCE_CLOSE, braintreeUtil.bind(this._handleForceClose, this)); +}; + +AppView.prototype._buildUrl = function () { + var url = this.options.paypalAssetsUrl; + url += '/pwpp/'; + url += constants.VERSION; + url += '/html/braintree-frame.html'; + url += '#' + this.options.channel; + + return url; +}; + +AppView.prototype.open = function () { + this.focus(); + this.app.open(); + this.poll(); +}; + +AppView.prototype._handleForceClose = function (event) { + if (event.target === constants.PAYPAL_INTEGRATION_NAME) { + this.close(); + } +}; + +AppView.prototype.close = function () { + this.app.close(); +}; + +AppView.prototype.focus = function () { + if (braintreeUtil.isFunction(this.app.focus)) { + this.app.focus(); + } +}; + +AppView.prototype.isClosed = function () { + return this.app.isClosed(); +}; + +AppView.prototype.stopPolling = function () { + clearInterval(this.pollId); +}; + +AppView.prototype.poll = function () { + this.pollId = setInterval(braintreeUtil.bind(function () { + if (this.isClosed()) { + this._handleClosed(); + } + }, this), 100); +}; + +AppView.prototype._handlePaymentMethodGenerated = function (bundle) { + if (bundle.type === constants.NONCE_TYPE) { + this.close(); + } +}; + +AppView.prototype._handleClosed = function () { + this.stopPolling(); + + this.close(); + + if (browser.isPopupSupported()) { + this.app.el = null; + } +}; + +AppView.prototype.teardown = function () { + this.destructor.teardown(); +}; + +module.exports = AppView; + +}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) +},{"../../shared/constants":186,"../../shared/util/browser":191,"./modal-view":184,"./popup-view":185,"braintree-bus":152,"braintree-utilities":164,"destructor":165}],184:[function(require,module,exports){ +(function (global){ +'use strict'; + +var braintreeUtil = require('braintree-utilities'); +var browser = require('../../shared/util/browser'); +var constants = require('../../shared/constants'); +var Bus = require('braintree-bus'); +var iframer = require('iframer'); + +function ModalView(options) { + this.options = options || {}; + this.container = document.body; + + this.bus = new Bus({ + merchantUrl: global.location.href, + channel: options.channel + }); + + if (this.options.headless) { + this._open = this._openHeadless; + } else { + this._attachBusEvents(); + } + + this._initialize(); +} + +ModalView.prototype._attachBusEvents = function () { + this.bus.on(constants.events.OPEN_MODAL, braintreeUtil.bind(this.open, this)); +}; + +ModalView.prototype._initialize = function () { + var name = this.options.isHermes ? constants.HERMES_FRAME_NAME : constants.FRAME_NAME; + + this.el = iframer({ + src: this.options.src, + name: name, + height: this.options.height || '100%', + width: this.options.width || '100%', + style: { + position: browser.isMobile() ? 'absolute' : 'fixed', + top: 0, + left: 0, + bottom: 0, + padding: 0, + margin: 0, + border: 0, + outline: 'none', + zIndex: 20001, + background: '#FFFFFF' + } + }); +}; + +ModalView.prototype.isClosed = function () { + return !this.container.contains(this.el); +}; + +ModalView.prototype._openHeadless = function () { + this.bus.emit(constants.events.OPEN_MODAL); +}; + +ModalView.prototype._open = function () { + if (braintreeUtil.isFunction(this.options.insertFrameFunction)) { + this.options.insertFrameFunction(this.el.src); + } else { + this.container.appendChild(this.el); + } + + this.bus.emit(constants.events.UI_MODAL_DID_OPEN, {source: constants.PAYPAL_INTEGRATION_NAME}); +}; + +ModalView.prototype.open = function () { + if (this.isClosed()) { + this._open(); + } +}; + +ModalView.prototype.close = function () { + if (!this.isClosed()) { + this.container.removeChild(this.el); + + this.bus.emit(constants.events.UI_MODAL_DID_CLOSE, {source: constants.PAYPAL_INTEGRATION_NAME}); + } +}; + +ModalView.prototype.teardown = function () { + this.close(); + this.bus.teardown(); +}; + +module.exports = ModalView; + +}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) +},{"../../shared/constants":186,"../../shared/util/browser":191,"braintree-bus":152,"braintree-utilities":164,"iframer":168}],185:[function(require,module,exports){ +(function (global){ +'use strict'; + +var constants = require('../../shared/constants'); +var Bus = require('braintree-bus'); +var browser = require('../../shared/useragent/browser'); + +function PopupView(options) { + this.options = options; + + this.bus = new Bus({ + merchantUrl: global.location.href, + channel: this.options.channel + }); + + if (options.isHermes) { + this.name = constants.HERMES_POPUP_NAME; + this.popupHeight = constants.HERMES_POPUP_HEIGHT; + this.popupWidth = constants.HERMES_POPUP_WIDTH; + } else { + this.name = constants.POPUP_NAME; + this.popupHeight = constants.POPUP_HEIGHT; + this.popupWidth = constants.POPUP_WIDTH; + } +} + +PopupView.prototype._getPopupOptions = function () { + return [ + 'height=' + this.popupHeight, + 'width=' + this.popupWidth, + 'top=' + this._getTopPosition(), + 'left=' + this._getLeftPosition(), + constants.POPUP_OPTIONS + ].join(','); +}; + +PopupView.prototype._centerPosition = function (windowMetric, popupMetric, offset) { + return (windowMetric - popupMetric) / 2 + offset; +}; + +PopupView.prototype._getTopPosition = function () { + var windowHeight = window.outerHeight || document.documentElement.clientHeight; + var windowTop = typeof window.screenY === 'undefined' ? window.screenTop : window.screenY; + + return this._centerPosition(windowHeight, this.popupHeight, windowTop); +}; + +PopupView.prototype._getLeftPosition = function () { + var windowWidth = window.outerWidth || document.documentElement.clientWidth; + var windowLeft = typeof window.screenX === 'undefined' ? window.screenLeft : window.screenX; + + return this._centerPosition(windowWidth, this.popupWidth, windowLeft); +}; + +PopupView.prototype.isClosed = function () { + if (this.el) { + return this.el.closed; + } +}; + +PopupView.prototype.open = function () { + if (!this.el) { + this.el = window.open(this.options.src, this.name, this._getPopupOptions()); + this.focus(); + + this.bus.emit(Bus.events.UI_POPUP_DID_OPEN, {source: constants.PAYPAL_INTEGRATION_NAME}); + } +}; + +PopupView.prototype.close = function () { + if (this.el) { + if (browser.isIE8() && !this.isClosed() || !browser.isIE8()) { + this.el.close(); + } + + this.bus.emit(Bus.events.UI_POPUP_DID_CLOSE, {source: constants.PAYPAL_INTEGRATION_NAME}); + } +}; + +PopupView.prototype.focus = function () { + if (this.el) { + this.el.focus(); + } +}; + +PopupView.prototype.teardown = function () { + this.close(); + this.bus.teardown(); +}; + +module.exports = PopupView; + +}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) +},{"../../shared/constants":186,"../../shared/useragent/browser":187,"braintree-bus":152}],186:[function(require,module,exports){ +'use strict'; + +var i; +var version = "1.6.1"; +var events = [ + 'GET_CLIENT_TOKEN', + 'GET_CLIENT_OPTIONS', + 'OPEN_MODAL', + 'CLOSE_APP', + 'FOCUS_APP', + 'UI_MODAL_DID_OPEN', + 'UI_MODAL_DID_CLOSE' +]; + +exports.VERSION = version; +exports.POPUP_NAME = 'braintree_paypal_popup'; +exports.HERMES_POPUP_NAME = 'PPFrameRedirect'; +exports.FRAME_NAME = 'braintree-paypal-frame'; +exports.HERMES_FRAME_NAME = 'PPFrameRedirect'; +exports.POPUP_PATH = '/pwpp/' + version + '/html/braintree-frame.html'; +exports.POPUP_OPTIONS = 'resizable,scrollbars'; +exports.POPUP_HEIGHT = 470; +exports.POPUP_WIDTH = 410; +exports.HERMES_POPUP_HEIGHT = 535; +exports.HERMES_POPUP_WIDTH = 450; +exports.BRIDGE_FRAME_NAME = 'bt-proxy-frame'; +exports.HERMES_SUPPORTED_CURRENCIES = ['USD', 'GBP', 'EUR', 'AUD', 'CAD', 'DKK', 'NOK', 'PLN', 'SEK', 'CHF', 'TRY']; +exports.HERMES_SUPPORTED_COUNTRIES = ['US', 'GB', 'AU', 'CA', 'ES', 'FR', 'DE', 'IT', 'NL', 'NO', 'PL', 'CH', 'TR', 'DK', 'BE', 'AT']; +exports.NONCE_TYPE = 'PayPalAccount'; +exports.PAYPAL_INTEGRATION_NAME = 'PayPal'; +exports.ILLEGAL_XHR_ERROR = 'Illegal XHR request attempted'; +exports.events = {}; + +for (i = 0; i < events.length; i++) { + exports.events[events[i]] = 'paypal:' + events[i]; +} + +},{}],187:[function(require,module,exports){ +'use strict'; + +var userAgent = require('./useragent'); +var platform = require('./platform'); + +function isAndroid() { + return userAgent.matchUserAgent('Android') && !isChrome(); +} + +function isChrome() { + return userAgent.matchUserAgent('Chrome') || userAgent.matchUserAgent('CriOS'); +} + +function isFirefox() { + return userAgent.matchUserAgent('Firefox'); +} + +function isIE() { + return userAgent.matchUserAgent('Trident') || userAgent.matchUserAgent('MSIE'); +} + +function isIE8() { + return userAgent.matchUserAgent(/MSIE 8\.0/); +} + +function isOpera() { + return userAgent.matchUserAgent('Opera') || userAgent.matchUserAgent('OPR'); +} + +function isOperaMini() { + return isOpera() && Object.prototype.toString.call(window.operamini) === '[object OperaMini]'; +} + +function isSafari() { + return userAgent.matchUserAgent('Safari') && !isChrome() && !isAndroid(); +} + +function isIosWebView() { + return platform.isIos() && !isChrome() && !isSafari(); +} + +function isAndroidWebView() { + var androidWebviewRegExp = /Version\/[\w\.]+ Chrome\/[\w\.]+ Mobile/; + return platform.isAndroid() && userAgent.matchUserAgent(androidWebviewRegExp); +} + +module.exports = { + isAndroid: isAndroid, + isChrome: isChrome, + isFirefox: isFirefox, + isIE: isIE, + isIE8: isIE8, + isOpera: isOpera, + isOperaMini: isOperaMini, + isSafari: isSafari, + isIosWebView: isIosWebView, + isAndroidWebView: isAndroidWebView +}; + +},{"./platform":189,"./useragent":190}],188:[function(require,module,exports){ +'use strict'; + +var userAgent = require('./useragent'); +var platform = require('./platform'); + +function isMobile() { + return !isTablet() && + (platform.isAndroid() || platform.isIpod() || platform.isIphone() || + userAgent.matchUserAgent('IEMobile')); +} + +function isTablet() { + return platform.isIpad() || platform.isAndroid() && + !userAgent.matchUserAgent('Mobile'); +} + +function isDesktop() { + return !isMobile() && !isTablet(); +} + +module.exports = { + isMobile: isMobile, + isTablet: isTablet, + isDesktop: isDesktop +}; + +},{"./platform":189,"./useragent":190}],189:[function(require,module,exports){ +'use strict'; + +var userAgent = require('./useragent'); + +function isAndroid() { + return userAgent.matchUserAgent('Android'); +} + +function isIpad() { + return userAgent.matchUserAgent('iPad'); +} + +function isIpod() { + return userAgent.matchUserAgent('iPod'); +} + +function isIphone() { + return userAgent.matchUserAgent('iPhone') && !isIpod(); +} + +function isIos() { + return isIpad() || isIpod() || isIphone(); +} + +module.exports = { + isAndroid: isAndroid, + isIpad: isIpad, + isIpod: isIpod, + isIphone: isIphone, + isIos: isIos +}; + +},{"./useragent":190}],190:[function(require,module,exports){ +'use strict'; + +var nativeUserAgent = window.navigator.userAgent; + +function getNativeUserAgent() { + return nativeUserAgent; +} + +function matchUserAgent(pattern) { + var userAgent = exports.getNativeUserAgent(); + var matches = userAgent.match(pattern); + if (matches) { + return true; + } + return false; +} + +exports.getNativeUserAgent = getNativeUserAgent; +exports.matchUserAgent = matchUserAgent; + +},{}],191:[function(require,module,exports){ +'use strict'; +/* globals ActiveXObject */ + +var browser = require('../useragent/browser'); +var device = require('../useragent/device'); +var platform = require('../useragent/platform'); +var userAgent = require('../useragent/useragent'); + +var uaString = window.navigator.userAgent; +var mobileRe = /[Mm]obi|tablet|iOS|Android|IEMobile|Windows\sPhone/; + +function isMobile() { + return isMobileDevice() && window.outerWidth < 600; +} + +function isMobileDevice() { + return mobileRe.test(uaString); +} + +function detectedPostMessage() { + return Boolean(window.postMessage); +} + +function isPopupSupported() { + if (browser.isOperaMini()) { + return false; + } + + if (device.isDesktop()) { + return true; + } + + if (device.isMobile() || device.isTablet()) { + if (browser.isIE()) { + return false; + } + + if (platform.isAndroid()) { + if (browser.isAndroidWebView()) { + return false; + } + + return true; + } + + if (platform.isIos()) { + // Chrome, Safari Versions 8.0-8.1, or WebViews + if (browser.isChrome()) { + return false; + } + + if (browser.isSafari() && userAgent.matchUserAgent(/OS (?:8_1|8_0|8)(?!_\d)/i)) { + return false; + } + + if (browser.isIosWebView()) { + return false; + } + + return true; + } + } + + return false; +} + +function isOverlaySupported() { + if (browser.isIE8()) { + return false; + } + + try { + return window.self === window.top; + } catch (e) { + return false; + } +} + +function isBridgeIframeRequired() { + return browser.isIE(); +} + +function isMetroBrowser() { + var supported = null; + var errorName = ''; + + try { + new ActiveXObject(''); // eslint-disable-line + } catch (e) { + errorName = e.name; + } + + try { + supported = Boolean(new ActiveXObject('htmlfile')); + } catch (e) { + supported = false; + } + + if (errorName !== 'ReferenceError' && supported === false) { + supported = false; + } else { + supported = true; + } + return !supported; +} + +module.exports = { + isMobile: isMobile, + isMobileDevice: isMobileDevice, + detectedPostMessage: detectedPostMessage, + isPopupSupported: isPopupSupported, + isOverlaySupported: isOverlaySupported, + isBridgeIframeRequired: isBridgeIframeRequired, + isMetroBrowser: isMetroBrowser +}; + +},{"../useragent/browser":187,"../useragent/device":188,"../useragent/platform":189,"../useragent/useragent":190}],192:[function(require,module,exports){ +'use strict'; + +var utils = require('braintree-utilities'); + +function MessageBus(host, channel) { + this.host = host || window; + this.channel = channel || null; + this.handlers = []; + + utils.addEventListener(this.host, 'message', utils.bind(this.receive, this)); +} + +MessageBus.prototype.receive = function (event) { + var i, message, parsed, type; + + try { + parsed = JSON.parse(event.data); + } catch (e) { + return; + } + + type = parsed.type; + message = new MessageBus.Message(this, event.source, parsed.data); + + for (i = 0; i < this.handlers.length; i++) { + if (this.handlers[i].type === type) { + this.handlers[i].handler(message); + } + } +}; + +MessageBus.prototype.send = function (source, type, data) { + source.postMessage(JSON.stringify({ + type: this._namespaceEvent(type), + data: data + }), '*'); +}; + +MessageBus.prototype.register = function (type, handler) { + this.handlers.push({ + type: this._namespaceEvent(type), + handler: handler + }); +}; + +MessageBus.prototype.unregister = function (type, handler) { + for (var i = this.handlers.length - 1; i >= 0; i--) { + if (this.handlers[i].type === type && this.handlers[i].handler === handler) { + return this.handlers.splice(i, 1); + } + } +}; + +MessageBus.prototype._namespaceEvent = function (eventName) { + return this.channel ? ['braintree', this.channel, eventName].join(':') : eventName; +}; + +MessageBus.Message = function (bus, source, content) { + this.bus = bus; + this.source = source; + this.content = content; +}; + +MessageBus.Message.prototype.reply = function (type, data) { + this.bus.send(this.source, type, data); +}; + +module.exports = MessageBus; + +},{"braintree-utilities":206}],193:[function(require,module,exports){ +'use strict'; + +var utils = require('braintree-utilities'); + +function PubsubClient(bus, target) { + this.bus = bus; + this.target = target; + this.handlers = []; + + this.bus.register('publish', utils.bind(this._handleMessage, this)); +} + +PubsubClient.prototype._handleMessage = function (message) { + var i, + content = message.content, + handlers = this.handlers[content.channel]; + + if (typeof handlers !== 'undefined') { + for (i = 0; i < handlers.length; i++) { + handlers[i](content.data); + } + } +}; + +PubsubClient.prototype.publish = function (channel, data) { + this.bus.send(this.target, 'publish', { channel: channel, data: data }); +}; + +PubsubClient.prototype.subscribe = function (channel, handler) { + this.handlers[channel] = this.handlers[channel] || []; + this.handlers[channel].push(handler); +}; + +PubsubClient.prototype.unsubscribe = function (channel, handler) { + var i, + handlers = this.handlers[channel]; + + if (typeof handlers !== 'undefined') { + for (i = 0; i < handlers.length; i++) { + if (handlers[i] === handler) { + handlers.splice(i, 1); + } + } + } +}; + +module.exports = PubsubClient; + +},{"braintree-utilities":206}],194:[function(require,module,exports){ +'use strict'; + +function PubsubServer(bus) { + this.bus = bus; + this.frames = []; + this.handlers = []; +} + +PubsubServer.prototype.subscribe = function (channel, handler) { + this.handlers[channel] = this.handlers[channel] || []; + this.handlers[channel].push(handler); +}; + +PubsubServer.prototype.registerFrame = function (frame) { + this.frames.push(frame); +}; + +PubsubServer.prototype.unregisterFrame = function (frame) { + for (var i = 0; i < this.frames.length; i++) { + if (this.frames[i] === frame) { + this.frames.splice(i, 1); + } + } +}; + +PubsubServer.prototype.publish = function (channel, data) { + var i, + handlers = this.handlers[channel]; + + if (typeof handlers !== 'undefined') { + for (i = 0; i < handlers.length; i++) { + handlers[i](data); + } + } + + for (i = 0; i < this.frames.length; i++) { + this.bus.send(this.frames[i], 'publish', { + channel: channel, + data: data + }); + } +}; + +PubsubServer.prototype.unsubscribe = function (channel, handler) { + var i, + handlers = this.handlers[channel]; + + if (typeof handlers !== 'undefined') { + for (i = 0; i < handlers.length; i++) { + if (handlers[i] === handler) { + handlers.splice(i, 1); + } + } + } +}; + +module.exports = PubsubServer; + +},{}],195:[function(require,module,exports){ +'use strict'; + +var utils = require('braintree-utilities'); + +function RPCClient(bus, target) { + this.bus = bus; + this.target = target || window.parent; + this.counter = 0; + this.callbacks = {}; + + this.bus.register('rpc_response', utils.bind(this._handleResponse, this)); +} + +RPCClient.prototype._handleResponse = function (message) { + var content = message.content, + thisCallback = this.callbacks[content.id]; + + if (typeof thisCallback === 'function') { + thisCallback.apply(null, content.response); + delete this.callbacks[content.id]; + } +}; + +RPCClient.prototype.invoke = function (method, args, callback) { + var counter = this.counter++; + + this.callbacks[counter] = callback; + this.bus.send(this.target, 'rpc_request', { id: counter, method: method, args: args }); +}; + +module.exports = RPCClient; + +},{"braintree-utilities":206}],196:[function(require,module,exports){ +'use strict'; + +var utils = require('braintree-utilities'); + +function RPCServer(bus) { + this.bus = bus; + this.methods = {}; + + this.bus.register('rpc_request', utils.bind(this._handleRequest, this)); +} + +RPCServer.prototype._handleRequest = function (message) { + var reply, + content = message.content, + args = content.args || [], + thisMethod = this.methods[content.method]; + + if (typeof thisMethod === 'function') { + reply = function () { + message.reply('rpc_response', { + id: content.id, + response: Array.prototype.slice.call(arguments) + }); + }; + + args.push(reply); + + thisMethod.apply(null, args); + } +}; + +RPCServer.prototype.reset = function () { + this.methods = {}; +}; + +RPCServer.prototype.define = function (method, handler) { + this.methods[method] = handler; +}; + +module.exports = RPCServer; + +},{"braintree-utilities":206}],197:[function(require,module,exports){ +var MessageBus = require('./lib/message-bus'); +var PubsubClient = require('./lib/pubsub-client'); +var PubsubServer = require('./lib/pubsub-server'); +var RPCClient = require('./lib/rpc-client'); +var RPCServer = require('./lib/rpc-server'); + +module.exports = { + MessageBus: MessageBus, + PubsubClient: PubsubClient, + PubsubServer: PubsubServer, + RPCClient: RPCClient, + RPCServer: RPCServer +}; + +},{"./lib/message-bus":192,"./lib/pubsub-client":193,"./lib/pubsub-server":194,"./lib/rpc-client":195,"./lib/rpc-server":196}],198:[function(require,module,exports){ +arguments[4][35][0].apply(exports,arguments) +},{"dup":35}],199:[function(require,module,exports){ +arguments[4][36][0].apply(exports,arguments) +},{"dup":36}],200:[function(require,module,exports){ +arguments[4][22][0].apply(exports,arguments) +},{"dup":22}],201:[function(require,module,exports){ +arguments[4][38][0].apply(exports,arguments) +},{"dup":38}],202:[function(require,module,exports){ +arguments[4][39][0].apply(exports,arguments) +},{"dup":39}],203:[function(require,module,exports){ +arguments[4][40][0].apply(exports,arguments) +},{"dup":40}],204:[function(require,module,exports){ +arguments[4][41][0].apply(exports,arguments) +},{"./array":198,"dup":41}],205:[function(require,module,exports){ +arguments[4][42][0].apply(exports,arguments) +},{"dup":42}],206:[function(require,module,exports){ +arguments[4][43][0].apply(exports,arguments) +},{"./lib/array":198,"./lib/base64":199,"./lib/dom":200,"./lib/events":201,"./lib/fn":202,"./lib/string":203,"./lib/url":204,"./lib/uuid":205,"dup":43}],207:[function(require,module,exports){ +arguments[4][35][0].apply(exports,arguments) +},{"dup":35}],208:[function(require,module,exports){ +arguments[4][36][0].apply(exports,arguments) +},{"dup":36}],209:[function(require,module,exports){ +arguments[4][22][0].apply(exports,arguments) +},{"dup":22}],210:[function(require,module,exports){ +arguments[4][38][0].apply(exports,arguments) +},{"dup":38}],211:[function(require,module,exports){ +arguments[4][39][0].apply(exports,arguments) +},{"dup":39}],212:[function(require,module,exports){ +arguments[4][40][0].apply(exports,arguments) +},{"dup":40}],213:[function(require,module,exports){ +arguments[4][41][0].apply(exports,arguments) +},{"./array":207,"dup":41}],214:[function(require,module,exports){ +arguments[4][42][0].apply(exports,arguments) +},{"dup":42}],215:[function(require,module,exports){ +arguments[4][43][0].apply(exports,arguments) +},{"./lib/array":207,"./lib/base64":208,"./lib/dom":209,"./lib/events":210,"./lib/fn":211,"./lib/string":212,"./lib/url":213,"./lib/uuid":214,"dup":43}],216:[function(require,module,exports){ +arguments[4][80][0].apply(exports,arguments) +},{"batch-execute-functions":217,"braintree-utilities/lib/fn":218,"dup":80}],217:[function(require,module,exports){ +arguments[4][81][0].apply(exports,arguments) +},{"dup":81}],218:[function(require,module,exports){ +arguments[4][39][0].apply(exports,arguments) +},{"dup":39}],219:[function(require,module,exports){ +arguments[4][83][0].apply(exports,arguments) +},{"./lib/default-attributes":220,"dup":83,"lodash.assign":221,"lodash.isstring":232,"setattributes":233}],220:[function(require,module,exports){ +arguments[4][84][0].apply(exports,arguments) +},{"dup":84}],221:[function(require,module,exports){ +arguments[4][85][0].apply(exports,arguments) +},{"dup":85,"lodash._baseassign":222,"lodash._createassigner":224,"lodash.keys":228}],222:[function(require,module,exports){ +arguments[4][86][0].apply(exports,arguments) +},{"dup":86,"lodash._basecopy":223,"lodash.keys":228}],223:[function(require,module,exports){ +arguments[4][87][0].apply(exports,arguments) +},{"dup":87}],224:[function(require,module,exports){ +arguments[4][88][0].apply(exports,arguments) +},{"dup":88,"lodash._bindcallback":225,"lodash._isiterateecall":226,"lodash.restparam":227}],225:[function(require,module,exports){ +arguments[4][89][0].apply(exports,arguments) +},{"dup":89}],226:[function(require,module,exports){ +arguments[4][90][0].apply(exports,arguments) +},{"dup":90}],227:[function(require,module,exports){ +arguments[4][91][0].apply(exports,arguments) +},{"dup":91}],228:[function(require,module,exports){ +arguments[4][48][0].apply(exports,arguments) +},{"dup":48,"lodash._getnative":229,"lodash.isarguments":230,"lodash.isarray":231}],229:[function(require,module,exports){ +arguments[4][49][0].apply(exports,arguments) +},{"dup":49}],230:[function(require,module,exports){ +arguments[4][45][0].apply(exports,arguments) +},{"dup":45}],231:[function(require,module,exports){ +arguments[4][46][0].apply(exports,arguments) +},{"dup":46}],232:[function(require,module,exports){ +arguments[4][51][0].apply(exports,arguments) +},{"dup":51}],233:[function(require,module,exports){ +arguments[4][97][0].apply(exports,arguments) +},{"dup":97}],234:[function(require,module,exports){ +'use strict'; + +var RPC_METHOD_NAMES = ['getCreditCards', 'unlockCreditCard', 'sendAnalyticsEvents']; + +function APIProxyServer(apiClient) { + this.apiClient = apiClient; +} + +APIProxyServer.prototype.attach = function (rpcServer) { + var self = this; + var i = 0; + var len = RPC_METHOD_NAMES.length; + + function attachDefine(name) { + rpcServer.define(name, function () { + self.apiClient[name].apply(self.apiClient, arguments); + }); + } + + for (i; i < len; i++) { + attachDefine(RPC_METHOD_NAMES[i]); + } +}; + +module.exports = APIProxyServer; + +},{}],235:[function(require,module,exports){ +(function (global){ +'use strict'; + +var htmlNode, bodyNode; +var api = require('braintree-api'); +var BraintreeBus = require('braintree-bus'); +var Destructor = require('destructor'); +var rpc = require('braintree-rpc'); +var utils = require('braintree-utilities'); +var normalizeElement = utils.normalizeElement; +var bind = utils.bind; +var isBrowserHttps = utils.isBrowserHttps; +var APIProxyServer = require('./api-proxy-server'); +var MerchantFormManager = require('./merchant-form-manager'); +var FrameContainer = require('./frame-container'); +var constants = require('../shared/constants'); +var version = "1.9.1"; +var PayPalModalView = require('braintree-paypal/src/external/views/app-view'); + +function getElementStyle(element, style) { + var computedStyle = window.getComputedStyle ? getComputedStyle(element) : element.currentStyle; + + return computedStyle[style]; +} + +function getMerchantPageDefaultStyles() { + return { + html: { + height: htmlNode.style.height || '', + overflow: getElementStyle(htmlNode, 'overflow'), + position: getElementStyle(htmlNode, 'position') + }, + body: { + height: bodyNode.style.height || '', + overflow: getElementStyle(bodyNode, 'overflow') + } + }; +} + +function isMobile() { + var isMobileUserAgent = /Android|iPhone|iPod|iPad/i.test(window.navigator.userAgent); + return isMobileUserAgent; +} + +function Client(settings) { + var inlineFramePath, modalFramePath, formElement; + + this.channel = settings.channel; + this.destructor = new Destructor(); + this.merchantConfiguration = settings.merchantConfiguration; + this.encodedClientToken = settings.gatewayConfiguration; + this.analyticsConfiguration = settings.analyticsConfiguration; + this.paypalOptions = settings.merchantConfiguration.paypal || {}; + this.container = null; + this.merchantFormManager = null; + this.root = settings.root; + this.configurationRequests = []; + this.braintreeApiClient = api.configure({ + clientToken: settings.gatewayConfiguration, + analyticsConfiguration: this.analyticsConfiguration, + integration: 'dropin', + enableCORS: this.merchantConfiguration.enableCORS + }); + + this.paymentMethodNonceReceivedCallback = settings.merchantConfiguration.paymentMethodNonceReceived; + this.clientToken = api.parseClientToken(settings.gatewayConfiguration); + + this.braintreeBus = new BraintreeBus({ + merchantUrl: global.location.href, + channel: settings.channel + }); + + this.bus = new rpc.MessageBus(this.root, this.channel); + this.rpcServer = new rpc.RPCServer(this.bus); + this.apiProxyServer = new APIProxyServer(this.braintreeApiClient); + + this.apiProxyServer.attach(this.rpcServer); + + inlineFramePath = settings.inlineFramePath || this.clientToken.assetsUrl + '/dropin/' + version + '/inline-frame.html'; + modalFramePath = settings.modalFramePath || this.clientToken.assetsUrl + '/dropin/' + version + '/modal-frame.html'; + htmlNode = document.documentElement; + bodyNode = document.body; + + this.frames = { + inline: this._createFrame(inlineFramePath, constants.INLINE_FRAME_NAME), + modal: this._createFrame(modalFramePath, constants.MODAL_FRAME_NAME) + }; + + this.container = normalizeElement(settings.merchantConfiguration.container, 'Unable to find valid container.'); + + formElement = normalizeElement(settings.merchantConfiguration.form || this._findClosest(this.container, 'form')); + + this.merchantFormManager = new MerchantFormManager({ + form: formElement, + frames: this.frames, + onSubmit: this.paymentMethodNonceReceivedCallback, + apiClient: this.braintreeApiClient + }).initialize(); + + this.destructor.registerFunctionForTeardown(bind(function () { + this.merchantFormManager.teardown(); + }, this)); + + if (settings.gatewayConfiguration.paypalEnabled) { + this._configurePayPal(); + } + + this.braintreeApiClient.sendAnalyticsEvents('dropin.web.initialized'); +} + +Client.prototype.initialize = function () { + var i; + var self = this; + + this._initializeModal(); + + this.braintreeBus.emit(BraintreeBus.events.ASYNC_DEPENDENCY_INITIALIZING); + this.container.appendChild(this.frames.inline.element); + bodyNode.appendChild(this.frames.modal.element); + + this.destructor.registerFunctionForTeardown(function (done) { + self._hideModal(function () { + self.container.removeChild(self.frames.inline.element); + bodyNode.removeChild(self.frames.modal.element); + + done(); + }); + }); + + this.rpcServer.define('receiveSharedCustomerIdentifier', function (sharedCustomerIdentifier) { + self.braintreeApiClient.attrs.sharedCustomerIdentifier = sharedCustomerIdentifier; + self.braintreeApiClient.attrs.sharedCustomerIdentifierType = 'browser_session_cookie_store'; + + for (i = 0; i < self.configurationRequests.length; i++) { + self.configurationRequests[i](self.encodedClientToken); + } + + self.configurationRequests = []; + }); + + this.braintreeBus.on(BraintreeBus.events.PAYMENT_METHOD_GENERATED, bind(this._handleAltPayData, this)); + + this.rpcServer.define('getConfiguration', function (reply) { + reply({ + enableCORS: self.merchantConfiguration.enableCORS, + clientToken: self.encodedClientToken, + paypalOptions: self.paypalOptions, + analyticsConfiguration: self.analyticsConfiguration, + merchantHttps: isBrowserHttps() + }); + }); + + this.rpcServer.define('selectPaymentMethod', function (paymentMethods) { + self.frames.modal.rpcClient.invoke('selectPaymentMethod', [paymentMethods]); + self._showModal(); + }); + + this.rpcServer.define('sendAddedPaymentMethod', function (paymentMethod) { + self.merchantFormManager.setNoncePayload(paymentMethod); + + self.frames.inline.rpcClient.invoke('receiveNewPaymentMethod', [paymentMethod]); + }); + + this.rpcServer.define('sendUsedPaymentMethod', function (paymentMethod) { + self.frames.inline.rpcClient.invoke('selectPaymentMethod', [paymentMethod]); + }); + + this.rpcServer.define('sendUnlockedNonce', function (paymentMethod) { + self.merchantFormManager.setNoncePayload(paymentMethod); + }); + + this.rpcServer.define('clearNonce', function () { + self.merchantFormManager.clearNoncePayload(); + }); + + this.rpcServer.define('closeDropInModal', function () { + self._hideModal(); + }); + + this.rpcServer.define('setInlineFrameHeight', function (height) { + self.frames.inline.element.style.height = height + 'px'; + }); + + this.bus.register('ready', function (message) { + if (message.source === self.frames.inline.element.contentWindow) { + self.frames.inline.rpcClient = new rpc.RPCClient(self.bus, message.source); + } else if (message.source === self.frames.modal.element.contentWindow) { + self.frames.modal.rpcClient = new rpc.RPCClient(self.bus, message.source); + } + }); +}; + +Client.prototype._createFrame = function (endpoint, name) { + return new FrameContainer(endpoint, name, this.braintreeBus); +}; + +Client.prototype._initializeModal = function () { + this.frames.modal.element.style.display = 'none'; + this.frames.modal.element.style.position = isMobile() ? 'absolute' : 'fixed'; + this.frames.modal.element.style.top = '0'; + this.frames.modal.element.style.left = '0'; + this.frames.modal.element.style.height = '100%'; + this.frames.modal.element.style.width = '100%'; +}; + +Client.prototype._lockMerchantWindowSize = function () { + setTimeout(function () { + htmlNode.style.overflow = 'hidden'; + bodyNode.style.overflow = 'hidden'; + bodyNode.style.height = '100%'; + + if (isMobile()) { + htmlNode.style.position = 'relative'; + htmlNode.style.height = window.innerHeight + 'px'; + } + }, 160); +}; + +Client.prototype._unlockMerchantWindowSize = function () { + var defaultStyles = this.merchantPageDefaultStyles; + + if (!defaultStyles) { return; } + + bodyNode.style.height = defaultStyles.body.height; + bodyNode.style.overflow = defaultStyles.body.overflow; + + htmlNode.style.overflow = defaultStyles.html.overflow; + + if (isMobile()) { + htmlNode.style.height = defaultStyles.html.height; + htmlNode.style.position = defaultStyles.html.position; + } + + delete this.merchantPageDefaultStyles; +}; + +Client.prototype._showModal = function () { + var self = this; + var el = this.frames.modal.element; + + this.merchantPageDefaultStyles = getMerchantPageDefaultStyles(); + + el.style.display = 'block'; + + this.frames.modal.rpcClient.invoke('open', [], function () { + setTimeout(function () { + self._lockMerchantWindowSize(); + el.contentWindow.focus(); + }, 200); + }); +}; + +Client.prototype._hideModal = function (done) { + this._unlockMerchantWindowSize(); + this.frames.modal.element.style.display = 'none'; + + if (done) { + done(); + } +}; + +Client.prototype._configurePayPal = function () { + this.paypalModalView = new PayPalModalView({ + channel: this.channel, + insertFrameFunction: this.paypalOptions.insertFrame, + paypalAssetsUrl: this.clientToken.paypal.assetsUrl, + isHermes: !!this.paypalOptions.singleUse && !!this.paypalOptions.amount && !!this.paypalOptions.currency + }); +}; + +Client.prototype._handleAltPayData = function (payload) { + this.merchantFormManager.setNoncePayload(payload); + this.frames.inline.rpcClient.invoke('receiveNewPaymentMethod', [payload]); + this.frames.modal.rpcClient.invoke('modalViewClose'); +}; + +Client.prototype._findClosest = function (node, tagName) { + tagName = tagName.toUpperCase(); + + do { + if (node.nodeName === tagName) { + return node; + } + } while (node = node.parentNode); + + throw 'Unable to find a valid ' + tagName; +}; + +Client.prototype.teardown = function (done) { + if (this.paypalModalView) { + this.paypalModalView.teardown(); + } + + this.braintreeBus.emit(constants.MODAL_FRAME_TEARDOWN_EVENT, bind(function () { + this.braintreeBus.emit(constants.INLINE_FRAME_TEARDOWN_EVENT, bind(function () { + this.destructor.teardown(bind(function (err) { + if (err) { return done(err); } + + this.braintreeBus.teardown(); + done(); + }, this)); + }, this)); + }, this)); +}; + +module.exports = Client; + +}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) +},{"../shared/constants":239,"./api-proxy-server":234,"./frame-container":237,"./merchant-form-manager":238,"braintree-api":117,"braintree-bus":148,"braintree-paypal/src/external/views/app-view":183,"braintree-rpc":197,"braintree-utilities":215,"destructor":216}],236:[function(require,module,exports){ +'use strict'; + +var Client = require('./client'); +var VERSION = "1.9.1"; + +function create(options) { + var client = new Client(options); + client.initialize(); + + return client; +} + +module.exports = { + create: create, + VERSION: VERSION +}; + +},{"./client":235}],237:[function(require,module,exports){ +'use strict'; + +var BraintreeBus = require('braintree-bus'); +var constants = require('../shared/constants'); +var iFramer = require('iframer'); + +// TODO: move to shared and deduplicate from src/internal/util/dropin-util.js +var TRANSITION_END_EVENT_NAMES = { + transition: 'transitionend', + '-o-transition': 'otransitionEnd', + '-moz-transition': 'transitionend', + '-webkit-transition': 'webkitTransitionEnd' +}; + +function getTransitionEndEventName() { + var eventName; + var fakeEl = document.createElement('fakeelement'); + + for (eventName in TRANSITION_END_EVENT_NAMES) { + if (typeof fakeEl.style[eventName] !== 'undefined') { + return TRANSITION_END_EVENT_NAMES[eventName]; + } + } + return null; +} + +function listenForReady(el, braintreeBus) { + var transitionEndEvent = getTransitionEndEventName(); + + function handler(event) { + if (event.target === el && event.propertyName === 'height') { + braintreeBus.emit(BraintreeBus.events.ASYNC_DEPENDENCY_READY); + el.removeEventListener(transitionEndEvent, handler); + } + } + + if (transitionEndEvent) { + el.addEventListener(transitionEndEvent, handler); + } else { + setTimeout(function () { + braintreeBus.emit(BraintreeBus.events.ASYNC_DEPENDENCY_READY); + }, 500); + } +} + +function FrameContainer(endpoint, name, braintreeBus) { + var transition = 'height 210ms cubic-bezier(0.390, 0.575, 0.565, 1.000)'; + var element = iFramer({ + name: name, + width: '100%', + height: '68', + style: { + transition: transition, + WebkitTransition: transition, + MozTransition: transition, + msTransition: transition, + OTransition: transition, + border: '0', + zIndex: '9999' + } + }); + + this.element = element; + + // Delayed so that browsers won't cache iframe URLs. + setTimeout(function () { + element.src = endpoint + '#' + braintreeBus.channel; + }, 0); + + if (name === constants.INLINE_FRAME_NAME) { + listenForReady(element, braintreeBus); + } +} + +module.exports = FrameContainer; + +},{"../shared/constants":239,"braintree-bus":148,"iframer":219}],238:[function(require,module,exports){ +'use strict'; + +var utils = require('braintree-utilities'); +var FormNapper = require('form-napper'); + +function MerchantFormManager(options) { + this.formNapper = new FormNapper(options.form); + this.frames = options.frames; + this.onSubmit = options.onSubmit; + this.apiClient = options.apiClient; +} + +MerchantFormManager.prototype.initialize = function () { + if (this._isSubmitBased()) { + this._setElements(); + } + + this._setEvents(); + + return this; +}; + +MerchantFormManager.prototype.setNoncePayload = function (payload) { + this.noncePayload = payload; +}; + +MerchantFormManager.prototype.clearNoncePayload = function () { + this.noncePayload = null; +}; + +MerchantFormManager.prototype._isSubmitBased = function () { + return !this.onSubmit; +}; + +MerchantFormManager.prototype._isCallbackBased = function () { + return !!this.onSubmit; +}; + +MerchantFormManager.prototype._setElements = function () { + this.nonceInput = this.formNapper.inject('payment_method_nonce', ''); +}; + +MerchantFormManager.prototype._setEvents = function () { + this.formNapper.hijack(utils.bind(this._handleFormSubmit, this)); +}; + +MerchantFormManager.prototype._handleFormSubmit = function (event) { + if (this.noncePayload && this.noncePayload.nonce) { + this._handleNonceReply(event); + } else { + this.frames.inline.rpcClient.invoke('requestNonce', [], utils.bind(function (payload) { + this.setNoncePayload(payload); + this._handleNonceReply(event); + }, this)); + } +}; + +MerchantFormManager.prototype._handleNonceReply = function (event) { + if (this._isCallbackBased()) { + this.apiClient.sendAnalyticsEvents('dropin.web.end.callback', utils.bind(function () { + var payload = this.noncePayload; + + payload.originalEvent = event; + + this.onSubmit(payload); + + setTimeout(utils.bind(function () { + delete payload.originalEvent; + + this.frames.inline.rpcClient.invoke('clearLoadingState'); + this.frames.inline.rpcClient.invoke('receiveNewPaymentMethod', [payload]); + }, this), 200); + }, this)); + } else { + this._triggerFormSubmission(); + } +}; + +MerchantFormManager.prototype._triggerFormSubmission = function () { + this.nonceInput = this.formNapper.inject('payment_method_nonce', this.noncePayload.nonce); + + this.apiClient.sendAnalyticsEvents('dropin.web.end.auto-submit', utils.bind(function () { + this.formNapper.submit(); + }, this)); +}; + +MerchantFormManager.prototype.teardown = function () { + var form; + + if (this.nonceInput) { + form = this.formNapper.htmlForm; + form.removeChild(this.nonceInput); + } + + this.formNapper.detach(); +}; + +module.exports = MerchantFormManager; + +},{"braintree-utilities":215,"form-napper":376}],239:[function(require,module,exports){ +module.exports={ + "PAYPAL_INTEGRATION_NAME": "PayPal", + "INLINE_FRAME_NAME": "braintree-dropin-frame", + "MODAL_FRAME_NAME": "braintree-dropin-modal-frame", + "PAYMENT_METHOD_TYPES": ["CoinbaseAccount", "PayPalAccount", "CreditCard"], + "cssClassMap": { + "American Express": "american-express", + "Diners Club": "diners-club", + "DinersClub": "diners-club", + "Discover": "discover", + "JCB": "jcb", + "Maestro": "maestro", + "MasterCard": "master-card", + "Solo": "solo", + "Switch": "switch", + "UKMaestro": "maestro", + "UnionPay": "unionpay", + "Visa": "visa" + }, + "INLINE_FRAME_TEARDOWN_EVENT": "dropin:TEARDOWN_INLINE_FRAME", + "MODAL_FRAME_TEARDOWN_EVENT": "dropin:TEARDOWN_MODAL_FRAME" +} + +},{}],240:[function(require,module,exports){ +(function (global){ +'use strict'; +var ELEMENT_NODE = global.Node ? global.Node.ELEMENT_NODE : 1; + +function extractValues(node, results) { + results = results || {}; + + var child, i; + var children = node.children; + + for (i = 0; i < children.length; i++) { + child = children[i]; + + if (isBraintreeNode(child)) { + var dataAttr = child.getAttribute('data-braintree-name'); + + if (dataAttr === 'postal_code') { + results.billingAddress = { + postalCode: child.value + }; + } else { + results[dataAttr] = child.value; + } + + scrubAttributes(child); + } else if (child.children && child.children.length > 0) { + extractValues(child, results); + } + } + + return results; +} + +function scrubAttributes(node) { + try { + node.attributes.removeNamedItem('name'); + } catch (e) {} +} + +function scrubAllAttributes(node) { + extractValues(node); +} + +function isBraintreeNode(node) { + return node.nodeType === ELEMENT_NODE && node.attributes['data-braintree-name']; +} + +module.exports = { + extractValues: extractValues, + scrubAllAttributes: scrubAllAttributes, + scrubAttributes: scrubAttributes, + isBraintreeNode: isBraintreeNode +}; + +}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) +},{}],241:[function(require,module,exports){ +(function (global){ +'use strict'; + +var util = require('braintree-utilities'); +var fields = require('./fields'); +var Destructor = require('destructor'); +var Bus = require('braintree-bus'); +var PaymentMethodModel = require('./models/payment-method-model'); +var getNonceInput = require('./get-nonce-input'); +var ERROR_PAYLOAD = { + message: 'Unable to process payments at this time', + type: 'IMMEDIATE' +}; + +function Form(apiClient, configuration) { + var merchantConfiguration = configuration.merchantConfiguration; + var hasExistingInput = typeof merchantConfiguration.paymentMethodNonceInputField === 'object'; + + this.destructor = new Destructor(); + + this.apiClient = apiClient; + + this.isCreditCardForm = merchantConfiguration.useCreditCard === false ? false : true; + + this.htmlForm = document.getElementById(merchantConfiguration.id); + + this.paymentMethodNonceInput = getNonceInput(merchantConfiguration.paymentMethodNonceInputField); + this.htmlForm.appendChild(this.paymentMethodNonceInput); + this.destructor.registerFunctionForTeardown(util.bind(function () { + if (hasExistingInput) { + this.paymentMethodNonceInput.value = ''; + } else { + this.htmlForm.removeChild(this.paymentMethodNonceInput); + } + }, this)); + + this.model = new PaymentMethodModel(); + + this.bus = new Bus({ + merchantUrl: global.location.href, + channel: configuration.channel + }); + + this.setEvents(); + this.destructor.registerFunctionForTeardown(util.bind(function () { + this.bus.teardown(); + }, this)); +} + +Form.prototype.setEvents = function () { + this.onSubmitHandler = util.bind(this.handleSubmit, this); + this.onExternalNonceReceived = util.bind(this.onExternalNonceReceived, this); + this.clearExternalNonce = util.bind(this.clearExternalNonce, this); + + util.addEventListener(this.htmlForm, 'submit', this.onSubmitHandler); + this.destructor.registerFunctionForTeardown(util.bind(function () { + util.removeEventListener(this.htmlForm, 'submit', this.onSubmitHandler); + }, this)); + + this.bus.on(Bus.events.PAYMENT_METHOD_GENERATED, this.onExternalNonceReceived); + this.bus.on(Bus.events.PAYMENT_METHOD_CANCELLED, this.clearExternalNonce); +}; + +Form.prototype.handleSubmit = function (event) { + var type; + + if (event.preventDefault) { + event.preventDefault(); + } else { + event.returnValue = false; + } + + if (!this.isCreditCardForm) { + this.onNonceReceived(null, this.model.attributes); + return; + } + + type = this.model.get('type'); + + if (type && type !== 'CreditCard') { + fields.scrubAllAttributes(this.htmlForm); + this.onNonceReceived(null, this.model.attributes); + return; + } + + this.apiClient.tokenizeCard(fields.extractValues(this.htmlForm), util.bind(function (err, nonce, payload) { + if (err) { + this.onNonceReceived(ERROR_PAYLOAD, null); + } else { + this.model.set({ + nonce: nonce, + type: payload.type, + details: payload.details + }); + + this.onNonceReceived(null, this.model.attributes); + } + }, this)); +}; + +Form.prototype.writeNonceToDOM = function () { + this.paymentMethodNonceInput.value = this.model.get('nonce'); +}; + +Form.prototype.onExternalNonceReceived = function (payload) { + this.model.set(payload); + this.writeNonceToDOM(); +}; + +Form.prototype.clearExternalNonce = function () { + this.model.reset(); +}; + +Form.prototype.onNonceReceived = function (err) { + var form = this.htmlForm; + + if (err) { + this.bus.emit(Bus.events.ERROR, ERROR_PAYLOAD); + return; + } + + util.removeEventListener(form, 'submit', this.onSubmitHandler); + + this.writeNonceToDOM(); + + if (form.submit && (typeof form.submit === 'function' || form.submit.call)) { + form.submit(); + } else { + setTimeout(function () { + form.querySelector('[type="submit"]').click(); + }, 1); + } +}; + +Form.prototype.teardown = function () { + this.destructor.teardown(); +}; + +module.exports = Form; + +}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) +},{"./fields":240,"./get-nonce-input":242,"./models/payment-method-model":243,"braintree-bus":246,"braintree-utilities":258,"destructor":259}],242:[function(require,module,exports){ +'use strict'; + +module.exports = function getNonceInput(paymentMethodNonceInputField) { + var nonceInputName; + + if (typeof paymentMethodNonceInputField === 'object') { + return paymentMethodNonceInputField; + } + + nonceInputName = 'payment_method_nonce'; + + if (typeof paymentMethodNonceInputField === 'string') { + nonceInputName = paymentMethodNonceInputField; + } + + var nonceInput = document.createElement('input'); + nonceInput.name = nonceInputName; + nonceInput.type = 'hidden'; + + return nonceInput; +}; + +},{}],243:[function(require,module,exports){ +'use strict'; + +function PaymentMethodModel() { + this.reset(); +} + +PaymentMethodModel.prototype.get = function (key) { + return this.attributes[key]; +} + +PaymentMethodModel.prototype.set = function (payload) { + this.attributes = payload || {}; +}; + +PaymentMethodModel.prototype.reset = function () { + this.attributes = {}; +} + +module.exports = PaymentMethodModel; + +},{}],244:[function(require,module,exports){ +'use strict'; + +module.exports = function validateAnnotations(htmlForm) { + var inputs = htmlForm.getElementsByTagName('*'); + var valid = {}; + + for (var i = 0; i < inputs.length; i++) { + var field = inputs[i].getAttribute('data-braintree-name'); + valid[field] = true; + } + + if (!valid.number) { + throw new Error('Unable to find an input with data-braintree-name="number" in your form. Please add one.'); + } + + if (valid.expiration_date) { + if (valid.expiration_month || valid.expiration_year) { + throw new Error('You have inputs with data-braintree-name="expiration_date" AND data-braintree-name="expiration_(year|month)". Please use either "expiration_date" or "expiration_year" and "expiration_month".'); + } + } else { + if (!valid.expiration_month && !valid.expiration_year) { + throw new Error('Unable to find an input with data-braintree-name="expiration_date" in your form. Please add one.'); + } + + if (!valid.expiration_month) { + throw new Error('Unable to find an input with data-braintree-name="expiration_month" in your form. Please add one.'); + } + + if (!valid.expiration_year) { + throw new Error('Unable to find an input with data-braintree-name="expiration_year" in your form. Please add one.'); + } + } +}; + +},{}],245:[function(require,module,exports){ +'use strict'; + +var Form = require('./lib/form'); +var validateAnnotations = require('./lib/validate-annotations'); + +function setup(apiClient, configuration) { + var merchantConfiguration = configuration.merchantConfiguration || {}; + var htmlForm = document.getElementById(merchantConfiguration.id); + var isCreditCardForm = merchantConfiguration.useCreditCard === false ? false : true; + + if (!htmlForm) { + throw new Error('Unable to find form with id: "' + merchantConfiguration.id + '"'); + } + + if (isCreditCardForm) { + validateAnnotations(htmlForm); + } + + return new Form(apiClient, configuration); +} + +module.exports = {setup: setup}; + +},{"./lib/form":241,"./lib/validate-annotations":244}],246:[function(require,module,exports){ +arguments[4][52][0].apply(exports,arguments) +},{"./lib/check-origin":247,"./lib/events":248,"dup":52,"framebus":249}],247:[function(require,module,exports){ +arguments[4][53][0].apply(exports,arguments) +},{"dup":53}],248:[function(require,module,exports){ +arguments[4][54][0].apply(exports,arguments) +},{"dup":54}],249:[function(require,module,exports){ +arguments[4][55][0].apply(exports,arguments) +},{"dup":55}],250:[function(require,module,exports){ +arguments[4][35][0].apply(exports,arguments) +},{"dup":35}],251:[function(require,module,exports){ +arguments[4][36][0].apply(exports,arguments) +},{"dup":36}],252:[function(require,module,exports){ +arguments[4][22][0].apply(exports,arguments) +},{"dup":22}],253:[function(require,module,exports){ +arguments[4][38][0].apply(exports,arguments) +},{"dup":38}],254:[function(require,module,exports){ +arguments[4][39][0].apply(exports,arguments) +},{"dup":39}],255:[function(require,module,exports){ +arguments[4][40][0].apply(exports,arguments) +},{"dup":40}],256:[function(require,module,exports){ +arguments[4][41][0].apply(exports,arguments) +},{"./array":250,"dup":41}],257:[function(require,module,exports){ +arguments[4][42][0].apply(exports,arguments) +},{"dup":42}],258:[function(require,module,exports){ +arguments[4][43][0].apply(exports,arguments) +},{"./lib/array":250,"./lib/base64":251,"./lib/dom":252,"./lib/events":253,"./lib/fn":254,"./lib/string":255,"./lib/url":256,"./lib/uuid":257,"dup":43}],259:[function(require,module,exports){ +arguments[4][80][0].apply(exports,arguments) +},{"batch-execute-functions":260,"braintree-utilities/lib/fn":261,"dup":80}],260:[function(require,module,exports){ +arguments[4][81][0].apply(exports,arguments) +},{"dup":81}],261:[function(require,module,exports){ +arguments[4][39][0].apply(exports,arguments) +},{"dup":39}],262:[function(require,module,exports){ +arguments[4][2][0].apply(exports,arguments) +},{"./coinbase-account":263,"./constants":264,"./credit-card":265,"./europe-bank-account":266,"./normalize-api-fields":268,"./parse-client-token":269,"./paypal-account":270,"./request/choose-driver":273,"./sepa-mandate":278,"./should-enable-cors":279,"./util":280,"braintree-3ds":289,"braintree-utilities":303,"dup":2}],263:[function(require,module,exports){ +arguments[4][3][0].apply(exports,arguments) +},{"dup":3}],264:[function(require,module,exports){ +arguments[4][4][0].apply(exports,arguments) +},{"dup":4}],265:[function(require,module,exports){ +arguments[4][5][0].apply(exports,arguments) +},{"dup":5}],266:[function(require,module,exports){ +arguments[4][6][0].apply(exports,arguments) +},{"dup":6}],267:[function(require,module,exports){ +arguments[4][7][0].apply(exports,arguments) +},{"./constants":264,"./parse-client-token":269,"./request/choose-driver":273,"./should-enable-cors":279,"./util":280,"dup":7}],268:[function(require,module,exports){ +arguments[4][8][0].apply(exports,arguments) +},{"dup":8}],269:[function(require,module,exports){ +arguments[4][9][0].apply(exports,arguments) +},{"./polyfill":271,"braintree-utilities":303,"dup":9}],270:[function(require,module,exports){ +arguments[4][10][0].apply(exports,arguments) +},{"dup":10}],271:[function(require,module,exports){ +arguments[4][11][0].apply(exports,arguments) +},{"dup":11}],272:[function(require,module,exports){ +arguments[4][12][0].apply(exports,arguments) +},{"../constants":264,"../util":280,"./parse-body":276,"./prep-body":277,"dup":12}],273:[function(require,module,exports){ +arguments[4][13][0].apply(exports,arguments) +},{"../util":280,"./ajax-driver":272,"./jsonp-driver":274,"dup":13}],274:[function(require,module,exports){ +arguments[4][14][0].apply(exports,arguments) +},{"../constants":264,"./jsonp":275,"dup":14}],275:[function(require,module,exports){ +arguments[4][15][0].apply(exports,arguments) +},{"../util":280,"dup":15}],276:[function(require,module,exports){ +arguments[4][16][0].apply(exports,arguments) +},{"dup":16}],277:[function(require,module,exports){ +arguments[4][17][0].apply(exports,arguments) +},{"dup":17,"lodash.isstring":311}],278:[function(require,module,exports){ +arguments[4][18][0].apply(exports,arguments) +},{"dup":18}],279:[function(require,module,exports){ +arguments[4][19][0].apply(exports,arguments) +},{"dup":19}],280:[function(require,module,exports){ +arguments[4][20][0].apply(exports,arguments) +},{"dup":20,"lodash.isempty":304,"lodash.isobject":310}],281:[function(require,module,exports){ +arguments[4][21][0].apply(exports,arguments) +},{"./lib/client":262,"./lib/get-configuration":267,"./lib/parse-client-token":269,"./lib/util":280,"dup":21}],282:[function(require,module,exports){ +arguments[4][22][0].apply(exports,arguments) +},{"dup":22}],283:[function(require,module,exports){ +arguments[4][23][0].apply(exports,arguments) +},{"dup":23}],284:[function(require,module,exports){ +arguments[4][24][0].apply(exports,arguments) +},{"dup":24}],285:[function(require,module,exports){ +arguments[4][25][0].apply(exports,arguments) +},{"dup":25}],286:[function(require,module,exports){ +arguments[4][26][0].apply(exports,arguments) +},{"./lib/dom":282,"./lib/events":283,"./lib/fn":284,"./lib/url":285,"dup":26}],287:[function(require,module,exports){ +arguments[4][27][0].apply(exports,arguments) +},{"../shared/receiver":294,"braintree-utilities":286,"dup":27}],288:[function(require,module,exports){ +arguments[4][28][0].apply(exports,arguments) +},{"./authorization_service":287,"./loader":290,"braintree-utilities":286,"dup":28}],289:[function(require,module,exports){ +arguments[4][29][0].apply(exports,arguments) +},{"./client":288,"dup":29}],290:[function(require,module,exports){ +arguments[4][30][0].apply(exports,arguments) +},{"./loader_display":291,"./loader_message":292,"./loader_spinner":293,"dup":30}],291:[function(require,module,exports){ +arguments[4][31][0].apply(exports,arguments) +},{"dup":31}],292:[function(require,module,exports){ +arguments[4][32][0].apply(exports,arguments) +},{"dup":32}],293:[function(require,module,exports){ +arguments[4][33][0].apply(exports,arguments) +},{"dup":33}],294:[function(require,module,exports){ +arguments[4][34][0].apply(exports,arguments) +},{"braintree-utilities":286,"dup":34}],295:[function(require,module,exports){ +arguments[4][35][0].apply(exports,arguments) +},{"dup":35}],296:[function(require,module,exports){ +arguments[4][36][0].apply(exports,arguments) +},{"dup":36}],297:[function(require,module,exports){ +arguments[4][22][0].apply(exports,arguments) +},{"dup":22}],298:[function(require,module,exports){ +arguments[4][38][0].apply(exports,arguments) +},{"dup":38}],299:[function(require,module,exports){ +arguments[4][39][0].apply(exports,arguments) +},{"dup":39}],300:[function(require,module,exports){ +arguments[4][40][0].apply(exports,arguments) +},{"dup":40}],301:[function(require,module,exports){ +arguments[4][41][0].apply(exports,arguments) +},{"./array":295,"dup":41}],302:[function(require,module,exports){ +arguments[4][42][0].apply(exports,arguments) +},{"dup":42}],303:[function(require,module,exports){ +arguments[4][43][0].apply(exports,arguments) +},{"./lib/array":295,"./lib/base64":296,"./lib/dom":297,"./lib/events":298,"./lib/fn":299,"./lib/string":300,"./lib/url":301,"./lib/uuid":302,"dup":43}],304:[function(require,module,exports){ +arguments[4][44][0].apply(exports,arguments) +},{"dup":44,"lodash.isarguments":305,"lodash.isarray":306,"lodash.isfunction":307,"lodash.isstring":311,"lodash.keys":308}],305:[function(require,module,exports){ +arguments[4][45][0].apply(exports,arguments) +},{"dup":45}],306:[function(require,module,exports){ +arguments[4][46][0].apply(exports,arguments) +},{"dup":46}],307:[function(require,module,exports){ +arguments[4][47][0].apply(exports,arguments) +},{"dup":47}],308:[function(require,module,exports){ +arguments[4][48][0].apply(exports,arguments) +},{"dup":48,"lodash._getnative":309,"lodash.isarguments":305,"lodash.isarray":306}],309:[function(require,module,exports){ +arguments[4][49][0].apply(exports,arguments) +},{"dup":49}],310:[function(require,module,exports){ +arguments[4][50][0].apply(exports,arguments) +},{"dup":50}],311:[function(require,module,exports){ +arguments[4][51][0].apply(exports,arguments) +},{"dup":51}],312:[function(require,module,exports){ +arguments[4][52][0].apply(exports,arguments) +},{"./lib/check-origin":313,"./lib/events":314,"dup":52,"framebus":315}],313:[function(require,module,exports){ +arguments[4][53][0].apply(exports,arguments) +},{"dup":53}],314:[function(require,module,exports){ +arguments[4][54][0].apply(exports,arguments) +},{"dup":54}],315:[function(require,module,exports){ +arguments[4][55][0].apply(exports,arguments) +},{"dup":55}],316:[function(require,module,exports){ +arguments[4][35][0].apply(exports,arguments) +},{"dup":35}],317:[function(require,module,exports){ +arguments[4][36][0].apply(exports,arguments) +},{"dup":36}],318:[function(require,module,exports){ +arguments[4][22][0].apply(exports,arguments) +},{"dup":22}],319:[function(require,module,exports){ +arguments[4][38][0].apply(exports,arguments) +},{"dup":38}],320:[function(require,module,exports){ +arguments[4][39][0].apply(exports,arguments) +},{"dup":39}],321:[function(require,module,exports){ +arguments[4][40][0].apply(exports,arguments) +},{"dup":40}],322:[function(require,module,exports){ +arguments[4][41][0].apply(exports,arguments) +},{"./array":316,"dup":41}],323:[function(require,module,exports){ +arguments[4][42][0].apply(exports,arguments) +},{"dup":42}],324:[function(require,module,exports){ +arguments[4][43][0].apply(exports,arguments) +},{"./lib/array":316,"./lib/base64":317,"./lib/dom":318,"./lib/events":319,"./lib/fn":320,"./lib/string":321,"./lib/url":322,"./lib/uuid":323,"dup":43}],325:[function(require,module,exports){ +arguments[4][80][0].apply(exports,arguments) +},{"batch-execute-functions":326,"braintree-utilities/lib/fn":327,"dup":80}],326:[function(require,module,exports){ +arguments[4][81][0].apply(exports,arguments) +},{"dup":81}],327:[function(require,module,exports){ +arguments[4][39][0].apply(exports,arguments) +},{"dup":39}],328:[function(require,module,exports){ +arguments[4][83][0].apply(exports,arguments) +},{"./lib/default-attributes":329,"dup":83,"lodash.assign":330,"lodash.isstring":341,"setattributes":342}],329:[function(require,module,exports){ +arguments[4][84][0].apply(exports,arguments) +},{"dup":84}],330:[function(require,module,exports){ +arguments[4][85][0].apply(exports,arguments) +},{"dup":85,"lodash._baseassign":331,"lodash._createassigner":333,"lodash.keys":337}],331:[function(require,module,exports){ +arguments[4][86][0].apply(exports,arguments) +},{"dup":86,"lodash._basecopy":332,"lodash.keys":337}],332:[function(require,module,exports){ +arguments[4][87][0].apply(exports,arguments) +},{"dup":87}],333:[function(require,module,exports){ +arguments[4][88][0].apply(exports,arguments) +},{"dup":88,"lodash._bindcallback":334,"lodash._isiterateecall":335,"lodash.restparam":336}],334:[function(require,module,exports){ +arguments[4][89][0].apply(exports,arguments) +},{"dup":89}],335:[function(require,module,exports){ +arguments[4][90][0].apply(exports,arguments) +},{"dup":90}],336:[function(require,module,exports){ +arguments[4][91][0].apply(exports,arguments) +},{"dup":91}],337:[function(require,module,exports){ +arguments[4][48][0].apply(exports,arguments) +},{"dup":48,"lodash._getnative":338,"lodash.isarguments":339,"lodash.isarray":340}],338:[function(require,module,exports){ +arguments[4][49][0].apply(exports,arguments) +},{"dup":49}],339:[function(require,module,exports){ +arguments[4][45][0].apply(exports,arguments) +},{"dup":45}],340:[function(require,module,exports){ +arguments[4][46][0].apply(exports,arguments) +},{"dup":46}],341:[function(require,module,exports){ +arguments[4][51][0].apply(exports,arguments) +},{"dup":51}],342:[function(require,module,exports){ +arguments[4][97][0].apply(exports,arguments) +},{"dup":97}],343:[function(require,module,exports){ +(function (global){ +'use strict'; + +var braintreeUtil = require('braintree-utilities'); +var Destructor = require('destructor'); +var Bus = require('braintree-bus'); +var AppView = require('./views/app-view'); +var LoggedInView = require('./views/logged-in-view'); +var LoggedOutView = require('./views/logged-out-view'); +var OverlayView = require('./views/overlay-view'); +var MerchantPageView = require('./views/merchant-page-view'); +var PaymentMethodNonceInputFieldView = require('./views/payment-method-nonce-input-field-view'); +var BridgeIframeView = require('./views/bridge-iframe-view'); +var browser = require('../shared/util/browser'); +var constants = require('../shared/constants'); +var util = require('../shared/util/util'); + +function Client(clientToken, options, channel) { + options = options || {}; + + this._clientToken = clientToken; + this._clientOptions = options; + + this._clientToken.correlationId = util.generateUid(); + + this.destructor = new Destructor(); + + this.channel = channel; + this.bus = new Bus({ + merchantUrl: global.location.href, + channel: this.channel + }); + + this.container = braintreeUtil.normalizeElement(options.container); + this.paymentMethodNonceInputField = options.paymentMethodNonceInputField; + + this.insertFrameFunction = options.insertFrame; + this.onSuccess = options.onSuccess; + this.onCancelled = options.onCancelled; + this.loggedInView = null; + this.loggedOutView = null; + this.appView = null; + this.merchantPageView = null; + this.paymentMethodNonceInputFieldView = null; + this.overlayView = null; + this.bridgeIframeView = null; + this.insertUI = options.headless !== true; +} + +Client.prototype.initialize = function () { + var clickLoginHandler = braintreeUtil.bind(this._handleClickLogin, this); + + this._createViews(); + + this.bus.on( + constants.events.GET_CLIENT_TOKEN, + braintreeUtil.bind(this._handleGetClientToken, this) + ); + + this.bus.on( + constants.events.GET_CLIENT_OPTIONS, + braintreeUtil.bind(this._handleGetClientOptions, this) + ); + + if (this.insertUI) { + this.bus.on( + Bus.events.PAYMENT_METHOD_GENERATED, + braintreeUtil.bind(this._handlePaymentMethodGenerated, this) + ); + } + + braintreeUtil.addEventListener(document.body, 'click', clickLoginHandler); + + this.destructor.registerFunctionForTeardown(function () { + braintreeUtil.removeEventListener(document.body, 'click', clickLoginHandler); + }); +}; + +Client.prototype._createViews = function () { + var i; + var views = []; + + if (browser.isBridgeIframeRequired()) { + this.bridgeIframeView = new BridgeIframeView({ + container: this.container, + paypalAssetsUrl: this._clientToken.paypal.assetsUrl, + channel: this.channel + }); + views.push(this.bridgeIframeView); + } + + this.appView = new AppView({ + insertFrameFunction: this.insertFrameFunction, + paypalAssetsUrl: this._clientToken.paypal.assetsUrl, + isHermes: util.isHermesConfiguration(this._clientToken, this._clientOptions), + headless: this._clientOptions.headless, + channel: this.channel + }); + views.push(this.appView); + + if (this.insertUI) { + this.paymentMethodNonceInputFieldView = new PaymentMethodNonceInputFieldView({ + container: this.container, + el: this.paymentMethodNonceInputField, + channel: this.channel + }); + views.push(this.paymentMethodNonceInputFieldView); + + this.merchantPageView = new MerchantPageView({ + channel: this.channel + }); + views.push(this.merchantPageView); + + this.loggedInView = new LoggedInView({ + paypalAssetsUrl: this._clientToken.paypal.assetsUrl, + container: this.container, + channel: this.channel + }); + views.push(this.loggedInView); + + this.loggedOutView = new LoggedOutView({ + paypalAssetsUrl: this._clientToken.paypal.assetsUrl, + container: this.container, + enablePayPalButton: util.isOneTimeHermesConfiguration(this._clientOptions), + locale: this._clientOptions.locale, + channel: this.channel + }); + views.push(this.loggedOutView); + + if (browser.isPopupSupported() && browser.isOverlaySupported()) { + this.overlayView = new OverlayView({ + paypalAssetsUrl: this._clientToken.paypal.assetsUrl, + onFocus: braintreeUtil.bind(function () { this.bus.emit(constants.events.FOCUS_APP); }, this), + onClose: braintreeUtil.bind(function () { this.bus.emit(constants.events.CLOSE_APP); }, this), + channel: this.channel + }); + views.push(this.overlayView); + } + } + + this.destructor.registerFunctionForTeardown(function () { + for (i = 0; i < views.length; i++) { + views[i].teardown(); + } + }); +}; + +Client.prototype._handleClickLogin = function (event) { + var target = event.target || event.srcElement; + + while (true) { // eslint-disable-line no-constant-condition + if (target == null) { return; } + if (target === event.currentTarget) { return; } + if (this._isButton(target)) { break; } + + target = target.parentNode; + } + + util.preventDefault(event); + + this.launch(); +}; + +Client.prototype.launch = function () { + this.appView.open(); +}; + +Client.prototype._isButton = function (node) { + var isPayPalButton = node.id === 'braintree-paypal-button'; + var isHermesButton = util.isOneTimeHermesConfiguration(this._clientOptions) && + node.className.match(/paypal-button(?!-widget)/); + + return isPayPalButton || isHermesButton; +}; + +Client.prototype._handlePaymentMethodGenerated = function (bundle) { + if (bundle.type === constants.NONCE_TYPE && braintreeUtil.isFunction(this.onSuccess)) { + this.onSuccess(bundle); + } +}; + +Client.prototype._clientTokenData = function () { + return { + analyticsUrl: this._clientToken.analytics ? + this._clientToken.analytics.url : null, + authorizationFingerprint: this._clientToken.authorizationFingerprint, + clientApiUrl: this._clientToken.clientApiUrl, + displayName: this._clientOptions.displayName || this._clientToken.paypal.displayName, + paypalAssetsUrl: this._clientToken.paypal.assetsUrl, + paypalClientId: this._clientToken.paypal.clientId, + paypalPrivacyUrl: this._clientToken.paypal.privacyUrl, + paypalUserAgreementUrl: this._clientToken.paypal.userAgreementUrl, + billingAgreementsEnabled: this._clientToken.paypal.billingAgreementsEnabled, + unvettedMerchant: this._clientToken.paypal.unvettedMerchant, + payeeEmail: this._clientToken.paypal.payeeEmail, + correlationId: this._clientToken.correlationId, + offline: this._clientOptions.offline || this._clientToken.paypal.environmentNoNetwork, + sdkVersion: this._clientToken.sdkVersion, + merchantAppId: this._clientToken.merchantAppId + }; +}; + +Client.prototype._handleGetClientToken = function (callback) { + callback(this._clientTokenData()); +}; + +Client.prototype._clientOptionsData = function () { + return { + locale: this._clientOptions.locale || 'en_us', + onetime: this._clientOptions.singleUse || false, + integration: this._clientOptions.integration || 'paypal', + enableShippingAddress: this._clientOptions.enableShippingAddress || false, + enableBillingAddress: this._clientOptions.enableBillingAddress || false, + enableHermes: util.isHermesConfiguration(this._clientToken, this._clientOptions), + amount: this._clientOptions.amount || null, + currency: this._clientOptions.currency || null, + shippingAddressOverride: this._clientOptions.shippingAddressOverride || null, + enableCORS: this._clientOptions.enableCORS + }; +}; + +Client.prototype._handleGetClientOptions = function (callback) { + callback(this._clientOptionsData()); +}; + +Client.prototype.teardown = function () { + this.destructor.teardown(braintreeUtil.bind(function () { + this.bus.teardown(); + }, this)); +}; + +module.exports = Client; + +}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) +},{"../shared/constants":354,"../shared/util/browser":361,"../shared/util/util":363,"./views/app-view":345,"./views/bridge-iframe-view":346,"./views/logged-in-view":347,"./views/logged-out-view":348,"./views/merchant-page-view":349,"./views/overlay-view":351,"./views/payment-method-nonce-input-field-view":352,"braintree-bus":312,"braintree-utilities":324,"destructor":325}],344:[function(require,module,exports){ +'use strict'; + +var Client = require('./client'); +var browser = require('../shared/util/browser'); +var constants = require('../shared/constants'); +var getLocale = require('../shared/get-locale'); +var isHermesConfiguration = require('../shared/util/util').isHermesConfiguration; +var isOneTimeHermesConfiguration = require('../shared/util/util').isOneTimeHermesConfiguration; +var VERSION = "1.6.1"; +var braintreeUtil = require('braintree-utilities'); +var braintreeApi = require('braintree-api'); + +function create(clientToken, options, channel) { + var client, onUnsupported; + options = options || {}; + onUnsupported = options.onUnsupported; + + if (typeof onUnsupported !== 'function') { + onUnsupported = function (error) { + try { + console.log(error); // eslint-disable-line no-console + } catch (e) {} // eslint-disable-line + }; + } + + if (!clientToken) { + onUnsupported(new Error('Parameter "clientToken" cannot be null')); + return null; + } + + clientToken = braintreeApi.parseClientToken(clientToken); + + if (!clientToken.paypalEnabled) { + onUnsupported(new Error('PayPal is not enabled')); + return null; + } + + if (!browser.detectedPostMessage()) { + onUnsupported(new Error('unsupported browser detected')); + return null; + } + + if (!options.container) { + onUnsupported(new Error('Please supply a container for the PayPal button to be appended to')); + return null; + } + + if (!isBrowserSecure(clientToken, options)) { + onUnsupported(new Error('unsupported protocol detected')); + return null; + } + + if (isMisconfiguredUnvettedMerchant(clientToken, options)) { + onUnsupported(new Error('Unvetted merchant client token does not include a payee email')); + return null; + } + + if (isHermesConfiguration(clientToken, options)) { + if (!isHermesSupportedCountry(options.locale)) { + onUnsupported(new Error('This PayPal integration does not support this country')); + return null; + } + } + + if (isOneTimeHermesConfiguration(options)) { + if (!isHermesSupportedCurrency(options.currency)) { + onUnsupported(new Error('This PayPal integration does not support this currency')); + return null; + } + + if (!isValidAmount(options.amount)) { + onUnsupported(new Error('Amount must be a number')); + return null; + } + } + + client = new Client(clientToken, options, channel); + client.initialize(); + + return client; +} + +function isSupportedOption(option, supported) { + var i; + var supportedLength = supported.length; + var isSupported = false; + + for (i = 0; i < supportedLength; i++) { + if (option.toLowerCase() === supported[i].toLowerCase()) { + isSupported = true; + } + } + + return isSupported; +} + +function isHermesSupportedCurrency(currency) { + return isSupportedOption(currency, constants.HERMES_SUPPORTED_CURRENCIES); +} + +function isHermesSupportedCountry(locale) { + return isSupportedOption(getLocale(locale).split('_')[1], constants.HERMES_SUPPORTED_COUNTRIES); +} + +function isValidAmount(amount) { + amount = parseFloat(amount); + return typeof amount === 'number' && !isNaN(amount) && amount >= 0; +} + +function isMisconfiguredUnvettedMerchant(clientToken, options) { + return clientToken.paypal.unvettedMerchant && (!isHermesConfiguration(clientToken, options) || !clientToken.paypal.payeeEmail); +} + +function isBrowserSecure(clientToken, options) { + if (clientToken.paypal.allowHttp) { return true; } + if (browser.isPopupSupported()) { return true; } + if ('merchantHttps' in options) { return options.merchantHttps; } + + return braintreeUtil.isBrowserHttps(); +} + +module.exports = { + create: create, + VERSION: VERSION +}; + +},{"../shared/constants":354,"../shared/get-locale":356,"../shared/util/browser":361,"../shared/util/util":363,"./client":343,"braintree-api":281,"braintree-utilities":324}],345:[function(require,module,exports){ +arguments[4][183][0].apply(exports,arguments) +},{"../../shared/constants":354,"../../shared/util/browser":361,"./modal-view":350,"./popup-view":353,"braintree-bus":312,"braintree-utilities":324,"destructor":325,"dup":183}],346:[function(require,module,exports){ +'use strict'; + +var constants = require('../../shared/constants'); +var iframer = require('iframer'); + +function BridgeIframeView(options) { + this.options = options || {}; + + this.el = iframer({ + src: this._buildUrl(), + name: constants.BRIDGE_FRAME_NAME, + height: 1, + width: 1, + style: { + position: 'static', + top: 0, + left: 0, + bottom: 0, + padding: 0, + margin: 0, + border: 0, + outline: 'none', + background: 'transparent' + } + }); + + this.options.container.appendChild(this.el); +} + +BridgeIframeView.prototype._buildUrl = function () { + var url = this.options.paypalAssetsUrl; + url += '/pwpp/'; + url += constants.VERSION; + url += '/html/bridge-frame.html'; + url += '#' + this.options.channel; + + return url; +}; + +BridgeIframeView.prototype.teardown = function () { + this.options.container.removeChild(this.el); +}; + +module.exports = BridgeIframeView; + +},{"../../shared/constants":354,"iframer":328}],347:[function(require,module,exports){ +(function (global){ +'use strict'; + +var braintreeUtil = require('braintree-utilities'); +var Destructor = require('destructor'); +var Bus = require('braintree-bus'); +var util = require('../../shared/util/util'); +var dom = require('../../shared/util/dom'); +var constants = require('../../shared/constants'); + +function LoggedInView(options) { + this.options = options || {}; + this.wrapper = this.options.container || document.body; + + this.destructor = new Destructor(); + + this.bus = new Bus({ + merchantUrl: global.location.href, + channel: options.channel + }); + + this._initialize(); +} + +LoggedInView.prototype._initialize = function () { + var clickLogoutHandler = braintreeUtil.bind(this._handleClickLogout, this); + + this._createViewContainer(); + this._createPayPalName(); + this._createEmailNode(); + this._createLogoutNode(); + + braintreeUtil.addEventListener(this.logoutNode, 'click', clickLogoutHandler); + + this.destructor.registerFunctionForTeardown(braintreeUtil.bind(function () { + braintreeUtil.removeEventListener(this.logoutNode, 'click', clickLogoutHandler); + }, this)); + + this.bus.on(Bus.events.PAYMENT_METHOD_GENERATED, braintreeUtil.bind(this._handlePaymentMethodGenerated, this)); + this.bus.on(Bus.events.PAYMENT_METHOD_CANCELLED, braintreeUtil.bind(this._handlePaymentMethodCancelled, this)); +}; + +LoggedInView.prototype._createViewContainer = function () { + var cssStyles = [ + 'display: none', + 'max-width: 500px', + 'overflow: hidden', + 'padding: 16px', + 'background-image: url(' + this.options.paypalAssetsUrl + '/pwpp/' + constants.VERSION + '/images/paypal-small.png)', + 'background-image: url(' + this.options.paypalAssetsUrl + '/pwpp/' + constants.VERSION + '/images/paypal-small.svg), none', + 'background-position: 20px 50%', + 'background-repeat: no-repeat', + 'background-size: 13px 15px', + 'border-top: 1px solid #d1d4d6', + 'border-bottom: 1px solid #d1d4d6' + ].join(';'); + + this.container = document.createElement('div'); + this.container.id = 'braintree-paypal-loggedin'; + this.container.classList.add('braintree-paypal-loggedin'); + this.container.style.cssText = cssStyles; + + this.wrapper.appendChild(this.container); +}; + +LoggedInView.prototype._createPayPalName = function () { + var cssStyles = [ + 'color: #283036', + 'font-size: 13px', + 'font-weight: 800', + 'font-family: "Helvetica Neue", Helvetica, Arial, sans-serif', + 'margin-left: 36px', + '-webkit-font-smoothing: antialiased', + '-moz-font-smoothing: antialiased', + '-ms-font-smoothing: antialiased', + 'font-smoothing: antialiased' + ].join(';'); + + this.payPalName = document.createElement('span'); + this.payPalName.id = 'bt-pp-name'; + this.payPalName.classList.add('bt-pp-name'); + this.payPalName.innerHTML = 'PayPal'; + this.payPalName.style.cssText = cssStyles; + + return this.container.appendChild(this.payPalName); +}; + +LoggedInView.prototype._createEmailNode = function () { + var cssStyles = [ + 'color: #6e787f', + 'font-size: 13px', + 'font-family: "Helvetica Neue", Helvetica, Arial, sans-serif', + 'margin-left: 5px', + '-webkit-font-smoothing: antialiased', + '-moz-font-smoothing: antialiased', + '-ms-font-smoothing: antialiased', + 'font-smoothing: antialiased' + ].join(';'); + + this.emailNode = document.createElement('span'); + this.emailNode.id = 'bt-pp-email'; + this.emailNode.classList.add('bt-pp-email'); + this.emailNode.style.cssText = cssStyles; + + this.container.appendChild(this.emailNode); +}; + +LoggedInView.prototype._createLogoutNode = function () { + var cssStyles = [ + 'color: #3d95ce', + 'font-size: 11px', + 'font-family: "Helvetica Neue", Helvetica, Arial, sans-serif', + 'line-height: 20px', + 'margin: 0 0 0 25px', + 'padding: 0', + 'background-color: transparent', + 'border: 0', + 'cursor: pointer', + 'text-decoration: underline', + 'float: right', + '-webkit-font-smoothing: antialiased', + '-moz-font-smoothing: antialiased', + '-ms-font-smoothing: antialiased', + 'font-smoothing: antialiased' + ].join(';'); + + this.logoutNode = document.createElement('button'); + this.logoutNode.id = 'bt-pp-cancel'; + this.logoutNode.classList.add('bt-pp-cancel'); + this.logoutNode.innerHTML = 'Cancel'; + this.logoutNode.style.cssText = cssStyles; + + this.container.appendChild(this.logoutNode); +}; + +LoggedInView.prototype.show = function (email) { + this.container.style.display = 'block'; + dom.setTextContent(this.emailNode, email); +}; + +LoggedInView.prototype.hide = function () { + this.container.style.display = 'none'; +}; + +LoggedInView.prototype._handleClickLogout = function (event) { + util.preventDefault(event); + + this.bus.emit(Bus.events.PAYMENT_METHOD_CANCELLED, {source: constants.PAYPAL_INTEGRATION_NAME}); +}; + +LoggedInView.prototype._handlePaymentMethodGenerated = function (bundle) { + var email; + + if (bundle.type === constants.NONCE_TYPE) { + email = bundle && bundle.details && bundle.details.email ? bundle.details.email : ''; + this.show(email); + } +}; + +LoggedInView.prototype._handlePaymentMethodCancelled = function (event) { + if (event.source === constants.PAYPAL_INTEGRATION_NAME) { + this.hide(); + } +}; + +LoggedInView.prototype.teardown = function () { + this.wrapper.removeChild(this.container); + this.destructor.teardown(); + this.bus.teardown(); +}; + +module.exports = LoggedInView; + +}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) +},{"../../shared/constants":354,"../../shared/util/dom":362,"../../shared/util/util":363,"braintree-bus":312,"braintree-utilities":324,"destructor":325}],348:[function(require,module,exports){ +(function (global){ +'use strict'; + +var braintreeUtil = require('braintree-utilities'); +var Bus = require('braintree-bus'); +var constants = require('../../shared/constants'); +var getLocale = require('../../shared/get-locale'); + +function LoggedOutView(options) { + this.options = options; + this.wrapper = this.options.container || document.body; + + this.bus = new Bus({ + merchantUrl: global.location.href, + channel: options.channel + }); + + this._initialize(); +} + +LoggedOutView.prototype._initialize = function () { + this.createViewContainer(); + + if (this.options.enablePayPalButton) { + this.createCheckoutWithPayPalButton(); + } else { + this.createPayWithPayPalButton(); + } + + this.bus.on(Bus.events.PAYMENT_METHOD_GENERATED, braintreeUtil.bind(this._handlePaymentMethodGenerated, this)); + this.bus.on(Bus.events.PAYMENT_METHOD_CANCELLED, braintreeUtil.bind(this._handlePaymentMethodCancelled, this)); +}; + +LoggedOutView.prototype.createViewContainer = function () { + this.container = document.createElement('div'); + this.container.id = 'braintree-paypal-loggedout'; + + this.wrapper.appendChild(this.container); + this.loginNode = this.container; +}; + +LoggedOutView.prototype.createPayWithPayPalButton = function () { + var element = document.createElement('a'); + var image = new Image(); + var imageCssText = [ + 'max-width: 100%', + 'display: block', + 'width: 100%', + 'height: 100%', + 'outline: none', + 'border: 0' + ].join(';'); + var cssStyles = [ + 'display: block', + 'width: 115px', + 'height: 44px', + 'overflow: hidden' + ].join(';'); + + element.id = 'braintree-paypal-button'; + element.href = '#'; + element.style.cssText = cssStyles; + + image.src = this.options.paypalAssetsUrl + '/pwpp/' + constants.VERSION + '/images/pay-with-paypal.png'; + image.setAttribute('alt', 'Pay with PayPal'); + image.style.cssText = imageCssText; + + element.appendChild(image); + this.container.appendChild(element); +}; + +LoggedOutView.prototype.createCheckoutWithPayPalButton = function () { + var script = document.createElement('script'); + var attr; + var scriptAttrs = { + 'data-merchant': 'merchant-id', + 'data-button': 'checkout', + 'data-type': 'button', + 'data-color': 'blue', + 'data-lc': getLocale(this.options.locale) + }; + + script.src = '//www.paypalobjects.com/api/button.js'; + script.async = true; + + for (attr in scriptAttrs) { + if (scriptAttrs.hasOwnProperty(attr)) { + script.setAttribute(attr, scriptAttrs[attr]); + } + } + + this.container.appendChild(script); +}; + +LoggedOutView.prototype.show = function () { + this.container.style.display = 'block'; +}; + +LoggedOutView.prototype.hide = function () { + this.container.style.display = 'none'; +}; + +LoggedOutView.prototype._handlePaymentMethodGenerated = function (bundle) { + if (bundle.type === constants.NONCE_TYPE) { + this.hide(); + } +}; + +LoggedOutView.prototype._handlePaymentMethodCancelled = function (event) { + if (event.source === constants.PAYPAL_INTEGRATION_NAME) { + this.show(); + } +}; + +LoggedOutView.prototype.teardown = function () { + this.wrapper.removeChild(this.container); + this.bus.teardown(); +}; + +module.exports = LoggedOutView; + +}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) +},{"../../shared/constants":354,"../../shared/get-locale":356,"braintree-bus":312,"braintree-utilities":324}],349:[function(require,module,exports){ +(function (global){ +'use strict'; + +var Bus = require('braintree-bus'); +var braintreeUtil = require('braintree-utilities'); +var constants = require('../../shared/constants'); + +function MerchantPageView(options) { + this.options = options; + + this.bus = new Bus({ + merchantUrl: global.location.href, + channel: options.channel + }); + + this.bus.on(constants.events.UI_MODAL_DID_OPEN, braintreeUtil.bind(this.lockWindowSize, this)); + this.bus.on(constants.events.UI_MODAL_DID_CLOSE, braintreeUtil.bind(this.unlockWindowSize, this)); +} + +MerchantPageView.prototype.lockWindowSize = function () { + this.defaultStyles = getMerchantPageDefaultStyles(); + document.documentElement.style.height = '100%'; + document.documentElement.style.overflow = 'hidden'; + document.body.style.height = '100%'; + document.body.style.overflow = 'hidden'; +}; + +MerchantPageView.prototype.unlockWindowSize = function () { + if (this.defaultStyles) { + document.documentElement.style.height = this.defaultStyles.html.styles.height; + document.documentElement.style.overflow = this.defaultStyles.html.styles.overflow; + document.body.style.height = this.defaultStyles.body.styles.height; + document.body.style.overflow = this.defaultStyles.body.styles.overflow; + delete this.defaultStyles; + } +}; + +MerchantPageView.prototype._handleUIModalDidOpen = function (event) { + if (event.source === constants.PAYPAL_INTEGRATION_NAME) { + this.lockWindowSize(); + } +}; + +MerchantPageView.prototype._handleUIModalDidClose = function (event) { + if (event.source === constants.PAYPAL_INTEGRATION_NAME) { + this.unlockWindowSize(); + } +}; + +MerchantPageView.prototype.teardown = function () { + this.unlockWindowSize(); + this.bus.teardown(); +}; + +function getStyles(element) { + var computedStyles = window.getComputedStyle ? getComputedStyle(element) : element.currentStyle; + return { + overflow: computedStyles.overflow || '', + height: element.style.height || '' + }; +} + +function getMerchantPageDefaultStyles() { + return { + html: { + node: document.documentElement, + styles: getStyles(document.documentElement) + }, + body: { + node: document.body, + styles: getStyles(document.body) + } + }; +} + +module.exports = MerchantPageView; + +}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) +},{"../../shared/constants":354,"braintree-bus":312,"braintree-utilities":324}],350:[function(require,module,exports){ +arguments[4][184][0].apply(exports,arguments) +},{"../../shared/constants":354,"../../shared/util/browser":361,"braintree-bus":312,"braintree-utilities":324,"dup":184,"iframer":328}],351:[function(require,module,exports){ +(function (global){ +'use strict'; +var braintreeUtil = require('braintree-utilities'); +var Destructor = require('destructor'); +var Bus = require('braintree-bus'); +var constants = require('../../shared/constants'); + +function OverlayView(options) { + this.options = options; + this.spriteSrc = this.options.paypalAssetsUrl + '/pwpp/' + constants.VERSION + '/images/pp_overlay_sprite.png'; + + this.bus = new Bus({ + merchantUrl: global.location.href, + channel: options.channel + }); + + this.destructor = new Destructor(); + + this._create(); + this._setupEvents(); + + this.bus.on(Bus.events.UI_POPUP_DID_OPEN, braintreeUtil.bind(this._handleUIPopupDidOpen, this)); + this.bus.on(Bus.events.UI_POPUP_DID_CLOSE, braintreeUtil.bind(this._handleUIPopupDidClose, this)); +} + +OverlayView.prototype.open = function () { + if (document.body.contains(this.el)) { + return; + } + + document.body.appendChild(this.el); +}; + +OverlayView.prototype.close = function () { + if (document.body.contains(this.el)) { + document.body.removeChild(this.el); + } +}; + +OverlayView.prototype._handleUIPopupDidClose = function (event) { + if (event.source === constants.PAYPAL_INTEGRATION_NAME) { + this.close(); + } +}; + +OverlayView.prototype._handleUIPopupDidOpen = function (event) { + if (event.source === constants.PAYPAL_INTEGRATION_NAME) { + this.open(); + } +}; + +OverlayView.prototype._create = function () { + this.el = document.createElement('div'); + + this.el.className = 'bt-overlay'; + + this._setStyles(this.el, [ + 'z-index: 20001', + 'position: fixed', + 'top: 0', + 'left: 0', + 'height: 100%', + 'width: 100%', + 'text-align: center', + 'background: #000', + 'background: rgba(0,0,0,0.7)', + '-ms-filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity=52)"' + ]); + + this.el.appendChild(this._createCloseIcon()); + this.el.appendChild(this._createMessage()); +}; + +OverlayView.prototype._createCloseIcon = function () { + this.closeIcon = document.createElement('div'); + + this.closeIcon.className = 'bt-close-overlay'; + + this._setStyles(this.closeIcon, [ + 'position: absolute', + 'top: 10px', + 'right: 10px', + 'cursor: pointer', + 'background: url(' + this.spriteSrc + ') no-repeat 0 -67px', + 'height: 14px', + 'width: 14px' + ]); + + return this.closeIcon; +}; + +OverlayView.prototype._createMessage = function () { + var message = document.createElement('div'); + + this._setStyles(message, [ + 'position: relative', + 'top: 50%', + 'max-width: 350px', + 'font-family: "HelveticaNeue", "HelveticaNeue-Light", "Helvetica Neue Light", helvetica, arial, sans-serif', + 'font-size: 14px', + 'line-height: 20px', + 'margin: -70px auto 0' + ]); + + message.appendChild(this._createLogo()); + message.appendChild(this._createExplanation()); + message.appendChild(this._createFocusLink()); + + return message; +}; + +OverlayView.prototype._createExplanation = function () { + var explanation = document.createElement('div'); + + this._setStyles(explanation, [ + 'color: #FFF', + 'margin-bottom: 20px' + ]); + + explanation.innerHTML = 'Don\'t see the secure PayPal browser? We\'ll help you re-launch the window to complete your purchase.'; + + return explanation; +}; + +OverlayView.prototype._createLogo = function () { + var logo = document.createElement('div'); + + this._setStyles(logo, [ + 'background: url(' + this.spriteSrc + ') no-repeat 0 0', + 'width: 94px', + 'height: 25px', + 'margin: 0 auto 26px auto' + ]); + + return logo; +}; + +OverlayView.prototype._createFocusLink = function () { + this.focusLink = document.createElement('a'); + + this._setStyles(this.focusLink, [ + 'color: #009be1', + 'cursor: pointer' + ]); + + this.focusLink.innerHTML = 'Continue'; + + return this.focusLink; +}; + +OverlayView.prototype._setStyles = function (el, styles) { + var cssStyles = styles.join(';'); + el.style.cssText = cssStyles; +}; + +OverlayView.prototype._setupEvents = function () { + var clickCloseHandler = braintreeUtil.bind(this._handleClose, this); + var clickFocusHandler = braintreeUtil.bind(this._handleFocus, this); + + braintreeUtil.addEventListener(this.closeIcon, 'click', clickCloseHandler); + braintreeUtil.addEventListener(this.focusLink, 'click', clickFocusHandler); + + this.destructor.registerFunctionForTeardown(braintreeUtil.bind(function () { + braintreeUtil.removeEventListener(this.closeIcon, 'click', clickCloseHandler); + braintreeUtil.removeEventListener(this.focusLink, 'click', clickFocusHandler); + }, this)); +}; + +OverlayView.prototype._handleClose = function (event) { + event.preventDefault(); + this.close(); + + if (braintreeUtil.isFunction(this.options.onClose)) { + this.options.onClose(); + } +}; + +OverlayView.prototype._handleFocus = function (event) { + event.preventDefault(); + + if (braintreeUtil.isFunction(this.options.onFocus)) { + this.options.onFocus(); + } +}; + +OverlayView.prototype.teardown = function () { + this.bus.teardown(); + this.destructor.teardown(); + this.close(); +}; + +module.exports = OverlayView; + +}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) +},{"../../shared/constants":354,"braintree-bus":312,"braintree-utilities":324,"destructor":325}],352:[function(require,module,exports){ +(function (global){ +'use strict'; + +var braintreeUtil = require('braintree-utilities'); +var Destructor = require('destructor'); +var Bus = require('braintree-bus'); +var constants = require('../../shared/constants'); + +function PaymentMethodNonceInputFieldView(options) { + this.options = options || {}; + this.container = this.options.container || document.body; + this.el = this.options.el; + + this.destructor = new Destructor(); + + this.bus = new Bus({ + merchantUrl: global.location.href, + channel: options.channel + }); + + this._initialize(); +} + +PaymentMethodNonceInputFieldView.prototype._initialize = function () { + if (!braintreeUtil.isFunction(this.el)) { + if (this.el != null) { + this.el = braintreeUtil.normalizeElement(this.el); + + this.destructor.registerFunctionForTeardown(braintreeUtil.bind(function () { + this.clear(); + }, this)); + } else { + this.el = this.create(); + } + } + + this.bus.on(Bus.events.PAYMENT_METHOD_GENERATED, braintreeUtil.bind(this._handlePaymentMethodGenerated, this)); + this.bus.on(Bus.events.PAYMENT_METHOD_CANCELLED, braintreeUtil.bind(this._handlePaymentMethodCancelled, this)); +}; + +PaymentMethodNonceInputFieldView.prototype.create = function () { + var input = document.createElement('input'); + input.name = 'payment_method_nonce'; + input.type = 'hidden'; + this.container.appendChild(input); + + this.destructor.registerFunctionForTeardown(braintreeUtil.bind(function () { + this.container.removeChild(input); + }, this)); + + return input; +}; + +PaymentMethodNonceInputFieldView.prototype.value = function (value) { + if (braintreeUtil.isFunction(this.el)) { + this.el(value); + } else { + this.el.value = value; + } +}; + +PaymentMethodNonceInputFieldView.prototype.clear = function () { + this.value(''); +}; + +PaymentMethodNonceInputFieldView.prototype._handlePaymentMethodCancelled = function (event) { + if (event.source === constants.PAYPAL_INTEGRATION_NAME) { + this.clear(); + } +}; + +PaymentMethodNonceInputFieldView.prototype._handlePaymentMethodGenerated = function (bundle) { + if (bundle.type === constants.NONCE_TYPE) { + this.value(bundle.nonce); + } +}; + +PaymentMethodNonceInputFieldView.prototype.teardown = function () { + this.destructor.teardown(); + this.bus.teardown(); +}; + +module.exports = PaymentMethodNonceInputFieldView; + +}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) +},{"../../shared/constants":354,"braintree-bus":312,"braintree-utilities":324,"destructor":325}],353:[function(require,module,exports){ +arguments[4][185][0].apply(exports,arguments) +},{"../../shared/constants":354,"../../shared/useragent/browser":357,"braintree-bus":312,"dup":185}],354:[function(require,module,exports){ +arguments[4][186][0].apply(exports,arguments) +},{"dup":186}],355:[function(require,module,exports){ +'use strict'; + +module.exports = { + us: 'en_us', + gb: 'en_uk', + uk: 'en_uk', + de: 'de_de', + fr: 'fr_fr', + it: 'it_it', + es: 'es_es', + ca: 'en_ca', + au: 'en_au', + at: 'de_de', + be: 'en_us', + ch: 'de_de', + dk: 'da_dk', + nl: 'nl_nl', + no: 'no_no', + pl: 'pl_pl', + se: 'sv_se', + tr: 'tr_tr', + bg: 'en_us', + cy: 'en_us', + hr: 'en_us', + is: 'en_us', + kh: 'en_us', + mt: 'en_us', + my: 'en_us', + ru: 'ru_ru' +}; + +},{}],356:[function(require,module,exports){ +'use strict'; + +var countryCodeLookupTable = require('../shared/data/country-code-lookup'); + +function isFormatted(code) { + return code.indexOf('_') !== -1 && code.length === 5; +} + +function queryTable(code) { + var key, match; + + for (key in countryCodeLookupTable) { + if (countryCodeLookupTable.hasOwnProperty(key)) { + if (key === code) { + match = countryCodeLookupTable[key]; + } else if (countryCodeLookupTable[key] === code) { + match = countryCodeLookupTable[key]; + } + } + } + + return match; +} + +function getLocale(code) { + var match, pieces; + + code = code ? code.toLowerCase() : 'us'; + code = code.replace(/-/g, '_'); + + match = isFormatted(code) ? code : queryTable(code); + + if (match) { + pieces = match.split('_'); + return [pieces[0], pieces[1].toUpperCase()].join('_'); + } + + return 'en_US'; +} + +module.exports = getLocale; + +},{"../shared/data/country-code-lookup":355}],357:[function(require,module,exports){ +arguments[4][187][0].apply(exports,arguments) +},{"./platform":359,"./useragent":360,"dup":187}],358:[function(require,module,exports){ +arguments[4][188][0].apply(exports,arguments) +},{"./platform":359,"./useragent":360,"dup":188}],359:[function(require,module,exports){ +arguments[4][189][0].apply(exports,arguments) +},{"./useragent":360,"dup":189}],360:[function(require,module,exports){ +arguments[4][190][0].apply(exports,arguments) +},{"dup":190}],361:[function(require,module,exports){ +arguments[4][191][0].apply(exports,arguments) +},{"../useragent/browser":357,"../useragent/device":358,"../useragent/platform":359,"../useragent/useragent":360,"dup":191}],362:[function(require,module,exports){ +'use strict'; + +function setTextContent(element, content) { + var property = 'innerText'; + if (document && document.body) { + if ('textContent' in document.body) { + property = 'textContent'; + } + } + element[property] = content; +} + +module.exports = { + setTextContent: setTextContent +}; + +},{}],363:[function(require,module,exports){ +'use strict'; + +var trim = typeof String.prototype.trim === 'function' ? + function (str) { return str.trim(); } : + function (str) { return str.replace(/^\s+|\s+$/, ''); }; + +var b2a = typeof window.btoa === 'function' ? + function (str) { return window.btoa(str); } : + function (str) { + var keyStr = + 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/='; + var output = ''; + var chr1, chr2, chr3, enc1, enc2, enc3, enc4; + var i = 0; + + while (i < str.length) { + chr1 = str.charCodeAt(i++); + chr2 = str.charCodeAt(i++); + chr3 = str.charCodeAt(i++); + + enc1 = chr1 >> 2; + enc2 = (chr1 & 3) << 4 | chr2 >> 4; + enc3 = (chr2 & 15) << 2 | chr3 >> 6; + enc4 = chr3 & 63; + + if (isNaN(chr2)) { + enc3 = enc4 = 64; + } else if (isNaN(chr3)) { + enc4 = 64; + } + + output = output + keyStr.charAt(enc1) + keyStr.charAt(enc2) + + keyStr.charAt(enc3) + keyStr.charAt(enc4); + } + + return output; + }; + +function generateUid() { + var i, r; + var uid = ''; + + for (i = 0; i < 32; i++) { + r = Math.floor(Math.random() * 16); + uid += r.toString(16); + } + + return uid; +} + +function castToBoolean(value) { + return /^(true|1)$/i.test(value); +} + +function htmlEscape(str) { + return str.replace(/&/g, '&') + .replace(//g, '>') + .replace(/\"/g, '"') + .replace(/\'/g, '''); +} + +function parseUrlParams(url) { + var arr, i, n, parts, index, key, value, encodedValue; + var startIndex = url.indexOf('?'); + var values = {}; + + if (startIndex >= 0) { + url = url.substr(startIndex + 1); + } + + if (url.length === 0) { + return null; + } + + arr = url.split('&'); + for (i = 0, n = arr.length; i < n; i++) { + parts = arr[i]; + index = parts.indexOf('='); + key = parts.substr(0, index); + encodedValue = parts.substr(index + 1); + value = decodeURIComponent(encodedValue); + value = value.replace(//g, '>'); + + if (value === 'false') { + value = false; + } + if (value == null || value === 'true') { + value = true; + } + values[key] = value; + } + + return values; +} + +function preventDefault(event) { + if (event.preventDefault) { + event.preventDefault(); + } else { + event.returnValue = false; + } +} + +function isOneTimeHermesConfiguration(options) { + return Boolean(options.singleUse) && Boolean(options.amount) && Boolean(options.currency); +} + +function isBillingAgreementsHermesConfiguration(clientToken) { + return Boolean(clientToken.paypal.billingAgreementsEnabled); +} + +function isHermesConfiguration(clientToken, options) { + return isBillingAgreementsHermesConfiguration(clientToken) || isOneTimeHermesConfiguration(options); +} + +module.exports = { + trim: trim, + btoa: b2a, + generateUid: generateUid, + castToBoolean: castToBoolean, + htmlEscape: htmlEscape, + parseUrlParams: parseUrlParams, + preventDefault: preventDefault, + isOneTimeHermesConfiguration: isOneTimeHermesConfiguration, + isBillingAgreementsHermesConfiguration: isBillingAgreementsHermesConfiguration, + isHermesConfiguration: isHermesConfiguration +}; + +},{}],364:[function(require,module,exports){ +arguments[4][35][0].apply(exports,arguments) +},{"dup":35}],365:[function(require,module,exports){ +arguments[4][36][0].apply(exports,arguments) +},{"dup":36}],366:[function(require,module,exports){ +arguments[4][22][0].apply(exports,arguments) +},{"dup":22}],367:[function(require,module,exports){ +arguments[4][38][0].apply(exports,arguments) +},{"dup":38}],368:[function(require,module,exports){ +arguments[4][39][0].apply(exports,arguments) +},{"dup":39}],369:[function(require,module,exports){ +arguments[4][40][0].apply(exports,arguments) +},{"dup":40}],370:[function(require,module,exports){ +arguments[4][41][0].apply(exports,arguments) +},{"./array":364,"dup":41}],371:[function(require,module,exports){ +arguments[4][42][0].apply(exports,arguments) +},{"dup":42}],372:[function(require,module,exports){ +arguments[4][43][0].apply(exports,arguments) +},{"./lib/array":364,"./lib/base64":365,"./lib/dom":366,"./lib/events":367,"./lib/fn":368,"./lib/string":369,"./lib/url":370,"./lib/uuid":371,"dup":43}],373:[function(require,module,exports){ +arguments[4][80][0].apply(exports,arguments) +},{"batch-execute-functions":374,"braintree-utilities/lib/fn":375,"dup":80}],374:[function(require,module,exports){ +arguments[4][81][0].apply(exports,arguments) +},{"dup":81}],375:[function(require,module,exports){ +arguments[4][39][0].apply(exports,arguments) +},{"dup":39}],376:[function(require,module,exports){ +(function (global){ +'use strict'; + +function FormNapper(form) { + if (typeof form === 'string' || form instanceof String) { + form = document.getElementById(form); + } + + if (form instanceof HTMLFormElement) { + this.htmlForm = form; + } else { + throw new TypeError('FormNapper requires an HTMLFormElement element or the id string of one.'); + } +} + +FormNapper.prototype.hijack = function (onsubmit) { + if (this.submitHandler) { return; } + + this.submitHandler = function (event) { + if (event.preventDefault) { + event.preventDefault(); + } else { + event.returnValue = false; + } + + onsubmit(event); + }; + + if (global.addEventListener != null) { + this.htmlForm.addEventListener('submit', this.submitHandler, false); + } else if (global.attachEvent != null) { + this.htmlForm.attachEvent('onsubmit', this.submitHandler); + } else { + this.htmlForm.onsubmit = this.submitHandler; + } +}; + +FormNapper.prototype.inject = function (name, value) { + var input = this.htmlForm.querySelector('input[name="' + name + '"]'); + + if (input == null) { + input = document.createElement('input'); + input.type = 'hidden'; + input.name = name; + this.htmlForm.appendChild(input); + } + + input.value = value; + + return input; +}; + +FormNapper.prototype.submit = function () { + HTMLFormElement.prototype.submit.call(this.htmlForm); +}; + +FormNapper.prototype.detach = function () { + if (!this.submitHandler) { return; } + + if (global.removeEventListener != null) { + this.htmlForm.removeEventListener('submit', this.submitHandler, false); + } else if (global.detachEvent != null) { + this.htmlForm.detachEvent('onsubmit', this.submitHandler); + } else { + this.htmlForm.onsubmit = null; + } + + delete this.submitHandler; +}; + +module.exports = FormNapper; + +}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) +},{}],377:[function(require,module,exports){ +var HostedFields = require('./lib/external'); +var events = require('./lib/shared/constants').events; +var VERSION = "1.0.0"; + +module.exports = { + create: function (configuration) { + return new HostedFields(configuration); + }, + events: events, + VERSION: VERSION +}; + +},{"./lib/external":379,"./lib/shared/constants":381}],378:[function(require,module,exports){ +var constants = require('../shared/constants'); + +module.exports = function composeUrl(assetsUrl, channel) { + return assetsUrl + + '/hosted-fields/' + + constants.VERSION + + '/hosted-fields-frame.html#' + + channel; +}; + +},{"../shared/constants":381}],379:[function(require,module,exports){ +'use strict'; + +var Destructor = require('destructor'); +var classListManager = require('classlist'); +var iFramer = require('iframer'); +var Bus = require('braintree-bus'); +var composeUrl = require('./compose-url'); +var constants = require('../shared/constants'); +var nodeListToArray = require('nodelist-to-array'); +var utils = require('braintree-utilities'); +var findParentTags = require('../shared/find-parent-tags'); +var shouldUseLabelFocus = require('./should-use-label-focus'); +var events = constants.events; + +function injectFrame(frame, container) { + var clearboth = document.createElement('div'); + + clearboth.style.clear = 'both'; + + container = container || document.body; + + container.appendChild(frame); + container.appendChild(clearboth); + + return { + parent: container, + children: [frame, clearboth] + }; +} + +function inputEventHandler(fields, onFieldEvent) { + return function (eventData) { + var container = fields[eventData.fieldKey].containerElement; + var classList = classListManager(container); + + eventData.target = { + fieldKey: eventData.fieldKey, + container: container + }; + + classList + .toggle(constants.externalClasses.FOCUSED, eventData.isFocused) + .toggle(constants.externalClasses.VALID, eventData.isValid); + if (eventData.isStrictlyValidating) { + classList.toggle(constants.externalClasses.INVALID, !eventData.isValid); + } else { + classList.toggle(constants.externalClasses.INVALID, !eventData.isPotentiallyValid); + } + + delete eventData.fieldKey; + delete eventData.isStrictlyValidating; + + if (onFieldEvent) { + onFieldEvent(eventData); + } + }; +} + +function HostedFieldsIntegration(configuration) { + var type, field, container, frame, i, msg; + var fields = {}; + var fieldCount = 0; + + this.injectedNodes = []; + this.destructor = new Destructor(); + + this.bus = new Bus({ + channel: configuration.channel, + merchantUrl: location.href + }); + + this.destructor.registerFunctionForTeardown(utils.bind(function () { + this.bus.teardown(); + }, this)); + + this.bus.emit(Bus.events.ASYNC_DEPENDENCY_INITIALIZING); + this.bus.emit(Bus.events.SEND_ANALYTICS_EVENTS, 'hosted-fields.initialized'); + + for (i = 0; i < constants.whitelistedFields.length; i++) { + type = constants.whitelistedFields[i]; + field = configuration.merchantConfiguration.hostedFields[type]; + + if (!field) { continue; } + + container = document.querySelector(field.selector); + + if (!container) { + msg = 'Unable to find element with selector "' + field.selector + '" for hostedFields.' + type; + this.bus.emit(Bus.events.ERROR, { + message: msg + }); + continue; + } else if (container.querySelector('iframe[name^="braintree-"]')) { + this.bus.emit(Bus.events.ERROR, { + message: 'Cannot place two elements in "' + field.selector + '"' + }); + continue; + } + + frame = iFramer({ + type: type, + name: 'braintree-hosted-field-' + type, + style: constants.defaultIFrameStyle + }); + + this.injectedNodes.push(injectFrame(frame, container)); + this.setupLabelFocus(type, container); + fields[type] = { + frameElement: frame, + containerElement: container + }; + fieldCount++; + + /* eslint-disable no-loop-func */ + setTimeout((function (f) { + return function () { + f.src = composeUrl( + configuration.gatewayConfiguration.assetsUrl, + configuration.channel + ); + }; + })(frame), 0); + } /* eslint-enable no-loop-func */ + + this.bus.on(events.FRAME_READY, function (reply) { + fieldCount--; + if (fieldCount === 0) { + reply(true); + } else { + reply(false); + } + }); + + this.bus.on( + events.INPUT_EVENT, + inputEventHandler(fields, configuration.merchantConfiguration.hostedFields.onFieldEvent) + ); + + this.destructor.registerFunctionForTeardown(utils.bind(function () { + var j, k, nodeGroup; + + for (j = 0; j < this.injectedNodes.length; j++) { + nodeGroup = this.injectedNodes[j]; + + for (k = 0; k < nodeGroup.children.length; k++) { + nodeGroup.parent.removeChild(nodeGroup.children[k]); + } + + classListManager(nodeGroup.parent).remove( + constants.externalClasses.FOCUSED, + constants.externalClasses.INVALID, + constants.externalClasses.VALID + ); + } + }, this)); +} + +HostedFieldsIntegration.prototype.setupLabelFocus = function (type, container) { + var labels, i; + var bus = this.bus; + + if (!shouldUseLabelFocus()) { return; } + if (container.id == null) { return; } + + function triggerFocus() { + bus.emit(events.TRIGGER_INPUT_FOCUS, type); + } + + labels = nodeListToArray(document.querySelectorAll('label[for="' + container.id + '"]')); + labels = labels.concat(findParentTags(container, 'label')); + + for (i = 0; i < labels.length; i++) { + utils.addEventListener(labels[i], 'click', triggerFocus, false); + } + + this.destructor.registerFunctionForTeardown(function () { + for (i = 0; i < labels.length; i++) { + utils.removeEventListener(labels[i], 'click', triggerFocus, false); + } + }); +}; + +HostedFieldsIntegration.prototype.teardown = function (done) { + this.destructor.teardown(done); +}; + +module.exports = HostedFieldsIntegration; + +},{"../shared/constants":381,"../shared/find-parent-tags":382,"./compose-url":378,"./should-use-label-focus":380,"braintree-bus":383,"braintree-utilities":395,"classlist":396,"destructor":399,"iframer":402,"nodelist-to-array":417}],380:[function(require,module,exports){ +'use strict'; + +module.exports = function shouldUseLabelFocus() { + return !/(iPad|iPhone|iPod)/i.test(navigator.userAgent); +}; + +},{}],381:[function(require,module,exports){ +/*eslint-disable no-reserved-keys */ +'use strict'; + +var VERSION = "1.0.0"; + +module.exports = { + VERSION: VERSION, + events: { + FRAME_READY: 'hosted-fields:FRAME_READY', + VALIDATE_STRICT: 'hosted-fields:VALIDATE_STRICT', + CONFIGURATION: 'hosted-fields:CONFIGURATION', + TOKENIZATION_REQUEST: 'hosted-fields:TOKENIZATION_REQUEST', + INPUT_EVENT: 'hosted-fields:INPUT_EVENT', + TRIGGER_INPUT_FOCUS: 'hosted-fields:TRIGGER_INPUT_FOCUS' + }, + externalEvents: { + FOCUS: 'focus', + BLUR: 'blur', + FIELD_STATE_CHANGE: 'fieldStateChange' + }, + defaultMaxLengths: { + number: 19, + postalCode: 8, + expirationDate: 7, + expirationMonth: 2, + expirationYear: 4, + cvv: 3 + }, + externalClasses: { + FOCUSED: 'braintree-hosted-fields-focused', + INVALID: 'braintree-hosted-fields-invalid', + VALID: 'braintree-hosted-fields-valid' + }, + defaultIFrameStyle: { + border: 'none', + width: '100%', + height: '100%', + float: 'left' + }, + whitelistedFields: [ + 'number', + 'cvv', + 'expirationDate', + 'expirationMonth', + 'expirationYear', + 'postalCode' + ], + whitelistedStyles: [ + '-moz-osx-font-smoothing', + '-moz-transition', + '-webkit-font-smoothing', + '-webkit-transition', + 'color', + 'font', + 'font-family', + 'font-size', + 'font-size-adjust', + 'font-stretch', + 'font-style', + 'font-variant', + 'font-variant-alternates', + 'font-variant-caps', + 'font-variant-east-asian', + 'font-variant-ligatures', + 'font-variant-numeric', + 'font-weight', + 'line-height', + 'opacity', + 'outline', + 'text-shadow', + 'transition' + ], + passwordManagerFields: { + number: { + name: 'credit-card-number', + label: 'Credit Card Number' + }, + expirationDate: { + name: 'expiration', + label: 'Expiration Date' + }, + postalCode: { + name: 'postal-code', + label: 'Postal Code' + } + } +}; + +},{}],382:[function(require,module,exports){ +'use strict'; + +function findParentTags(element, tag) { + var parent = element.parentNode; + var parents = []; + + while (parent != null) { + if (parent.tagName != null && parent.tagName.toLowerCase() === tag) { + parents.push(parent); + } + + parent = parent.parentNode; + } + + return parents; +} + +module.exports = findParentTags; + +},{}],383:[function(require,module,exports){ +arguments[4][52][0].apply(exports,arguments) +},{"./lib/check-origin":384,"./lib/events":385,"dup":52,"framebus":386}],384:[function(require,module,exports){ +arguments[4][53][0].apply(exports,arguments) +},{"dup":53}],385:[function(require,module,exports){ +arguments[4][54][0].apply(exports,arguments) +},{"dup":54}],386:[function(require,module,exports){ +arguments[4][55][0].apply(exports,arguments) +},{"dup":55}],387:[function(require,module,exports){ +arguments[4][35][0].apply(exports,arguments) +},{"dup":35}],388:[function(require,module,exports){ +arguments[4][36][0].apply(exports,arguments) +},{"dup":36}],389:[function(require,module,exports){ +arguments[4][22][0].apply(exports,arguments) +},{"dup":22}],390:[function(require,module,exports){ +arguments[4][38][0].apply(exports,arguments) +},{"dup":38}],391:[function(require,module,exports){ +arguments[4][39][0].apply(exports,arguments) +},{"dup":39}],392:[function(require,module,exports){ +arguments[4][40][0].apply(exports,arguments) +},{"dup":40}],393:[function(require,module,exports){ +arguments[4][41][0].apply(exports,arguments) +},{"./array":387,"dup":41}],394:[function(require,module,exports){ +arguments[4][42][0].apply(exports,arguments) +},{"dup":42}],395:[function(require,module,exports){ +arguments[4][43][0].apply(exports,arguments) +},{"./lib/array":387,"./lib/base64":388,"./lib/dom":389,"./lib/events":390,"./lib/fn":391,"./lib/string":392,"./lib/url":393,"./lib/uuid":394,"dup":43}],396:[function(require,module,exports){ +'use strict'; + +module.exports = ClassList + +var indexOf = require('component-indexof'), + trim = require('trim'), + arr = Array.prototype + +/** + * ClassList(elem) is kind of like Element#classList. + * + * @param {Element} elem + * @return {ClassList} + */ +function ClassList (elem) { + if (!(this instanceof ClassList)) + return new ClassList(elem) + + var classes = trim(elem.className).split(/\s+/), + i + + this._elem = elem + + this.length = 0 + + for (i = 0; i < classes.length; i += 1) { + if (classes[i]) + arr.push.call(this, classes[i]) + } +} + +/** + * add(class1 [, class2 [, ...]]) adds the given class(es) to the + * element. + * + * @param {String} ... + * @return {Context} + */ +ClassList.prototype.add = function () { + var name, + i + + for (i = 0; i < arguments.length; i += 1) { + name = '' + arguments[i] + + if (indexOf(this, name) >= 0) + continue + + arr.push.call(this, name) + } + + this._elem.className = this.toString() + + return this +} + +/** + * remove(class1 [, class2 [, ...]]) removes the given class(es) from + * the element. + * + * @param {String} ... + * @return {Context} + */ +ClassList.prototype.remove = function () { + var index, + name, + i + + for (i = 0; i < arguments.length; i += 1) { + name = '' + arguments[i] + index = indexOf(this, name) + + if (index < 0) continue + + arr.splice.call(this, index, 1) + } + + this._elem.className = this.toString() + + return this +} + +/** + * contains(name) determines if the element has a given class. + * + * @param {String} name + * @return {Boolean} + */ +ClassList.prototype.contains = function (name) { + name += '' + return indexOf(this, name) >= 0 +} + +/** + * toggle(name [, force]) toggles a class. If force is a boolean, + * this method is basically just an alias for add/remove. + * + * @param {String} name + * @param {Boolean} force + * @return {Context} + */ +ClassList.prototype.toggle = function (name, force) { + name += '' + + if (force === true) return this.add(name) + if (force === false) return this.remove(name) + + return this[this.contains(name) ? 'remove' : 'add'](name) +} + +/** + * toString() returns the className of the element. + * + * @return {String} + */ +ClassList.prototype.toString = function () { + return arr.join.call(this, ' ') +} + +},{"component-indexof":397,"trim":398}],397:[function(require,module,exports){ +module.exports = function(arr, obj){ + if (arr.indexOf) return arr.indexOf(obj); + for (var i = 0; i < arr.length; ++i) { + if (arr[i] === obj) return i; + } + return -1; +}; +},{}],398:[function(require,module,exports){ + +exports = module.exports = trim; + +function trim(str){ + return str.replace(/^\s*|\s*$/g, ''); +} + +exports.left = function(str){ + return str.replace(/^\s*/, ''); +}; + +exports.right = function(str){ + return str.replace(/\s*$/, ''); +}; + +},{}],399:[function(require,module,exports){ +arguments[4][80][0].apply(exports,arguments) +},{"batch-execute-functions":400,"braintree-utilities/lib/fn":401,"dup":80}],400:[function(require,module,exports){ +arguments[4][81][0].apply(exports,arguments) +},{"dup":81}],401:[function(require,module,exports){ +arguments[4][39][0].apply(exports,arguments) +},{"dup":39}],402:[function(require,module,exports){ +arguments[4][83][0].apply(exports,arguments) +},{"./lib/default-attributes":403,"dup":83,"lodash.assign":406,"lodash.isstring":404,"setattributes":405}],403:[function(require,module,exports){ +arguments[4][84][0].apply(exports,arguments) +},{"dup":84}],404:[function(require,module,exports){ +arguments[4][51][0].apply(exports,arguments) +},{"dup":51}],405:[function(require,module,exports){ +arguments[4][97][0].apply(exports,arguments) +},{"dup":97}],406:[function(require,module,exports){ +arguments[4][85][0].apply(exports,arguments) +},{"dup":85,"lodash._baseassign":407,"lodash._createassigner":409,"lodash.keys":413}],407:[function(require,module,exports){ +arguments[4][86][0].apply(exports,arguments) +},{"dup":86,"lodash._basecopy":408,"lodash.keys":413}],408:[function(require,module,exports){ +arguments[4][87][0].apply(exports,arguments) +},{"dup":87}],409:[function(require,module,exports){ +arguments[4][88][0].apply(exports,arguments) +},{"dup":88,"lodash._bindcallback":410,"lodash._isiterateecall":411,"lodash.restparam":412}],410:[function(require,module,exports){ +arguments[4][89][0].apply(exports,arguments) +},{"dup":89}],411:[function(require,module,exports){ +arguments[4][90][0].apply(exports,arguments) +},{"dup":90}],412:[function(require,module,exports){ +arguments[4][91][0].apply(exports,arguments) +},{"dup":91}],413:[function(require,module,exports){ +arguments[4][48][0].apply(exports,arguments) +},{"dup":48,"lodash._getnative":414,"lodash.isarguments":415,"lodash.isarray":416}],414:[function(require,module,exports){ +arguments[4][49][0].apply(exports,arguments) +},{"dup":49}],415:[function(require,module,exports){ +arguments[4][45][0].apply(exports,arguments) +},{"dup":45}],416:[function(require,module,exports){ +arguments[4][46][0].apply(exports,arguments) +},{"dup":46}],417:[function(require,module,exports){ +function nodeListToArray(nodeList) { + try { + return Array.prototype.slice.call(nodeList); + } catch (err) { + var result = []; + for (var i = 0; i < nodeList.length; i++) { + result.push(nodeList[i]); + } + return result; + } +} + +if (typeof module !== 'undefined') { + module.exports = nodeListToArray; +} + +},{}],418:[function(require,module,exports){ +/** + * lodash 3.0.2 (Custom Build) + * Build: `lodash modern modularize exports="npm" -o ./` + * Copyright 2012-2015 The Dojo Foundation + * Based on Underscore.js 1.8.3 + * Copyright 2009-2015 Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors + * Available under MIT license + */ +var baseClone = require('lodash._baseclone'), + bindCallback = require('lodash._bindcallback'); + +/** + * Creates a deep clone of `value`. If `customizer` is provided it's invoked + * to produce the cloned values. If `customizer` returns `undefined` cloning + * is handled by the method instead. The `customizer` is bound to `thisArg` + * and invoked with up to three argument; (value [, index|key, object]). + * + * **Note:** This method is loosely based on the + * [structured clone algorithm](http://www.w3.org/TR/html5/infrastructure.html#internal-structured-cloning-algorithm). + * The enumerable properties of `arguments` objects and objects created by + * constructors other than `Object` are cloned to plain `Object` objects. An + * empty object is returned for uncloneable values such as functions, DOM nodes, + * Maps, Sets, and WeakMaps. + * + * @static + * @memberOf _ + * @category Lang + * @param {*} value The value to deep clone. + * @param {Function} [customizer] The function to customize cloning values. + * @param {*} [thisArg] The `this` binding of `customizer`. + * @returns {*} Returns the deep cloned value. + * @example + * + * var users = [ + * { 'user': 'barney' }, + * { 'user': 'fred' } + * ]; + * + * var deep = _.cloneDeep(users); + * deep[0] === users[0]; + * // => false + * + * // using a customizer callback + * var el = _.cloneDeep(document.body, function(value) { + * if (_.isElement(value)) { + * return value.cloneNode(true); + * } + * }); + * + * el === document.body + * // => false + * el.nodeName + * // => BODY + * el.childNodes.length; + * // => 20 + */ +function cloneDeep(value, customizer, thisArg) { + return typeof customizer == 'function' + ? baseClone(value, true, bindCallback(customizer, thisArg, 3)) + : baseClone(value, true); +} + +module.exports = cloneDeep; + +},{"lodash._baseclone":419,"lodash._bindcallback":429}],419:[function(require,module,exports){ +(function (global){ +/** + * lodash 3.3.0 (Custom Build) + * Build: `lodash modern modularize exports="npm" -o ./` + * Copyright 2012-2015 The Dojo Foundation + * Based on Underscore.js 1.8.3 + * Copyright 2009-2015 Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors + * Available under MIT license + */ +var arrayCopy = require('lodash._arraycopy'), + arrayEach = require('lodash._arrayeach'), + baseAssign = require('lodash._baseassign'), + baseFor = require('lodash._basefor'), + isArray = require('lodash.isarray'), + keys = require('lodash.keys'); + +/** `Object#toString` result references. */ +var argsTag = '[object Arguments]', + arrayTag = '[object Array]', + boolTag = '[object Boolean]', + dateTag = '[object Date]', + errorTag = '[object Error]', + funcTag = '[object Function]', + mapTag = '[object Map]', + numberTag = '[object Number]', + objectTag = '[object Object]', + regexpTag = '[object RegExp]', + setTag = '[object Set]', + stringTag = '[object String]', + weakMapTag = '[object WeakMap]'; + +var arrayBufferTag = '[object ArrayBuffer]', + float32Tag = '[object Float32Array]', + float64Tag = '[object Float64Array]', + int8Tag = '[object Int8Array]', + int16Tag = '[object Int16Array]', + int32Tag = '[object Int32Array]', + uint8Tag = '[object Uint8Array]', + uint8ClampedTag = '[object Uint8ClampedArray]', + uint16Tag = '[object Uint16Array]', + uint32Tag = '[object Uint32Array]'; + +/** Used to match `RegExp` flags from their coerced string values. */ +var reFlags = /\w*$/; + +/** Used to identify `toStringTag` values supported by `_.clone`. */ +var cloneableTags = {}; +cloneableTags[argsTag] = cloneableTags[arrayTag] = +cloneableTags[arrayBufferTag] = cloneableTags[boolTag] = +cloneableTags[dateTag] = cloneableTags[float32Tag] = +cloneableTags[float64Tag] = cloneableTags[int8Tag] = +cloneableTags[int16Tag] = cloneableTags[int32Tag] = +cloneableTags[numberTag] = cloneableTags[objectTag] = +cloneableTags[regexpTag] = cloneableTags[stringTag] = +cloneableTags[uint8Tag] = cloneableTags[uint8ClampedTag] = +cloneableTags[uint16Tag] = cloneableTags[uint32Tag] = true; +cloneableTags[errorTag] = cloneableTags[funcTag] = +cloneableTags[mapTag] = cloneableTags[setTag] = +cloneableTags[weakMapTag] = false; + +/** Used for native method references. */ +var objectProto = Object.prototype; + +/** Used to check objects for own properties. */ +var hasOwnProperty = objectProto.hasOwnProperty; + +/** + * Used to resolve the [`toStringTag`](http://ecma-international.org/ecma-262/6.0/#sec-object.prototype.tostring) + * of values. + */ +var objToString = objectProto.toString; + +/** Native method references. */ +var ArrayBuffer = global.ArrayBuffer, + Uint8Array = global.Uint8Array; + +/** + * The base implementation of `_.clone` without support for argument juggling + * and `this` binding `customizer` functions. + * + * @private + * @param {*} value The value to clone. + * @param {boolean} [isDeep] Specify a deep clone. + * @param {Function} [customizer] The function to customize cloning values. + * @param {string} [key] The key of `value`. + * @param {Object} [object] The object `value` belongs to. + * @param {Array} [stackA=[]] Tracks traversed source objects. + * @param {Array} [stackB=[]] Associates clones with source counterparts. + * @returns {*} Returns the cloned value. + */ +function baseClone(value, isDeep, customizer, key, object, stackA, stackB) { + var result; + if (customizer) { + result = object ? customizer(value, key, object) : customizer(value); + } + if (result !== undefined) { + return result; + } + if (!isObject(value)) { + return value; + } + var isArr = isArray(value); + if (isArr) { + result = initCloneArray(value); + if (!isDeep) { + return arrayCopy(value, result); + } + } else { + var tag = objToString.call(value), + isFunc = tag == funcTag; + + if (tag == objectTag || tag == argsTag || (isFunc && !object)) { + result = initCloneObject(isFunc ? {} : value); + if (!isDeep) { + return baseAssign(result, value); + } + } else { + return cloneableTags[tag] + ? initCloneByTag(value, tag, isDeep) + : (object ? value : {}); + } + } + // Check for circular references and return its corresponding clone. + stackA || (stackA = []); + stackB || (stackB = []); + + var length = stackA.length; + while (length--) { + if (stackA[length] == value) { + return stackB[length]; + } + } + // Add the source value to the stack of traversed objects and associate it with its clone. + stackA.push(value); + stackB.push(result); + + // Recursively populate clone (susceptible to call stack limits). + (isArr ? arrayEach : baseForOwn)(value, function(subValue, key) { + result[key] = baseClone(subValue, isDeep, customizer, key, value, stackA, stackB); + }); + return result; +} + +/** + * The base implementation of `_.forOwn` without support for callback + * shorthands and `this` binding. + * + * @private + * @param {Object} object The object to iterate over. + * @param {Function} iteratee The function invoked per iteration. + * @returns {Object} Returns `object`. + */ +function baseForOwn(object, iteratee) { + return baseFor(object, iteratee, keys); +} + +/** + * Creates a clone of the given array buffer. + * + * @private + * @param {ArrayBuffer} buffer The array buffer to clone. + * @returns {ArrayBuffer} Returns the cloned array buffer. + */ +function bufferClone(buffer) { + var result = new ArrayBuffer(buffer.byteLength), + view = new Uint8Array(result); + + view.set(new Uint8Array(buffer)); + return result; +} + +/** + * Initializes an array clone. + * + * @private + * @param {Array} array The array to clone. + * @returns {Array} Returns the initialized clone. + */ +function initCloneArray(array) { + var length = array.length, + result = new array.constructor(length); + + // Add array properties assigned by `RegExp#exec`. + if (length && typeof array[0] == 'string' && hasOwnProperty.call(array, 'index')) { + result.index = array.index; + result.input = array.input; + } + return result; +} + +/** + * Initializes an object clone. + * + * @private + * @param {Object} object The object to clone. + * @returns {Object} Returns the initialized clone. + */ +function initCloneObject(object) { + var Ctor = object.constructor; + if (!(typeof Ctor == 'function' && Ctor instanceof Ctor)) { + Ctor = Object; + } + return new Ctor; +} + +/** + * Initializes an object clone based on its `toStringTag`. + * + * **Note:** This function only supports cloning values with tags of + * `Boolean`, `Date`, `Error`, `Number`, `RegExp`, or `String`. + * + * @private + * @param {Object} object The object to clone. + * @param {string} tag The `toStringTag` of the object to clone. + * @param {boolean} [isDeep] Specify a deep clone. + * @returns {Object} Returns the initialized clone. + */ +function initCloneByTag(object, tag, isDeep) { + var Ctor = object.constructor; + switch (tag) { + case arrayBufferTag: + return bufferClone(object); + + case boolTag: + case dateTag: + return new Ctor(+object); + + case float32Tag: case float64Tag: + case int8Tag: case int16Tag: case int32Tag: + case uint8Tag: case uint8ClampedTag: case uint16Tag: case uint32Tag: + var buffer = object.buffer; + return new Ctor(isDeep ? bufferClone(buffer) : buffer, object.byteOffset, object.length); + + case numberTag: + case stringTag: + return new Ctor(object); + + case regexpTag: + var result = new Ctor(object.source, reFlags.exec(object)); + result.lastIndex = object.lastIndex; + } + return result; +} + +/** + * Checks if `value` is the [language type](https://es5.github.io/#x8) of `Object`. + * (e.g. arrays, functions, objects, regexes, `new Number(0)`, and `new String('')`) + * + * @static + * @memberOf _ + * @category Lang + * @param {*} value The value to check. + * @returns {boolean} Returns `true` if `value` is an object, else `false`. + * @example + * + * _.isObject({}); + * // => true + * + * _.isObject([1, 2, 3]); + * // => true + * + * _.isObject(1); + * // => false + */ +function isObject(value) { + // Avoid a V8 JIT bug in Chrome 19-20. + // See https://code.google.com/p/v8/issues/detail?id=2291 for more details. + var type = typeof value; + return !!value && (type == 'object' || type == 'function'); +} + +module.exports = baseClone; + +}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) +},{"lodash._arraycopy":420,"lodash._arrayeach":421,"lodash._baseassign":422,"lodash._basefor":424,"lodash.isarray":425,"lodash.keys":426}],420:[function(require,module,exports){ +/** + * lodash 3.0.0 (Custom Build) + * Build: `lodash modern modularize exports="npm" -o ./` + * Copyright 2012-2015 The Dojo Foundation + * Based on Underscore.js 1.7.0 + * Copyright 2009-2015 Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors + * Available under MIT license + */ + +/** + * Copies the values of `source` to `array`. + * + * @private + * @param {Array} source The array to copy values from. + * @param {Array} [array=[]] The array to copy values to. + * @returns {Array} Returns `array`. + */ +function arrayCopy(source, array) { + var index = -1, + length = source.length; + + array || (array = Array(length)); + while (++index < length) { + array[index] = source[index]; + } + return array; +} + +module.exports = arrayCopy; + +},{}],421:[function(require,module,exports){ +/** + * lodash 3.0.0 (Custom Build) + * Build: `lodash modern modularize exports="npm" -o ./` + * Copyright 2012-2015 The Dojo Foundation + * Based on Underscore.js 1.7.0 + * Copyright 2009-2015 Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors + * Available under MIT license + */ + +/** + * A specialized version of `_.forEach` for arrays without support for callback + * shorthands or `this` binding. + * + * @private + * @param {Array} array The array to iterate over. + * @param {Function} iteratee The function invoked per iteration. + * @returns {Array} Returns `array`. + */ +function arrayEach(array, iteratee) { + var index = -1, + length = array.length; + + while (++index < length) { + if (iteratee(array[index], index, array) === false) { + break; + } + } + return array; +} + +module.exports = arrayEach; + +},{}],422:[function(require,module,exports){ +arguments[4][86][0].apply(exports,arguments) +},{"dup":86,"lodash._basecopy":423,"lodash.keys":426}],423:[function(require,module,exports){ +arguments[4][87][0].apply(exports,arguments) +},{"dup":87}],424:[function(require,module,exports){ +/** + * lodash 3.0.2 (Custom Build) + * Build: `lodash modern modularize exports="npm" -o ./` + * Copyright 2012-2015 The Dojo Foundation + * Based on Underscore.js 1.8.3 + * Copyright 2009-2015 Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors + * Available under MIT license + */ + +/** + * The base implementation of `baseForIn` and `baseForOwn` which iterates + * over `object` properties returned by `keysFunc` invoking `iteratee` for + * each property. Iteratee functions may exit iteration early by explicitly + * returning `false`. + * + * @private + * @param {Object} object The object to iterate over. + * @param {Function} iteratee The function invoked per iteration. + * @param {Function} keysFunc The function to get the keys of `object`. + * @returns {Object} Returns `object`. + */ +var baseFor = createBaseFor(); + +/** + * Creates a base function for `_.forIn` or `_.forInRight`. + * + * @private + * @param {boolean} [fromRight] Specify iterating from right to left. + * @returns {Function} Returns the new base function. + */ +function createBaseFor(fromRight) { + return function(object, iteratee, keysFunc) { + var iterable = toObject(object), + props = keysFunc(object), + length = props.length, + index = fromRight ? length : -1; + + while ((fromRight ? index-- : ++index < length)) { + var key = props[index]; + if (iteratee(iterable[key], key, iterable) === false) { + break; + } + } + return object; + }; +} + +/** + * Converts `value` to an object if it's not one. + * + * @private + * @param {*} value The value to process. + * @returns {Object} Returns the object. + */ +function toObject(value) { + return isObject(value) ? value : Object(value); +} + +/** + * Checks if `value` is the [language type](https://es5.github.io/#x8) of `Object`. + * (e.g. arrays, functions, objects, regexes, `new Number(0)`, and `new String('')`) + * + * @static + * @memberOf _ + * @category Lang + * @param {*} value The value to check. + * @returns {boolean} Returns `true` if `value` is an object, else `false`. + * @example + * + * _.isObject({}); + * // => true + * + * _.isObject([1, 2, 3]); + * // => true + * + * _.isObject(1); + * // => false + */ +function isObject(value) { + // Avoid a V8 JIT bug in Chrome 19-20. + // See https://code.google.com/p/v8/issues/detail?id=2291 for more details. + var type = typeof value; + return !!value && (type == 'object' || type == 'function'); +} + +module.exports = baseFor; + +},{}],425:[function(require,module,exports){ +arguments[4][46][0].apply(exports,arguments) +},{"dup":46}],426:[function(require,module,exports){ +arguments[4][48][0].apply(exports,arguments) +},{"dup":48,"lodash._getnative":427,"lodash.isarguments":428,"lodash.isarray":425}],427:[function(require,module,exports){ +arguments[4][49][0].apply(exports,arguments) +},{"dup":49}],428:[function(require,module,exports){ +arguments[4][45][0].apply(exports,arguments) +},{"dup":45}],429:[function(require,module,exports){ +arguments[4][89][0].apply(exports,arguments) +},{"dup":89}],430:[function(require,module,exports){ +/** + * lodash 3.1.1 (Custom Build) + * Build: `lodash modern modularize exports="npm" -o ./` + * Copyright 2012-2015 The Dojo Foundation + * Based on Underscore.js 1.8.3 + * Copyright 2009-2015 Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors + * Available under MIT license + */ +var baseAssign = require('lodash._baseassign'), + baseCreate = require('lodash._basecreate'), + isIterateeCall = require('lodash._isiterateecall'); + +/** + * Creates an object that inherits from the given `prototype` object. If a + * `properties` object is provided its own enumerable properties are assigned + * to the created object. + * + * @static + * @memberOf _ + * @category Object + * @param {Object} prototype The object to inherit from. + * @param {Object} [properties] The properties to assign to the object. + * @param- {Object} [guard] Enables use as a callback for functions like `_.map`. + * @returns {Object} Returns the new object. + * @example + * + * function Shape() { + * this.x = 0; + * this.y = 0; + * } + * + * function Circle() { + * Shape.call(this); + * } + * + * Circle.prototype = _.create(Shape.prototype, { + * 'constructor': Circle + * }); + * + * var circle = new Circle; + * circle instanceof Circle; + * // => true + * + * circle instanceof Shape; + * // => true + */ +function create(prototype, properties, guard) { + var result = baseCreate(prototype); + if (guard && isIterateeCall(prototype, properties, guard)) { + properties = undefined; + } + return properties ? baseAssign(result, properties) : result; +} + +module.exports = create; + +},{"lodash._baseassign":431,"lodash._basecreate":437,"lodash._isiterateecall":438}],431:[function(require,module,exports){ +arguments[4][86][0].apply(exports,arguments) +},{"dup":86,"lodash._basecopy":432,"lodash.keys":433}],432:[function(require,module,exports){ +arguments[4][87][0].apply(exports,arguments) +},{"dup":87}],433:[function(require,module,exports){ +arguments[4][48][0].apply(exports,arguments) +},{"dup":48,"lodash._getnative":434,"lodash.isarguments":435,"lodash.isarray":436}],434:[function(require,module,exports){ +arguments[4][49][0].apply(exports,arguments) +},{"dup":49}],435:[function(require,module,exports){ +arguments[4][45][0].apply(exports,arguments) +},{"dup":45}],436:[function(require,module,exports){ +arguments[4][46][0].apply(exports,arguments) +},{"dup":46}],437:[function(require,module,exports){ +/** + * lodash 3.0.3 (Custom Build) + * Build: `lodash modern modularize exports="npm" -o ./` + * Copyright 2012-2015 The Dojo Foundation + * Based on Underscore.js 1.8.3 + * Copyright 2009-2015 Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors + * Available under MIT license + */ + +/** + * The base implementation of `_.create` without support for assigning + * properties to the created object. + * + * @private + * @param {Object} prototype The object to inherit from. + * @returns {Object} Returns the new object. + */ +var baseCreate = (function() { + function object() {} + return function(prototype) { + if (isObject(prototype)) { + object.prototype = prototype; + var result = new object; + object.prototype = undefined; + } + return result || {}; + }; +}()); + +/** + * Checks if `value` is the [language type](https://es5.github.io/#x8) of `Object`. + * (e.g. arrays, functions, objects, regexes, `new Number(0)`, and `new String('')`) + * + * @static + * @memberOf _ + * @category Lang + * @param {*} value The value to check. + * @returns {boolean} Returns `true` if `value` is an object, else `false`. + * @example + * + * _.isObject({}); + * // => true + * + * _.isObject([1, 2, 3]); + * // => true + * + * _.isObject(1); + * // => false + */ +function isObject(value) { + // Avoid a V8 JIT bug in Chrome 19-20. + // See https://code.google.com/p/v8/issues/detail?id=2291 for more details. + var type = typeof value; + return !!value && (type == 'object' || type == 'function'); +} + +module.exports = baseCreate; + +},{}],438:[function(require,module,exports){ +arguments[4][90][0].apply(exports,arguments) +},{"dup":90}],439:[function(require,module,exports){ +'use strict'; +/* eslint-disable consistent-return */ + +function convertToLegacyShippingAddress(address) { + var prop; + var legacyShippingAddress = {}; + + if (!address) { + return; + } + + for (prop in address) { + if (address.hasOwnProperty(prop)) { + legacyShippingAddress[toSnakeCase(prop)] = address[prop]; + } + } + + return legacyShippingAddress; +} + +function toSnakeCase(string) { + return string.replace(/([A-Z])/g, function ($1) { + return '_' + $1.toLowerCase(); + }); +} + +module.exports = {convertToLegacyShippingAddress: convertToLegacyShippingAddress}; + +},{}],440:[function(require,module,exports){ +'use strict'; + +module.exports = { + ROOT_SUCCESS_CALLBACK: 'onPaymentMethodReceived', + ROOT_ERROR_CALLBACK: 'onError', + ROOT_READY_CALLBACK: 'onReady' +}; + +},{}],441:[function(require,module,exports){ +(function (global){ +'use strict'; + +var clone = require('lodash.clonedeep'); +var api = require('braintree-api'); +var Bus = require('braintree-bus'); +var Destructor = require('destructor'); +var bind = require('braintree-utilities').bind; +var constants = require('../constants'); +var sanitizePayload = require('../lib/sanitize-payload'); +var lookupCallbackFor = require('../lib/lookup-callback-for'); +var fallbackErrorHandler = require('../lib/fallback-error-handler'); +var nodeType = require('../lib/node-type'); +var isJQueryElement = nodeType.isJQueryElement; +var isHTMLElement = nodeType.isHTMLElement; + +function noop() {} + +function _handleDependencyInitializing() { + this._dependenciesRemaining++; +} + +function _handleDependencyReady() { + this._dependenciesRemaining--; + + if (this._dependenciesRemaining === 0) { + delete this._dependenciesRemaining; + + this.bus.off(Bus.events.ASYNC_DEPENDENCY_INITIALIZING, this._handleDependencyInitializing); + this.bus.off(Bus.events.ASYNC_DEPENDENCY_READY, this._handleDependencyReady); + + this._onIntegrationReady(); + } +} + +function BaseIntegration(configuration) { + this.configuration = configuration; + + this.isReady = false; + + this.destructor = new Destructor(); + + this.bus = new Bus({ + channel: this.configuration.channel, + merchantUrl: global.location.href + }); + + this._createApiClient(); + this._configureCallbacks(); + this._configureAnalytics(); + this._attachEvents(); + this._emitInitializing(); +} + +BaseIntegration.prototype._emitInitializing = function () { + this.bus.emit(Bus.events.ASYNC_DEPENDENCY_INITIALIZING); +}; + +BaseIntegration.prototype._createApiClient = function () { + var apiClientOptions = { + clientToken: this.configuration.gatewayConfiguration, + integration: this.configuration.integrationType, + analyticsConfiguration: this.configuration.analyticsConfiguration + }; + + if (this.configuration.merchantConfiguration.enableCORS) { + apiClientOptions.enableCORS = true; + } + + this.apiClient = new api.Client(apiClientOptions); +}; + +BaseIntegration.prototype._configureCallbacks = function () { + var getCallback = lookupCallbackFor(this.configuration.merchantConfiguration); + + function successHandler(fn) { + return function (payload) { + fn(sanitizePayload(payload)); + }; + } + + this.onSuccess = successHandler(getCallback(constants.ROOT_SUCCESS_CALLBACK)); + this.onError = getCallback(constants.ROOT_ERROR_CALLBACK, fallbackErrorHandler); + this.onReady = getCallback(constants.ROOT_READY_CALLBACK); +}; + +BaseIntegration.prototype._configureAnalytics = function () { + var prefix = 'web.' + this.configuration.integrationType + '.'; + var apiClient = this.apiClient; + + this.bus.on(Bus.events.SEND_ANALYTICS_EVENTS, function (events, callback) { + var i; + + if (!(events instanceof Array)) { + events = [events]; + } + + for (i = 0; i < events.length; i++) { + events[i] = prefix + events[i]; + } + + apiClient.sendAnalyticsEvents(events, callback); + }); +}; + +BaseIntegration.prototype._attachEvents = function () { + var replyConfiguration; + var configuration = this.configuration; + + this.bus.on(Bus.events.ERROR, this.onError); + this.bus.on(Bus.events.PAYMENT_METHOD_RECEIVED, this.onSuccess); + + this.bus.on(Bus.events.WARNING, function (warning) { + try { console.warn(warning); } catch (e) { /* ignored */ } // eslint-disable-line no-console + }); + + replyConfiguration = { + enableCORS: configuration.merchantConfiguration.enableCORS, + configuration: configuration.gatewayConfiguration, + integration: configuration.integrationType, + analyticsConfiguration: configuration.analyticsConfiguration, + merchantConfiguration: clone(configuration.merchantConfiguration, function (value) { + if (isJQueryElement(value) || isHTMLElement(value)) { return {}; } + }) + }; + + this.bus.on(Bus.events.CONFIGURATION_REQUEST, function (reply) { + reply(replyConfiguration); + }); + + this._dependenciesRemaining = 0; + this._handleDependencyInitializing = bind(_handleDependencyInitializing, this); + this._handleDependencyReady = bind(_handleDependencyReady, this); + this.bus.on(Bus.events.ASYNC_DEPENDENCY_INITIALIZING, this._handleDependencyInitializing); + this.bus.on(Bus.events.ASYNC_DEPENDENCY_READY, this._handleDependencyReady); +}; + +BaseIntegration.prototype._onIntegrationReady = function () { + var instance = { + teardown: bind(function (done) { + var key; + var message = 'Cannot call teardown while in progress'; + + done = done || noop; + + function teardownReply() { + throw new Error(message); + } + + for (key in instance) { + if (instance.hasOwnProperty(key)) { + instance[key] = teardownReply; + } + } + + this.destructor.teardown(bind(function () { // eslint-disable-line no-invalid-this + message = 'Cannot teardown integration more than once'; + + this.bus.teardown(); // eslint-disable-line no-invalid-this + done(); + }, this)); // eslint-disable-line no-invalid-this + }, this) // eslint-disable-line no-invalid-this + }; + + this.isReady = true; + this.onReady(instance); +}; + +module.exports = BaseIntegration; + +}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) +},{"../constants":440,"../lib/fallback-error-handler":447,"../lib/lookup-callback-for":449,"../lib/node-type":450,"../lib/sanitize-payload":451,"braintree-api":21,"braintree-bus":52,"braintree-utilities":372,"destructor":373,"lodash.clonedeep":418}],442:[function(require,module,exports){ +'use strict'; + +var clone = require('lodash.clonedeep'); +var create = require('lodash.create'); +var api = require('braintree-api'); +var bind = require('braintree-utilities').bind; +var coinbase = require('braintree-coinbase'); +var Bus = require('braintree-bus'); +var BaseIntegration = require('./base-integration'); + +function CoinbaseIntegration() { + var coinbaseConfiguration, coinbaseIntegration; + + BaseIntegration.apply(this, arguments); + + coinbaseConfiguration = clone(this.configuration.merchantConfiguration); + + this._attachBusEvents(); + + coinbaseConfiguration.channel = this.configuration.channel; + coinbaseConfiguration.configuration = clone(this.configuration.gatewayConfiguration); + coinbaseConfiguration.coinbase = clone(coinbaseConfiguration.coinbase || {}); + coinbaseConfiguration.apiClient = new api.Client({ + enableCORS: this.configuration.merchantConfiguration.enableCORS || false, + clientToken: this.configuration.gatewayConfiguration, + integration: 'coinbase' + }); + + coinbaseIntegration = coinbase.create(coinbaseConfiguration); + this.destructor.registerFunctionForTeardown(function (done) { + coinbaseIntegration.teardown(done); + }); + + this.bus.emit(Bus.events.ASYNC_DEPENDENCY_READY); +} + +CoinbaseIntegration.prototype = create(BaseIntegration.prototype, { + constructor: CoinbaseIntegration +}); + +CoinbaseIntegration.prototype._attachBusEvents = function () { + this.bus.on(Bus.events.PAYMENT_METHOD_GENERATED, bind(this._onPaymentMethodGenerated, this)); +}; + +CoinbaseIntegration.prototype._onPaymentMethodGenerated = function (payload) { + this.bus.emit(Bus.events.PAYMENT_METHOD_RECEIVED, payload); +}; + +module.exports = CoinbaseIntegration; + +},{"./base-integration":441,"braintree-api":21,"braintree-bus":52,"braintree-coinbase":56,"braintree-utilities":372,"lodash.clonedeep":418,"lodash.create":430}],443:[function(require,module,exports){ +'use strict'; + +var clone = require('lodash.clonedeep'); +var create = require('lodash.create'); +var form = require('braintree-form'); +var paypal = require('braintree-paypal'); +var coinbase = require('braintree-coinbase'); +var utils = require('braintree-utilities'); +var hostedFields = require('hosted-fields'); +var FormNapper = require('form-napper'); +var constants = require('../constants'); +var Bus = require('braintree-bus'); +var convertToLegacyShippingAddress = require('../compatibility').convertToLegacyShippingAddress; +var BaseIntegration = require('./base-integration'); +var nodeType = require('../lib/node-type'); +var isJQueryElement = nodeType.isJQueryElement; +var isHTMLElement = nodeType.isHTMLElement; +var NonceManager = require('../lib/hosted-fields-nonce-manager'); + +function CustomIntegration() { + BaseIntegration.apply(this, arguments); + + if (this.configuration.merchantConfiguration.hostedFields != null) { + this._setupHostedFields(); + } else { + this._setupForm(); + } + + this._setupPayPal(); + this._setupCoinbase(); + + this.bus.emit(Bus.events.ASYNC_DEPENDENCY_READY); +} + +CustomIntegration.prototype = create(BaseIntegration.prototype, { + constructor: CustomIntegration +}); + +CustomIntegration.prototype._setupHostedFields = function () { + var submitRequestHandler; + var merchantConfiguration = this.configuration.merchantConfiguration; + var rootSuccessCallback = merchantConfiguration[constants.ROOT_SUCCESS_CALLBACK]; + var formNapper = new FormNapper(merchantConfiguration.id); + var hostedFieldsIntegration = hostedFields.create(this.configuration); + var nonceManager = new NonceManager({ + formNapper: formNapper, + rootCallback: rootSuccessCallback, + channel: this.configuration.channel + }); + + if (formNapper.htmlForm == null) { + this.bus.emit(Bus.events.ERROR, { + type: 'CONFIGURATION', + message: 'options.id does not reference a valid DOM element' + }); + return; + } + + submitRequestHandler = utils.bind(nonceManager.handleSubmitRequest, nonceManager); + + formNapper.hijack(submitRequestHandler); + this.bus.on(Bus.events.USER_FORM_SUBMIT_REQUEST, submitRequestHandler); + + this.destructor.registerFunctionForTeardown(utils.bind(function (done) { + nonceManager.teardown(); + formNapper.detach(); + hostedFieldsIntegration.teardown(done); + }, this)); +}; + +CustomIntegration.prototype._setupForm = function () { + var merchantConfiguration = this.configuration.merchantConfiguration; + var formShouldAutoSubmit, successCallback, formIntegration; + + if (merchantConfiguration.id) { + formIntegration = form.setup(this.apiClient, this.configuration); + + formShouldAutoSubmit = !utils.isFunction(merchantConfiguration[constants.ROOT_SUCCESS_CALLBACK]); + if (!formShouldAutoSubmit) { + successCallback = this.onSuccess; + formIntegration.onNonceReceived = utils.bind(function (err, payload) { + if (err) { + this.bus.emit(Bus.events.ERROR, err); // eslint-disable-line no-invalid-this + } else { + successCallback(payload); + } + }, this); + } + + this.destructor.registerFunctionForTeardown(function () { + formIntegration.teardown(); + }); + } else { + this.bus.on(Bus.events.PAYMENT_METHOD_GENERATED, utils.bind(function (payload) { + this.bus.emit(Bus.events.PAYMENT_METHOD_RECEIVED, payload); // eslint-disable-line no-invalid-this + }, this)); + } +}; + +CustomIntegration.prototype._setupPayPal = function () { + var paypalCallbackLookup, legacyPaypalSuccessCallback, legacyPaypalCancelledCallback, dummyInput, paypalIntegration, paypalConfiguration; + var merchantConfiguration = this.configuration.merchantConfiguration; + + if (!merchantConfiguration.paypal) { return; } + + paypalConfiguration = clone(merchantConfiguration.paypal, function (value) { + if (isJQueryElement(value)) { + return value[0]; + } else if (isHTMLElement(value)) { + return value; + } + }); + + paypalCallbackLookup = getIntegrationCallbackLookup(merchantConfiguration, 'paypal'); + legacyPaypalSuccessCallback = paypalCallbackLookup('onSuccess'); + legacyPaypalCancelledCallback = paypalCallbackLookup('onCancelled'); + + if (!paypalConfiguration.paymentMethodNonceInputField) { + dummyInput = document.createElement('input'); + dummyInput.id = 'braintree-custom-integration-dummy-input'; + paypalConfiguration.paymentMethodNonceInputField = dummyInput; + } + + paypalConfiguration.onSuccess = function (payload) { + legacyPaypalSuccessCallback( + payload.nonce, + payload.details.email, + convertToLegacyShippingAddress(payload.details.shippingAddress) + ); + }; + + paypalConfiguration.onCancelled = utils.bind(function () { + this.bus.emit(Bus.events.PAYMENT_METHOD_CANCELLED); // eslint-disable-line no-invalid-this + legacyPaypalCancelledCallback(); + }, this); + + if (merchantConfiguration.enableCORS) { + paypalConfiguration.enableCORS = true; + } + + paypalIntegration = paypal.create(this.configuration.gatewayConfiguration, paypalConfiguration, this.configuration.channel); + + if (paypalIntegration != null) { + this.destructor.registerFunctionForTeardown(function () { + paypalIntegration.teardown(); + }); + } +}; + +CustomIntegration.prototype._setupCoinbase = function () { + var coinbaseConfiguration, coinbaseIntegration; + + if (!this.configuration.merchantConfiguration.coinbase) { return; } + + if (navigator.userAgent.match(/MSIE 8\.0/)) { return; } + + coinbaseConfiguration = clone(this.configuration.merchantConfiguration); + coinbaseConfiguration.channel = this.configuration.channel; + coinbaseConfiguration.configuration = this.configuration.gatewayConfiguration; + coinbaseConfiguration.apiClient = this.apiClient; + delete coinbaseConfiguration.paypal; + + coinbaseIntegration = coinbase.create(coinbaseConfiguration); + + this.destructor.registerFunctionForTeardown(function (done) { + coinbaseIntegration.teardown(done); + }); +}; + +function getIntegrationCallbackLookup(options, integration) { + return function (funcName) { + if (integration in options && utils.isFunction(options[integration][funcName])) { + return options[integration][funcName]; + } + return function noop() {}; + }; +} + +module.exports = CustomIntegration; + +},{"../compatibility":439,"../constants":440,"../lib/hosted-fields-nonce-manager":448,"../lib/node-type":450,"./base-integration":441,"braintree-bus":52,"braintree-coinbase":56,"braintree-form":245,"braintree-paypal":344,"braintree-utilities":372,"form-napper":376,"hosted-fields":377,"lodash.clonedeep":418,"lodash.create":430}],444:[function(require,module,exports){ +'use strict'; + +var create = require('lodash.create'); +var dropin = require('braintree-dropin'); +var utils = require('braintree-utilities'); +var Bus = require('braintree-bus'); +var constants = require('../constants'); +var sanitizePayload = require('../lib/sanitize-payload'); +var BaseIntegration = require('./base-integration'); + +function _getLegacyCallback(options) { + if (utils.isFunction(options.paymentMethodNonceReceived)) { + return options.paymentMethodNonceReceived; + } + + return null; +} + +function _hasRootCallback(options) { + return utils.isFunction(options[constants.ROOT_SUCCESS_CALLBACK]); +} + +function DropinIntegration() { + var merchantConfiguration, legacyCallback, hasRootCallback, dropinIntegration; + + BaseIntegration.apply(this, arguments); + + merchantConfiguration = this.configuration.merchantConfiguration; + legacyCallback = _getLegacyCallback(merchantConfiguration); + hasRootCallback = _hasRootCallback(merchantConfiguration); + + if (legacyCallback || hasRootCallback) { + merchantConfiguration.paymentMethodNonceReceived = utils.bind(function (payload) { + if (legacyCallback) { + legacyCallback(payload.originalEvent, payload.nonce); + } + + this.bus.emit(Bus.events.PAYMENT_METHOD_RECEIVED, sanitizePayload(payload)); // eslint-disable-line no-invalid-this + }, this); + } + + dropinIntegration = dropin.create(this.configuration); + this.destructor.registerFunctionForTeardown(function (done) { + dropinIntegration.teardown(done); + }); + + this.bus.emit(Bus.events.ASYNC_DEPENDENCY_READY); +} + +DropinIntegration.prototype = create(BaseIntegration.prototype, { + constructor: DropinIntegration +}); + +module.exports = DropinIntegration; + +},{"../constants":440,"../lib/sanitize-payload":451,"./base-integration":441,"braintree-bus":52,"braintree-dropin":236,"braintree-utilities":372,"lodash.create":430}],445:[function(require,module,exports){ +'use strict'; + +module.exports = { + custom: require('./custom'), + dropin: require('./dropin'), + paypal: require('./paypal'), + coinbase: require('./coinbase') +}; + +},{"./coinbase":442,"./custom":443,"./dropin":444,"./paypal":446}],446:[function(require,module,exports){ +'use strict'; + +var create = require('lodash.create'); +var paypal = require('braintree-paypal'); +var utils = require('braintree-utilities'); +var constants = require('../constants'); +var Bus = require('braintree-bus'); +var convertToLegacyShippingAddress = require('../compatibility').convertToLegacyShippingAddress; +var BaseIntegration = require('./base-integration'); + +function _getLegacyCallback(options) { + if ('onSuccess' in options && utils.isFunction(options.onSuccess)) { + return options.onSuccess; + } else if ('paypal' in options && utils.isFunction(options.paypal.onSuccess)) { + return options.paypal.onSuccess; + } + + return null; +} + +function _hasRootCallback(options) { + return utils.isFunction(options[constants.ROOT_SUCCESS_CALLBACK]); +} + +function PayPalIntegration() { + var merchantConfiguration, legacyCallback, hasRootCallback, paypalIntegration; + + BaseIntegration.apply(this, arguments); + + merchantConfiguration = this.configuration.merchantConfiguration; + legacyCallback = _getLegacyCallback(merchantConfiguration); + hasRootCallback = _hasRootCallback(merchantConfiguration); + + if (legacyCallback || hasRootCallback) { + merchantConfiguration.onSuccess = utils.bind(function (payload) { + if (legacyCallback) { + legacyCallback( + payload.nonce, + payload.details.email, + convertToLegacyShippingAddress(payload.details.shippingAddress) + ); + } + + this.bus.emit(Bus.events.PAYMENT_METHOD_RECEIVED, payload); // eslint-disable-line no-invalid-this + }, this); + } + + paypalIntegration = paypal.create(this.configuration.gatewayConfiguration, merchantConfiguration, this.configuration.channel); + + this.destructor.registerFunctionForTeardown(function () { + paypalIntegration.teardown(); + }); + + this.bus.emit(Bus.events.ASYNC_DEPENDENCY_READY); +} + +PayPalIntegration.prototype = create(BaseIntegration.prototype, { + constructor: PayPalIntegration +}); + +module.exports = PayPalIntegration; + +},{"../compatibility":439,"../constants":440,"./base-integration":441,"braintree-bus":52,"braintree-paypal":344,"braintree-utilities":372,"lodash.create":430}],447:[function(require,module,exports){ +'use strict'; + +module.exports = function fallbackError(error) { + if (error.type === 'CONFIGURATION' || error.type === 'IMMEDIATE') { + throw new Error(error.message); + } else { + try { + console.error(JSON.stringify(error)); // eslint-disable-line no-console + } catch (e) { /* ignored */ } + } +}; + +},{}],448:[function(require,module,exports){ +'use strict'; + +var Bus = require('braintree-bus'); +var hostedFields = require('hosted-fields'); + +var ANALYTICS_STRING = 'web.custom.hosted-fields.via.'; +var INPUT_NAME = 'payment_method_nonce'; + +function NonceManager(configuration) { + this.paymentMethod = null; + this.nonceInputElement = null; + + this.bus = new Bus({channel: configuration.channel}); + this.formNapper = configuration.formNapper; + this.rootCallback = configuration.rootCallback; + + this._attachEvents(); +} + +NonceManager.prototype._clearNonce = function () { + this.paymentMethod = null; + this.nonceInputElement = this.formNapper.inject(INPUT_NAME, ''); +}; + +NonceManager.prototype._attachEvents = function () { + var self = this; + + this.bus.on(Bus.events.PAYMENT_METHOD_CANCELLED, function () { + self._clearNonce(); + }); + + this.bus.on(Bus.events.PAYMENT_METHOD_GENERATED, function (payload) { + self.paymentMethod = payload; + self.nonceInputElement = self.formNapper.inject(INPUT_NAME, self.paymentMethod.nonce); + }); +}; + +NonceManager.prototype.handleSubmitRequest = function () { + var self = this; + + this.bus.emit(hostedFields.events.TOKENIZATION_REQUEST, function (args) { + var err = args[0]; + var payload = args[1]; + + if (err) { + self.bus.emit(Bus.events.ERROR, err); + return; + } + + self.paymentMethod = payload || self.paymentMethod; + + if (self.paymentMethod == null) { + self.bus.emit(hostedFields.events.VALIDATE_STRICT); + self.bus.emit(Bus.events.ERROR, { + type: 'VALIDATION', + message: 'User did not enter a payment method' + }); + return; + } + + if (self.rootCallback) { + self.bus.emit(Bus.events.SEND_ANALYTICS_EVENTS, ANALYTICS_STRING + 'callback.success', function () { + self.rootCallback(self.paymentMethod); + }); + } else { + self.bus.emit(Bus.events.SEND_ANALYTICS_EVENTS, ANALYTICS_STRING + 'formsubmit.success', function () { + self.nonceInputElement = self.formNapper.inject(INPUT_NAME, self.paymentMethod.nonce); + self.formNapper.submit(); + }); + } + }); +}; + +NonceManager.prototype.teardown = function () { + this._clearNonce(); +}; + +module.exports = NonceManager; + +},{"braintree-bus":52,"hosted-fields":377}],449:[function(require,module,exports){ +'use strict'; + +var isFunction = require('braintree-utilities').isFunction; + +function noop() {} + +module.exports = function lookupCallbackFor(model) { + return function (callbackName, fallbackCallback) { + if (isFunction(model[callbackName])) { + return model[callbackName]; + } else if (isFunction(fallbackCallback)) { + return fallbackCallback; + } + + return noop; + }; +}; + +},{"braintree-utilities":372}],450:[function(require,module,exports){ +'use strict'; + +function isJQueryElement(element) { + return typeof element === 'object' && 'jquery' in element && element.length !== 0; +} + +function isHTMLElement(element) { + return element && element.nodeType === 1; +} + +module.exports = { + isJQueryElement: isJQueryElement, + isHTMLElement: isHTMLElement +}; + +},{}],451:[function(require,module,exports){ +'use strict'; + +module.exports = function sanitizePayload(payload) { + return { + nonce: payload.nonce, + details: payload.details, + type: payload.type + }; +}; + +},{}]},{},[1])(1) +});