{"version":3,"sources":["webpack:///webpack/bootstrap","webpack:///./link_paypal/cartridges/int_paypal/cartridge/client/default/js/api.js","webpack:///./link_paypal/cartridges/int_paypal/cartridge/client/default/js/loader.js","webpack:///./link_paypal/cartridges/int_paypal/cartridge/client/default/js/helper.js","webpack:///./link_paypal/cartridges/int_paypal/cartridge/client/default/js/cart/initCartButton.js","webpack:///./link_paypal/cartridges/int_paypal/cartridge/client/default/js/cart/registered/initBillingAgreementButton.js","webpack:///./link_paypal/cartridges/int_paypal/cartridge/client/default/js/cart/cart.js"],"names":["installedModules","__webpack_require__","moduleId","exports","module","i","l","modules","call","m","c","d","name","getter","o","Object","defineProperty","enumerable","get","r","Symbol","toStringTag","value","t","mode","__esModule","ns","create","key","bind","n","object","property","prototype","hasOwnProperty","p","s","loader","require","loaderInstance","document","querySelector","showCartErrorHtml","message","$","addClass","append","concat","window","scrollTo","showCheckoutErrorHtml","textContent","style","display","updateOrderData","show","ajax","url","paypalUrls","type","success","hide","location","href","placeOrderStage","error","err","JSON","parse","responseText","errorMsg","transactionExpired","reload","getPurchaseUnits","getPurchaseUnit","then","_ref","purchase_units","getBillingAgreementToken","isCartFlow","arguments","length","undefined","createBillingAgreementToken","data","createBillingAgreementCall","billingToken","createBillingAgreement","contentType","stringify","createCartBillingFormData","fieldsData","$paypalButton","cartBillingFormData","FormData","cartBillingFields","getAttribute","entries","forEach","entry","_entry","_slicedToArray","field","_typeof","returnFromCart","processData","finishLpmOrder","details","lpmName","paypalMethodId","containerElement","Constructor","this","containerEl","defaultStyle","color","shape","layout","label","tagline","getPaypalButtonStyle","button","config","createOrder","_","actions","getCartPurchaseUnit","parsedPurchaseUnit","cartError","cartPage","amount","application_context","shipping_preference","order","onApprove","_ref2","orderID","paypalOrderID","onCancel","onError","initPaypalButton","paypal","Buttons","render","token","fail","id","payer","billingAgreementID","billingAgreementPayerEmail","payer_info","email","dataType","initPaypalBAButton","head","script","$paypalImage","$cartButton","$isBAEnabled","isUpdateRequired","addEventListener","getElementsByTagName","item","createElement","onload","src","cartSdkUrl","setAttribute","partnerAttributionId","appendChild"],"mappings":"aACE,IAAIA,EAAmB,GAGvB,SAASC,EAAoBC,GAG5B,GAAGF,EAAiBE,GACnB,OAAOF,EAAiBE,GAAUC,QAGnC,IAAIC,EAASJ,EAAiBE,GAAY,CACzCG,EAAGH,EACHI,GAAG,EACHH,QAAS,IAUV,OANAI,EAAQL,GAAUM,KAAKJ,EAAOD,QAASC,EAAQA,EAAOD,QAASF,GAG/DG,EAAOE,GAAI,EAGJF,EAAOD,QAKfF,EAAoBQ,EAAIF,EAGxBN,EAAoBS,EAAIV,EAGxBC,EAAoBU,EAAI,SAASR,EAASS,EAAMC,GAC3CZ,EAAoBa,EAAEX,EAASS,IAClCG,OAAOC,eAAeb,EAASS,EAAM,CAAEK,YAAY,EAAMC,IAAKL,KAKhEZ,EAAoBkB,EAAI,SAAShB,GACX,oBAAXiB,QAA0BA,OAAOC,aAC1CN,OAAOC,eAAeb,EAASiB,OAAOC,YAAa,CAAEC,MAAO,WAE7DP,OAAOC,eAAeb,EAAS,aAAc,CAAEmB,OAAO,KAQvDrB,EAAoBsB,EAAI,SAASD,EAAOE,GAEvC,GADU,EAAPA,IAAUF,EAAQrB,EAAoBqB,IAC/B,EAAPE,EAAU,OAAOF,EACpB,GAAW,EAAPE,GAA8B,iBAAVF,GAAsBA,GAASA,EAAMG,WAAY,OAAOH,EAChF,IAAII,EAAKX,OAAOY,OAAO,MAGvB,GAFA1B,EAAoBkB,EAAEO,GACtBX,OAAOC,eAAeU,EAAI,UAAW,CAAET,YAAY,EAAMK,MAAOA,IACtD,EAAPE,GAA4B,iBAATF,EAAmB,IAAI,IAAIM,KAAON,EAAOrB,EAAoBU,EAAEe,EAAIE,EAAK,SAASA,GAAO,OAAON,EAAMM,IAAQC,KAAK,KAAMD,IAC9I,OAAOF,GAIRzB,EAAoB6B,EAAI,SAAS1B,GAChC,IAAIS,EAAST,GAAUA,EAAOqB,WAC7B,WAAwB,OAA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jF,OAAOc,SAASC,KAAOf,OAAOU,WAAWuE,UAE7CvF,YAAkB,uEAoBP+G,ICrFPC,EACAC,EDoFOF,EAdf,WACIpH,EAAOkB,OACPP,OAAO6F,OAAOC,QAAQ,CAClBvD,yBACA+C,YACAI,WACAC,UACAvF,MAAOoE,YAAqBhF,SAASC,cAAc,qCACpDsG,OAAO,uBACLpE,MAAK,WACFtC,EAAOwB,WC3Ff+F,EAAepH,SAASC,cAAc,iBACtCoH,EAAcrH,SAASC,cAAc,kCACrCqH,EAAeD,GAAe1F,KAAKC,MAAMyF,EAAY7D,aAAa,2BAChEtC,EAAalB,SAASC,cAAc,sBAAsBuD,aAAa,oBAoB7E,GAnBAhD,OAAOU,WAAaS,KAAKC,MAAMV,GAmB3BkG,EAAc,CACd,IAAIG,EAAmB5F,KAAKC,MAAMwF,EAAa5D,aAAa,4BAC5D4D,EAAaI,iBAAiB,QAASD,EAAmBzG,IAAkBkD,UAG5ExD,OAAO6F,OAAUiB,EACbL,IACAb,KApBAc,EAAOlH,SAASyH,qBAAqB,QAAQC,KAAK,IAClDP,EAASnH,SAAS2H,cAAc,WAC7BxG,KAAO,kBACdgG,EAAOS,OAAS,WACZN,EACIL,IACAb,KAERe,EAAOU,IAAMrH,OAAOU,WAAW4G,WAC/BX,EAAOY,aAAa,8BAA+BvH,OAAOU,WAAW8G,sBACrEd,EAAKe,YAAYd","file":"int_paypal_cart.min.js","sourcesContent":[" \t// The module cache\n \tvar installedModules = {};\n\n \t// The require function\n \tfunction __webpack_require__(moduleId) {\n\n \t\t// Check if module is in cache\n \t\tif(installedModules[moduleId]) {\n \t\t\treturn installedModules[moduleId].exports;\n \t\t}\n \t\t// Create a new module (and put it into the cache)\n \t\tvar module = installedModules[moduleId] = {\n \t\t\ti: moduleId,\n \t\t\tl: false,\n \t\t\texports: {}\n \t\t};\n\n \t\t// Execute the module function\n \t\tmodules[moduleId].call(module.exports, module, module.exports, __webpack_require__);\n\n \t\t// Flag the module as loaded\n \t\tmodule.l = true;\n\n \t\t// Return the exports of the module\n \t\treturn module.exports;\n \t}\n\n\n \t// expose the modules object (__webpack_modules__)\n \t__webpack_require__.m = modules;\n\n \t// expose the module cache\n \t__webpack_require__.c = installedModules;\n\n \t// define getter function for harmony exports\n \t__webpack_require__.d = function(exports, name, getter) {\n \t\tif(!__webpack_require__.o(exports, name)) {\n \t\t\tObject.defineProperty(exports, name, { enumerable: true, get: getter });\n \t\t}\n \t};\n\n \t// define __esModule on exports\n \t__webpack_require__.r = function(exports) {\n \t\tif(typeof Symbol !== 'undefined' && Symbol.toStringTag) {\n \t\t\tObject.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });\n \t\t}\n \t\tObject.defineProperty(exports, '__esModule', { value: true });\n \t};\n\n \t// create a fake namespace object\n \t// mode & 1: value is a module id, require it\n \t// mode & 2: merge all properties of value into the ns\n \t// mode & 4: return value when already ns object\n \t// mode & 8|1: behave like require\n \t__webpack_require__.t = function(value, mode) {\n \t\tif(mode & 1) value = __webpack_require__(value);\n \t\tif(mode & 8) return value;\n \t\tif((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;\n \t\tvar ns = Object.create(null);\n \t\t__webpack_require__.r(ns);\n \t\tObject.defineProperty(ns, 'default', { enumerable: true, value: value });\n \t\tif(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));\n \t\treturn ns;\n \t};\n\n \t// getDefaultExport function for compatibility with non-harmony modules\n \t__webpack_require__.n = function(module) {\n \t\tvar getter = module && module.__esModule ?\n \t\t\tfunction getDefault() { return module['default']; } :\n \t\t\tfunction getModuleExports() { return module; };\n \t\t__webpack_require__.d(getter, 'a', getter);\n \t\treturn getter;\n \t};\n\n \t// Object.prototype.hasOwnProperty.call\n \t__webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };\n\n \t// __webpack_public_path__\n \t__webpack_require__.p = \"\";\n\n\n \t// Load entry module and return exports\n \treturn __webpack_require__(__webpack_require__.s = 5);\n","var loaderInstance = require('./loader');\r\nvar $loaderContainer = document.querySelector('.paypalLoader');\r\nvar loader = loaderInstance($loaderContainer);\r\n/**\r\n * Appends error message on cart page\r\n *\r\n * @param {string} message error message\r\n */\r\nfunction showCartErrorHtml(message) {\r\n $('.checkout-btn').addClass('disabled');\r\n $('.cart-error').append(\r\n `
\r\n \r\n ${message}\r\n
`\r\n );\r\n window.scrollTo(0, 0);\r\n}\r\n\r\n/**\r\n * Appends error message on billing checkout page\r\n *\r\n * @param {string} message error message\r\n */\r\nfunction showCheckoutErrorHtml(message) {\r\n document.querySelector('.error-message-text').textContent = '';\r\n document.querySelector('.error-message').style.display = 'block';\r\n document.querySelector('.error-message-text').append(message);\r\n window.scrollTo(0, 0);\r\n}\r\n\r\n/**\r\n * Updates information about an order\r\n *\r\n * @returns {Object} Call handling result\r\n */\r\nfunction updateOrderData() {\r\n loader.show();\r\n return $.ajax({\r\n url: window.paypalUrls.updateOrderData + '?isCartFlow=true',\r\n type: 'PATCH',\r\n success: () => {\r\n loader.hide();\r\n window.location.href = window.paypalUrls.placeOrderStage;\r\n },\r\n error: (err) => {\r\n loader.hide();\r\n var error = JSON.parse(err.responseText);\r\n showCartErrorHtml(error.errorMsg);\r\n if (error.transactionExpired) {\r\n location.reload();\r\n }\r\n }\r\n });\r\n}\r\n\r\n/**\r\n * Gets purchase units\r\n *\r\n * @returns {Object} with purchase units data\r\n */\r\nfunction getPurchaseUnits() {\r\n return $.get(window.paypalUrls.getPurchaseUnit)\r\n .then(({ purchase_units }) => purchase_units);\r\n}\r\n\r\n/**\r\n * Gets Billing Agreement Token\r\n *\r\n * @param {boolean} isCartFlow - billing agreement flow from cart\r\n * @returns {string} billingToken - returns a JSON response that includes token, an approval URL\r\n */\r\nfunction getBillingAgreementToken(isCartFlow = false) {\r\n return $.get(window.paypalUrls.createBillingAgreementToken + `?isCartFlow=${isCartFlow}`)\r\n .then((data) => data);\r\n}\r\n\r\n/**\r\n * Gets Billing Agreement\r\n * After buyer approval, you use a billing agreement token to create the agreement.\r\n *\r\n * @param {string} billingToken - billing agreement token\r\n * @returns {Object} JSON response body that includes the billing agreement ID,\r\n * the state of the agreement, which is ACTIVE, and information about the payer\r\n */\r\nfunction createBillingAgreementCall(billingToken) {\r\n return $.ajax({\r\n url: window.paypalUrls.createBillingAgreement,\r\n type: 'POST',\r\n contentType: 'application/json',\r\n data: JSON.stringify({ billingToken })\r\n });\r\n}\r\n\r\n/**\r\n * Gets Order Details\r\n *\r\n * @param {string} orderId - billing agreement token\r\n * @returns {Object} JSON response body that includes payer email\r\n */\r\nfunction getOrderDetailsCall(orderId) {\r\n return $.get(window.paypalUrls.getOrderDetails + `?orderId=${orderId}`)\r\n .then((data) => data);\r\n}\r\n\r\n/**\r\n * Create billing formData from fields data\r\n *\r\n * @param {Object} fieldsData - fields data values\r\n * @param {Elemtn} $paypalButton - paypal button selector\r\n * @returns {Object} cart billing form data\r\n */\r\nfunction createCartBillingFormData(fieldsData, $paypalButton) {\r\n var cartBillingFormData = new FormData();\r\n if (!$paypalButton) {\r\n $paypalButton = document.querySelector('#paypal_pdp_image') || document.querySelector('#paypal_image');\r\n }\r\n var cartBillingFields = $paypalButton && JSON.parse($paypalButton.getAttribute('data-paypal-billing-form-fields'));\r\n\r\n Object.entries(cartBillingFields).forEach(entry => {\r\n const [key, field] = entry;\r\n if (typeof field === 'object') {\r\n cartBillingFormData.append(field.name, fieldsData && fieldsData[key] ? fieldsData[key] : field.value);\r\n }\r\n });\r\n\r\n return cartBillingFormData;\r\n}\r\n\r\n/**\r\n * Calls to returnFromCart endpoint, redirects to place order stage or shows error if it exists\r\n *\r\n * @returns {Object} Call handling result\r\n */\r\nfunction returnFromCart() {\r\n loader.show();\r\n let cartBillingFormData = createCartBillingFormData();\r\n\r\n return $.ajax({\r\n url: window.paypalUrls.returnFromCart,\r\n type: 'POST',\r\n contentType: false,\r\n data: cartBillingFormData,\r\n processData: false,\r\n success: () => {\r\n loader.hide();\r\n window.location.href = window.paypalUrls.placeOrderStage;\r\n },\r\n error: function (err) {\r\n loader.hide();\r\n showCartErrorHtml(err.responseText);\r\n }\r\n });\r\n}\r\n\r\n/**\r\n * Call finishLpmOrder endpoint\r\n * @param {Object} details billing address details\r\n * @returns {Promise} ajax call\r\n */\r\nfunction finishLpmOrder(details) {\r\n const lpmName = document.querySelector('#usedPaymentMethod').value;\r\n const paypalMethodId = document.querySelector('#paypalMethodId').value;\r\n return $.ajax({\r\n url: window.paypalUrls.finishLpmOrder,\r\n type: 'POST',\r\n contentType: 'application/json',\r\n data: JSON.stringify({\r\n details,\r\n lpmName,\r\n paypalMethodId\r\n })\r\n });\r\n}\r\n\r\nexport {\r\n updateOrderData,\r\n getPurchaseUnits,\r\n getBillingAgreementToken,\r\n createBillingAgreementCall,\r\n getOrderDetailsCall,\r\n returnFromCart,\r\n showCartErrorHtml,\r\n showCheckoutErrorHtml,\r\n finishLpmOrder,\r\n createCartBillingFormData\r\n};\r\n","/* eslint-disable require-jsdoc */\r\nmodule.exports = function (containerElement) {\r\n function Constructor() {\r\n this.containerEl = containerElement;\r\n }\r\n Constructor.prototype.show = function () {\r\n this.containerEl.style.display = 'block';\r\n };\r\n Constructor.prototype.hide = function () {\r\n this.containerEl.style.display = 'none';\r\n };\r\n return new Constructor();\r\n};\r\n","const defaultStyle = {\r\n color: 'gold',\r\n shape: 'rect',\r\n layout: 'vertical',\r\n label: 'paypal',\r\n tagline: false\r\n};\r\n\r\n/**\r\n * Gets paypal button styles\r\n * @param {Element} button - button element\r\n * @returns {Object} with button styles or if error appears with default styles\r\n */\r\nfunction getPaypalButtonStyle(button) {\r\n try {\r\n const config = button.getAttribute('data-paypal-button-config');\r\n if (config) {\r\n const buttonConfigs = JSON.parse(config);\r\n return buttonConfigs.style;\r\n }\r\n } catch (error) {\r\n return {\r\n style: defaultStyle\r\n };\r\n }\r\n}\r\n\r\nexport {\r\n getPaypalButtonStyle\r\n};\r\n","import {\r\n showCartErrorHtml,\r\n createCartBillingFormData\r\n} from '../api';\r\nimport {\r\n getPaypalButtonStyle\r\n} from '../helper';\r\n\r\nvar loaderInstance = require('../loader');\r\nvar $loaderContainer = document.querySelector('.paypalLoader');\r\nvar loader = loaderInstance($loaderContainer);\r\n\r\n/**\r\n * Gets purchase units object, creates order and returns object with data\r\n *\r\n * @param {Object} _ - arg\r\n * @param {Object} actions - paypal actions\r\n * @returns {Object} with purchase units data and application context\r\n */\r\nfunction createOrder(_, actions) {\r\n loader.show();\r\n return $\r\n .get(window.paypalUrls.getCartPurchaseUnit)\r\n .then(function ({ purchase_units }) {\r\n let parsedPurchaseUnit = purchase_units[0];\r\n if (parsedPurchaseUnit.cartError) {\r\n showCartErrorHtml('Your shopping cart is empty.');\r\n window.location.href = window.paypalUrls.cartPage;\r\n return;\r\n }\r\n if (JSON.parse(parsedPurchaseUnit.amount.value) === 0) {\r\n showCartErrorHtml('Order total 0 is not allowed for PayPal');\r\n }\r\n const application_context = {\r\n shipping_preference: parsedPurchaseUnit.shipping_preference\r\n };\r\n loader.hide();\r\n return actions.order.create({\r\n purchase_units,\r\n application_context\r\n });\r\n });\r\n}\r\n\r\n/**\r\n * Makes post call and transfers order ID to returnFromCart endpoint, goes to checkout place order stage\r\n *\r\n * @param {Object} orderID - order id\r\n */\r\nfunction onApprove({ orderID }) {\r\n let cartBillingFormData = createCartBillingFormData({\r\n paypalOrderID: orderID\r\n }, document.querySelector('.js_paypal_button_on_cart_page'));\r\n\r\n $.ajax({\r\n type: 'POST',\r\n url: window.paypalUrls.returnFromCart,\r\n contentType: false,\r\n data: cartBillingFormData,\r\n processData: false,\r\n success: () => {\r\n loader.hide();\r\n window.location.href = window.paypalUrls.placeOrderStage;\r\n },\r\n error: function () {\r\n loader.hide();\r\n if (window.location.href !== window.paypalUrls.cartPage) {\r\n window.location.href = window.paypalUrls.cartPage;\r\n }\r\n if (!document.querySelector('.cartError')) {\r\n showCartErrorHtml('An internal server error has occurred. \\r\\nRetry the request later.');\r\n }\r\n }\r\n });\r\n}\r\n\r\n/**\r\n * Hides loader on paypal widget closing without errors\r\n */\r\nfunction onCancel() {\r\n loader.hide();\r\n}\r\n\r\n/**\r\n * Shows errors if paypal widget was closed with errors\r\n */\r\nfunction onError() {\r\n loader.hide();\r\n if (window.location.href !== window.paypalUrls.cartPage) {\r\n window.location.href = window.paypalUrls.cartPage;\r\n }\r\n if (!document.querySelector('.cartError')) {\r\n showCartErrorHtml('An internal server error has occurred. \\r\\nRetry the request later.');\r\n }\r\n}\r\n\r\n/**\r\n *Inits paypal button on cart page\r\n */\r\nfunction initPaypalButton() {\r\n loader.show();\r\n window.paypal.Buttons({\r\n createOrder,\r\n onApprove,\r\n onCancel,\r\n onError,\r\n style: getPaypalButtonStyle(document.querySelector('.js_paypal_button_on_cart_page'))\r\n }).render('.paypal-cart-button')\r\n .then(() => {\r\n loader.hide();\r\n });\r\n}\r\n\r\nexport default initPaypalButton;\r\n","import {\r\n getBillingAgreementToken,\r\n createBillingAgreementCall,\r\n showCartErrorHtml,\r\n createCartBillingFormData\r\n} from '../../api';\r\nimport {\r\n getPaypalButtonStyle\r\n} from '../../helper';\r\n\r\nconst loaderInstance = require('../../loader');\r\nlet $loaderContainer = document.querySelector('.paypalLoader');\r\nlet loader = loaderInstance($loaderContainer);\r\n\r\n/**\r\n * Create's Billing Agreement\r\n *\r\n * @returns {string} returns JSON response that includes an data token\r\n */\r\nfunction createBillingAgreement() {\r\n loader.show();\r\n let isCartFlow = true;\r\n return getBillingAgreementToken(isCartFlow)\r\n .then((data) => data.token)\r\n .fail(() => {\r\n loader.hide();\r\n });\r\n}\r\n\r\n/**\r\n * Makes post call and transfers billingToken to returnFromCart endpoint, triggers checkout (stage = place order)\r\n *\r\n * @param {string} billingToken - billing agreement token\r\n * @returns {Object} JSON response that includes the billing agreement ID and information about the payer\r\n */\r\nfunction onApprove({ billingToken }) {\r\n return createBillingAgreementCall(billingToken)\r\n .then(({ id, payer }) => {\r\n let cartBillingFormData = createCartBillingFormData({\r\n billingAgreementID: id,\r\n billingAgreementPayerEmail: payer.payer_info.email\r\n }, document.querySelector('.js_paypal_button_on_cart_page'));\r\n\r\n return $.ajax({\r\n type: 'POST',\r\n url: window.paypalUrls.returnFromCart,\r\n data: cartBillingFormData,\r\n contentType: false,\r\n processData: false,\r\n dataType: 'json'\r\n });\r\n })\r\n .then(() => {\r\n loader.hide();\r\n window.location.href = window.paypalUrls.placeOrderStage;\r\n })\r\n .fail((err) => {\r\n loader.hide();\r\n if (window.location.href !== window.paypalUrls.cartPage) {\r\n window.location.href = window.paypalUrls.cartPage;\r\n }\r\n showCartErrorHtml(err.responseText);\r\n });\r\n}\r\n\r\n/**\r\n * Hides loader on paypal widget closing without errors\r\n */\r\nfunction onCancel() {\r\n loader.hide();\r\n}\r\n\r\n/**\r\n * Shows errors if paypal widget was closed with errors\r\n */\r\nfunction onError() {\r\n loader.hide();\r\n if (window.location.href !== window.paypalUrls.cartPage) {\r\n window.location.href = window.paypalUrls.cartPage;\r\n }\r\n showCartErrorHtml('An internal server error has occurred. \\r\\nRetry the request later.');\r\n}\r\n\r\n/**\r\n *Inits paypal Billing Agreement button on billing checkout page\r\n */\r\nfunction initPaypalBAButton() {\r\n loader.show();\r\n window.paypal.Buttons({\r\n createBillingAgreement,\r\n onApprove,\r\n onCancel,\r\n onError,\r\n style: getPaypalButtonStyle(document.querySelector('.js_paypal_button_on_cart_page'))\r\n }).render('.paypal-cart-button')\r\n .then(() => {\r\n loader.hide();\r\n });\r\n}\r\n\r\nexport default initPaypalBAButton;\r\n","/* eslint-disable no-nested-ternary */\r\nimport initPaypalButton from './initCartButton';\r\nimport initPaypalBAButton from './registered/initBillingAgreementButton';\r\nimport { updateOrderData, returnFromCart } from '../api';\r\n\r\nlet $paypalImage = document.querySelector('#paypal_image');\r\nlet $cartButton = document.querySelector('.js_paypal_button_on_cart_page');\r\nlet $isBAEnabled = $cartButton && JSON.parse($cartButton.getAttribute('data-paypal-ba-enabled'));\r\nconst paypalUrls = document.querySelector('.js_paypal-content').getAttribute('data-paypal-urls');\r\nwindow.paypalUrls = JSON.parse(paypalUrls);\r\n\r\n/**\r\n * Injects SDK into page for cart/minicart\r\n*/\r\nfunction injectPaypalSDK() {\r\n var head = document.getElementsByTagName('head').item(0);\r\n var script = document.createElement('script');\r\n script.type = 'text/javascript';\r\n script.onload = function () {\r\n $isBAEnabled ?\r\n initPaypalBAButton() :\r\n initPaypalButton();\r\n };\r\n script.src = window.paypalUrls.cartSdkUrl;\r\n script.setAttribute('data-partner-attribution-id', window.paypalUrls.partnerAttributionId);\r\n head.appendChild(script);\r\n}\r\n\r\nif ($paypalImage) {\r\n let isUpdateRequired = JSON.parse($paypalImage.getAttribute('data-is-update-required'));\r\n $paypalImage.addEventListener('click', isUpdateRequired ? updateOrderData : returnFromCart);\r\n} else {\r\n // We do not inject SDK if SDK is already injected and window.paypal exists to avoid PayPal components destroying\r\n window.paypal ? ($isBAEnabled ?\r\n initPaypalBAButton() :\r\n initPaypalButton()) : injectPaypalSDK();\r\n}\r\n"],"sourceRoot":""}