{"version":3,"file":"Paypal.7e58de13.js","sources":["app/assets/vite/stores/PaymentRequest.ts","node_modules/@stripe/stripe-js/dist/pure.js","node_modules/@stripe/stripe-js/pure.js","app/assets/vite/utils/stripe.ts","app/assets/vite/modules/website/elements/Stripe.ts","node_modules/@paypal/paypal-js/dist/esm/paypal-js.js","app/assets/vite/modules/website/elements/Paypal.ts"],"sourcesContent":["import { Model } from \"hybrids\";\n\ninterface PaymentRequest {\n id: string;\n amount: number;\n currency: string;\n country: string;\n label: string;\n}\n\nconst PaymentRequest: Model = {\n id: true,\n amount: 0,\n currency: \"\",\n country: \"\",\n label: \"\",\n};\n\nexport default PaymentRequest;\n","'use strict';\n\nObject.defineProperty(exports, '__esModule', { value: true });\n\nfunction _typeof(obj) {\n \"@babel/helpers - typeof\";\n\n if (typeof Symbol === \"function\" && typeof Symbol.iterator === \"symbol\") {\n _typeof = function (obj) {\n return typeof obj;\n };\n } else {\n _typeof = function (obj) {\n return obj && typeof Symbol === \"function\" && obj.constructor === Symbol && obj !== Symbol.prototype ? \"symbol\" : typeof obj;\n };\n }\n\n return _typeof(obj);\n}\n\nvar V3_URL = 'https://js.stripe.com/v3';\nvar V3_URL_REGEX = /^https:\\/\\/js\\.stripe\\.com\\/v3\\/?(\\?.*)?$/;\nvar EXISTING_SCRIPT_MESSAGE = 'loadStripe.setLoadParameters was called but an existing Stripe.js script already exists in the document; existing script parameters will be used';\nvar findScript = function findScript() {\n var scripts = document.querySelectorAll(\"script[src^=\\\"\".concat(V3_URL, \"\\\"]\"));\n\n for (var i = 0; i < scripts.length; i++) {\n var script = scripts[i];\n\n if (!V3_URL_REGEX.test(script.src)) {\n continue;\n }\n\n return script;\n }\n\n return null;\n};\n\nvar injectScript = function injectScript(params) {\n var queryString = params && !params.advancedFraudSignals ? '?advancedFraudSignals=false' : '';\n var script = document.createElement('script');\n script.src = \"\".concat(V3_URL).concat(queryString);\n var headOrBody = document.head || document.body;\n\n if (!headOrBody) {\n throw new Error('Expected document.body not to be null. Stripe.js requires a element.');\n }\n\n headOrBody.appendChild(script);\n return script;\n};\n\nvar registerWrapper = function registerWrapper(stripe, startTime) {\n if (!stripe || !stripe._registerWrapper) {\n return;\n }\n\n stripe._registerWrapper({\n name: 'stripe-js',\n version: \"1.53.0\",\n startTime: startTime\n });\n};\n\nvar stripePromise = null;\nvar loadScript = function loadScript(params) {\n // Ensure that we only attempt to load Stripe.js at most once\n if (stripePromise !== null) {\n return stripePromise;\n }\n\n stripePromise = new Promise(function (resolve, reject) {\n if (typeof window === 'undefined' || typeof document === 'undefined') {\n // Resolve to null when imported server side. This makes the module\n // safe to import in an isomorphic code base.\n resolve(null);\n return;\n }\n\n if (window.Stripe && params) {\n console.warn(EXISTING_SCRIPT_MESSAGE);\n }\n\n if (window.Stripe) {\n resolve(window.Stripe);\n return;\n }\n\n try {\n var script = findScript();\n\n if (script && params) {\n console.warn(EXISTING_SCRIPT_MESSAGE);\n } else if (!script) {\n script = injectScript(params);\n }\n\n script.addEventListener('load', function () {\n if (window.Stripe) {\n resolve(window.Stripe);\n } else {\n reject(new Error('Stripe.js not available'));\n }\n });\n script.addEventListener('error', function () {\n reject(new Error('Failed to load Stripe.js'));\n });\n } catch (error) {\n reject(error);\n return;\n }\n });\n return stripePromise;\n};\nvar initStripe = function initStripe(maybeStripe, args, startTime) {\n if (maybeStripe === null) {\n return null;\n }\n\n var stripe = maybeStripe.apply(undefined, args);\n registerWrapper(stripe, startTime);\n return stripe;\n}; // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types\n\nvar validateLoadParams = function validateLoadParams(params) {\n var errorMessage = \"invalid load parameters; expected object of shape\\n\\n {advancedFraudSignals: boolean}\\n\\nbut received\\n\\n \".concat(JSON.stringify(params), \"\\n\");\n\n if (params === null || _typeof(params) !== 'object') {\n throw new Error(errorMessage);\n }\n\n if (Object.keys(params).length === 1 && typeof params.advancedFraudSignals === 'boolean') {\n return params;\n }\n\n throw new Error(errorMessage);\n};\n\nvar loadParams;\nvar loadStripeCalled = false;\nvar loadStripe = function loadStripe() {\n for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {\n args[_key] = arguments[_key];\n }\n\n loadStripeCalled = true;\n var startTime = Date.now();\n return loadScript(loadParams).then(function (maybeStripe) {\n return initStripe(maybeStripe, args, startTime);\n });\n};\n\nloadStripe.setLoadParameters = function (params) {\n // we won't throw an error if setLoadParameters is called with the same values as before\n if (loadStripeCalled && loadParams) {\n var validatedParams = validateLoadParams(params);\n var parameterKeys = Object.keys(validatedParams);\n var sameParameters = parameterKeys.reduce(function (previousValue, currentValue) {\n var _loadParams;\n\n return previousValue && params[currentValue] === ((_loadParams = loadParams) === null || _loadParams === void 0 ? void 0 : _loadParams[currentValue]);\n }, true);\n\n if (sameParameters) {\n return;\n }\n }\n\n if (loadStripeCalled) {\n throw new Error('You cannot change load parameters after calling loadStripe');\n }\n\n loadParams = validateLoadParams(params);\n};\n\nexports.loadStripe = loadStripe;\n","module.exports = require('./dist/pure.js');\n","import { loadStripe } from \"@stripe/stripe-js/pure\";\nimport {\n ConfirmPaymentData,\n Stripe,\n StripeElement,\n StripeElements,\n} from \"@stripe/stripe-js\";\nimport {post} from \"~/utils/api\";\n\nlet stripe: Stripe | null;\nlet paymentElement: StripeElement | null;\nlet elements: StripeElements | null;\n\nexport default async function load(key: string, stripeAccount: string) {\n if (stripe) return stripe;\n return (stripe = await loadStripe(key, { stripeAccount }));\n}\n\nexport async function mount(\n target: HTMLElement,\n key: string,\n stripeAccount: string,\n paymentRequestId: string | null,\n styles?: object\n) {\n if (!paymentRequestId) throw Error(\"Client secret not available\");\n\n stripe = stripe || (await loadStripe(key, { stripeAccount }));\n if (stripe) {\n try {\n const stripeIntent = await post(\"/payment_methods/stripe\", {\n id: paymentRequestId,\n });\n const clientSecret = stripeIntent.client_secret;\n const appearance = {\n theme: \"stripe\",\n variables: {\n fontFamily: \"Averta, sans-serif\",\n fontSizeBase: \"14px\",\n ...styles,\n }\n };\n elements = stripe.elements({ clientSecret, appearance });\n paymentElement = elements.create(\"payment\", { layout: {\n type: \"accordion\",\n radios: false,\n }});\n\n paymentElement.mount(target);\n } catch (error) {\n throw error;\n }\n }\n\n return stripe;\n}\n\nexport function unmount() {\n if (paymentElement) {\n paymentElement.unmount();\n paymentElement = null;\n }\n}\n\nexport async function confirmCardPayment(\n paymentMethod?: ConfirmPaymentData[\"payment_method\"]\n) {\n if (!stripe) throw Error(\"Stripe API or Card element not initialized\");\n\n return await stripe.confirmPayment({\n // paymentMethod || (paymentElement ? { paymentElement } : undefined),\n elements,\n confirmParams: {\n return_url: window.location.origin + \"/payments/stripe/complete_payment\"\n }\n });\n}\n","import { define, dispatch, html, store } from \"hybrids\";\nimport {\n ConfirmCardPaymentData,\n StripePaymentRequestButtonElement,\n} from \"@stripe/stripe-js\";\n\nimport Order from \"~/stores/Order\";\nimport PaymentMethods from \"~/stores/PaymentMethods\";\nimport PaymentRequest from \"~/stores/PaymentRequest\";\n\nimport { post } from \"~/utils/api\";\nimport load, * as stripe from \"~/utils/stripe\";\n\nexport interface PaymentEvent extends CustomEvent {\n detail: {\n paymentMethod: Order[\"paymentMethod\"];\n paymentId: string;\n };\n}\n\nexport interface VWebsiteStripe extends HTMLElement {\n settings: PaymentMethods[\"stripe\"];\n paymentRequest?: PaymentRequest;\n cardEl?: ReturnType;\n newCard: boolean;\n paymentId: string;\n error: string;\n pending: boolean;\n}\n\nasync function confirm(\n host: VWebsiteStripe,\n event: Event | null,\n paymentMethod?: ConfirmCardPaymentData[\"payment_method\"]\n) {\n try {\n if (!host.paymentRequest) {\n throw Error(\"Missing payment request object\");\n }\n\n host.error = \"\";\n\n if (!paymentMethod && !host.newCard && host.paymentId) {\n dispatch(host, \"approve\", {\n detail: { paymentMethod: \"stripe\", paymentId: host.paymentId },\n });\n } else {\n host.pending = true;\n\n const result = await stripe.confirmCardPayment(\n paymentMethod\n );\n\n if (result.error) {\n throw result.error.message || \"Unknown error\";\n } else if (\n result.paymentIntent &&\n result.paymentIntent.status === \"succeeded\"\n ) {\n host.paymentId = result.paymentIntent.id;\n host.pending = false;\n\n dispatch(host, \"approve\", {\n detail: { paymentMethod: \"stripe\", paymentId: host.paymentId },\n });\n }\n }\n } catch (error) {\n host.error = String(error);\n host.pending = false;\n\n throw error;\n }\n}\n\nfunction toggleNewCard(host: VWebsiteStripe) {\n host.newCard = !host.newCard;\n}\n\nexport default define({\n tag: \"v-website-stripe\",\n settings: {\n value: undefined,\n observe(host, value) {\n if (value && value.cards.length) {\n host.paymentId = value.cards[0].id;\n }\n },\n },\n paymentRequest: store(PaymentRequest),\n error: \"\",\n cardEl: {\n async get(host) {\n host.pending = true;\n if (!host.paymentRequest) {\n host.pending = false;\n throw Error(\"Missing payment request object\");\n }\n\n const { key, account } = host.settings;\n const el = host.querySelector(\"#stripe-card-element\") as HTMLElement;\n\n const paymentMethodsElement = await stripe.mount(el, key, account, host.paymentRequest.id, {\n colorText: window\n .getComputedStyle(host)\n .getPropertyValue(\"--v-ui-color-text-primary\")\n .trim(),\n colorPrimary: window\n .getComputedStyle(host)\n .getPropertyValue(\"--v-ui-color-secondary\")\n .trim(),\n colorBackground: window\n .getComputedStyle(host)\n .getPropertyValue(\"--v-ui-loader-background\")\n .trim(),\n });\n\n setTimeout(() => {\n host.pending = false;\n }, 2000);\n\n return paymentMethodsElement;\n },\n connect: () => stripe.unmount,\n observe() {},\n },\n newCard: false,\n paymentId: \"\",\n pending: false,\n render: ({\n settings,\n newCard,\n paymentId,\n error,\n pending,\n }) => html`\n \n \n ${!newCard &&\n !!settings.cards.length &&\n html`\n ${settings.cards.map(\n (card) => html`\n \n `\n )}\n\n \n \n `}\n ${pending\n ? html`\n \n \n \n `\n : html`${(newCard || !settings.cards.length) &&\n html`\n \n \n \n ${!!settings.cards.length &&\n html`\n \n \n `}\n `}\n \n \n ${error &&\n html`\n ${error}\n `}\n \n `}\n \n `.css`\n :host(:last-child) v-ui-divider:last-child { display: none }\n \n label.radio {\n cursor: pointer;\n }\n `,\n content: () => html`\n
\n `,\n});\n","/*!\n * paypal-js v4.0.2 (2021-07-05T19:59:23.708Z)\n * Copyright 2020-present, PayPal, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nfunction findScript(url, attributes) {\n var currentScript = document.querySelector(\"script[src=\\\"\" + url + \"\\\"]\");\n if (currentScript === null) return null;\n var nextScript = createScriptElement(url, attributes); // ignore the data-uid-auto attribute that gets auto-assigned to every script tag\n\n var currentScriptDataset = Object.assign({}, currentScript.dataset);\n delete currentScriptDataset.uidAuto; // check if the new script has the same number of data attributes\n\n if (Object.keys(currentScriptDataset).length !== Object.keys(nextScript.dataset).length) {\n return null;\n }\n\n var isExactMatch = true; // check if the data attribute values are the same\n\n Object.keys(currentScriptDataset).forEach(function (key) {\n if (currentScriptDataset[key] !== nextScript.dataset[key]) {\n isExactMatch = false;\n }\n });\n return isExactMatch ? currentScript : null;\n}\nfunction insertScriptElement(_a) {\n var url = _a.url,\n attributes = _a.attributes,\n onSuccess = _a.onSuccess,\n onError = _a.onError;\n var newScript = createScriptElement(url, attributes);\n newScript.onerror = onError;\n newScript.onload = onSuccess;\n document.head.insertBefore(newScript, document.head.firstElementChild);\n}\nfunction processOptions(options) {\n var sdkBaseURL = \"https://www.paypal.com/sdk/js\";\n\n if (options.sdkBaseURL) {\n sdkBaseURL = options.sdkBaseURL;\n delete options.sdkBaseURL;\n }\n\n var processedMerchantIDAttributes = processMerchantID(options[\"merchant-id\"], options[\"data-merchant-id\"]);\n var newOptions = Object.assign({}, options, processedMerchantIDAttributes);\n\n var _a = Object.keys(newOptions).filter(function (key) {\n return typeof newOptions[key] !== \"undefined\" && newOptions[key] !== null && newOptions[key] !== \"\";\n }).reduce(function (accumulator, key) {\n var value = newOptions[key].toString();\n\n if (key.substring(0, 5) === \"data-\") {\n accumulator.dataAttributes[key] = value;\n } else {\n accumulator.queryParams[key] = value;\n }\n\n return accumulator;\n }, {\n queryParams: {},\n dataAttributes: {}\n }),\n queryParams = _a.queryParams,\n dataAttributes = _a.dataAttributes;\n\n return {\n url: sdkBaseURL + \"?\" + objectToQueryString(queryParams),\n dataAttributes: dataAttributes\n };\n}\nfunction objectToQueryString(params) {\n var queryString = \"\";\n Object.keys(params).forEach(function (key) {\n if (queryString.length !== 0) queryString += \"&\";\n queryString += key + \"=\" + params[key];\n });\n return queryString;\n}\n\nfunction createScriptElement(url, attributes) {\n if (attributes === void 0) {\n attributes = {};\n }\n\n var newScript = document.createElement(\"script\");\n newScript.src = url;\n Object.keys(attributes).forEach(function (key) {\n newScript.setAttribute(key, attributes[key]);\n\n if (key === \"data-csp-nonce\") {\n newScript.setAttribute(\"nonce\", attributes[\"data-csp-nonce\"]);\n }\n });\n return newScript;\n}\n\nfunction processMerchantID(merchantID, dataMerchantID) {\n var newMerchantID = \"\";\n var newDataMerchantID = \"\";\n\n if (Array.isArray(merchantID)) {\n if (merchantID.length > 1) {\n newMerchantID = \"*\";\n newDataMerchantID = merchantID.toString();\n } else {\n newMerchantID = merchantID.toString();\n }\n } else if (typeof merchantID === \"string\" && merchantID.length > 0) {\n newMerchantID = merchantID;\n } else if (typeof dataMerchantID === \"string\" && dataMerchantID.length > 0) {\n newMerchantID = \"*\";\n newDataMerchantID = dataMerchantID;\n }\n\n return {\n \"merchant-id\": newMerchantID,\n \"data-merchant-id\": newDataMerchantID\n };\n}\n\n/**\n * Load the Paypal JS SDK script asynchronously.\n *\n * @param {Object} options - used to configure query parameters and data attributes for the JS SDK.\n * @param {PromiseConstructor} [PromisePonyfill=window.Promise] - optional Promise Constructor ponyfill.\n * @return {Promise} paypalObject - reference to the global window PayPal object.\n */\n\nfunction loadScript(options, PromisePonyfill) {\n if (PromisePonyfill === void 0) {\n PromisePonyfill = getDefaultPromiseImplementation();\n }\n\n validateArguments(options, PromisePonyfill); // resolve with null when running in Node\n\n if (typeof window === \"undefined\") return PromisePonyfill.resolve(null);\n\n var _a = processOptions(options),\n url = _a.url,\n dataAttributes = _a.dataAttributes;\n\n var namespace = dataAttributes[\"data-namespace\"] || \"paypal\";\n var existingWindowNamespace = getPayPalWindowNamespace(namespace); // resolve with the existing global paypal namespace when a script with the same params already exists\n\n if (findScript(url, dataAttributes) && existingWindowNamespace) {\n return PromisePonyfill.resolve(existingWindowNamespace);\n }\n\n return loadCustomScript({\n url: url,\n attributes: dataAttributes\n }, PromisePonyfill).then(function () {\n var newWindowNamespace = getPayPalWindowNamespace(namespace);\n\n if (newWindowNamespace) {\n return newWindowNamespace;\n }\n\n throw new Error(\"The window.\" + namespace + \" global variable is not available.\");\n });\n}\n/**\n * Load a custom script asynchronously.\n *\n * @param {Object} options - used to set the script url and attributes.\n * @param {PromiseConstructor} [PromisePonyfill=window.Promise] - optional Promise Constructor ponyfill.\n * @return {Promise} returns a promise to indicate if the script was successfully loaded.\n */\n\nfunction loadCustomScript(options, PromisePonyfill) {\n if (PromisePonyfill === void 0) {\n PromisePonyfill = getDefaultPromiseImplementation();\n }\n\n validateArguments(options, PromisePonyfill);\n var url = options.url,\n attributes = options.attributes;\n\n if (typeof url !== \"string\" || url.length === 0) {\n throw new Error(\"Invalid url.\");\n }\n\n if (typeof attributes !== \"undefined\" && typeof attributes !== \"object\") {\n throw new Error(\"Expected attributes to be an object.\");\n }\n\n return new PromisePonyfill(function (resolve, reject) {\n // resolve with undefined when running in Node\n if (typeof window === \"undefined\") return resolve();\n insertScriptElement({\n url: url,\n attributes: attributes,\n onSuccess: function onSuccess() {\n return resolve();\n },\n onError: function onError() {\n return reject(new Error(\"The script \\\"\" + url + \"\\\" failed to load.\"));\n }\n });\n });\n}\n\nfunction getDefaultPromiseImplementation() {\n if (typeof Promise === \"undefined\") {\n throw new Error(\"Promise is undefined. To resolve the issue, use a Promise polyfill.\");\n }\n\n return Promise;\n}\n\nfunction getPayPalWindowNamespace(namespace) {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n return window[namespace];\n}\n\nfunction validateArguments(options, PromisePonyfill) {\n if (typeof options !== \"object\" || options === null) {\n throw new Error(\"Expected an options object.\");\n }\n\n if (typeof PromisePonyfill !== \"undefined\" && typeof PromisePonyfill !== \"function\") {\n throw new Error(\"Expected PromisePonyfill to be a function.\");\n }\n}\n\nvar version = \"4.0.2\";\n\nexport { loadCustomScript, loadScript, version };\n","import { define, dispatch, html, store } from \"hybrids\";\nimport { loadScript, PayPalNamespace } from \"@paypal/paypal-js\";\nimport { PayPalButtonsComponent } from \"@paypal/paypal-js/types/components/buttons\";\n\nimport { post } from \"~/utils/api\";\nimport PaymentRequest from \"~/stores/PaymentRequest\";\n\nexport interface WebsitePaypal {\n clientId: string;\n paymentRequest?: PaymentRequest;\n paymentId: string;\n error: string;\n el: PayPalButtonsComponent;\n paypal: Promise;\n}\n\nexport default define({\n tag: \"v-website-paypal\",\n clientId: \"\",\n paymentRequest: store(PaymentRequest),\n paymentId: \"\",\n error: \"\",\n el: undefined,\n paypal: {\n get: ({ clientId, paymentRequest }) => {\n if (!paymentRequest) {\n return Promise.reject(Error(\"Missing payment request object\"));\n }\n\n return loadScript({\n \"client-id\": clientId,\n currency: paymentRequest.currency,\n \"disable-funding\":\n \"card,credit,blik,venmo,sepa,bancontact,eps,giropay,ideal,mybank,p24,sofort\",\n });\n },\n observe(host, promise) {\n promise.then((paypal) => {\n if (paypal) {\n host.el?.close();\n\n host.el = paypal.Buttons?.({\n style: {\n layout: \"vertical\",\n color: \"blue\",\n shape: \"rect\",\n label: \"paypal\",\n height: 40,\n },\n createOrder: async () => {\n if (!host.paymentRequest) {\n throw Error(\"Missing payment request object\");\n }\n\n host.error = \"\";\n\n const res = await post(\"/payment_methods/paypal\", {\n id: host.paymentRequest.id,\n });\n\n if (res.errors) {\n throw res.errors;\n } else if (Math.round(res.status_code / 100) !== 2) {\n throw res.result.details[0].description;\n }\n\n return res.result.id;\n },\n onError: (error) => {\n host.error = String(error);\n },\n onApprove: async (data) => {\n host.error = \"\";\n host.paymentId = data.orderID;\n\n dispatch(host, \"approve\", {\n detail: { paymentId: data.orderID, paymentMethod: \"paypal\" },\n });\n },\n }) as PayPalButtonsComponent;\n\n host.el.render(host.querySelector(\"#paypal-input\") as HTMLElement);\n }\n });\n },\n },\n render: ({ error }) =>\n html`\n Integrated providers\n \n ${error &&\n html`\n \n ${error}\n \n `}\n `,\n content: ({ paymentId }) => html`\n