whoami7 - Manager
:
/
home
/
dataiclx
/
vielorbe.com
/
wp-content
/
plugins
/
surecart
/
dist
/
components
/
surecart
/
Upload File:
files >> //home/dataiclx/vielorbe.com/wp-content/plugins/surecart/dist/components/surecart/p-3b9fdf35.js.map
{"version":3,"names":["wp","i18n","__"],"sources":["src/store/upsell/mutations.ts"],"sourcesContent":["/**\n * External dependencies.\n */\nimport { addQueryArgs } from '@wordpress/url';\nimport apiFetch from '../../functions/fetch';\n\n/**\n * Internal dependencies.\n */\nimport { Checkout, LineItem, Price } from 'src/types';\nimport { state } from './store';\nimport { state as productState } from '../product';\nimport { createErrorNotice, removeNotice } from '@store/notices/mutations';\nimport { __ } from '@wordpress/i18n';\n\n/**\n * Update the upsell.\n */\nexport const trackOffer = () =>\n apiFetch({\n path: `surecart/v1/checkouts/${state.checkout_id}/offer_upsell/${state.upsell?.id}`,\n method: 'POST',\n keepalive: true, // Important: allow the request to outlive the page.\n });\n\n/**\n * Update the upsell.\n */\nexport const preview = async () => {\n try {\n if (!state.checkout_id || state.loading === 'busy') {\n return;\n }\n\n state.loading = 'busy';\n removeNotice();\n\n // Add Upsell to line item.\n const { checkout, ...lineItem } = await upsellRequest({ preview: true });\n\n state.checkout = checkout as Checkout;\n state.line_item = lineItem as LineItem;\n } catch (error) {\n console.error(error);\n\n if ((error?.additional_errors || []).find(error => error?.data?.options?.purchasable_statuses?.includes('out_of_stock'))) {\n return createErrorNotice({ code: 'out_of_stock', message: __('Apologies, this is currently out of stock.', 'surecart') });\n }\n\n if ((error?.additional_errors || []).find(error => error?.code === 'line_item.upsell.expired')) {\n state.loading = 'idle';\n createErrorNotice({ code: 'expired', message: __('This offer has expired.', 'surecart') });\n return decline();\n }\n\n createErrorNotice(error);\n } finally {\n state.loading = 'idle';\n }\n};\n\nexport const accept = async () => {\n try {\n if (!state.checkout_id || state.loading === 'busy') {\n return;\n }\n\n state.loading = 'busy';\n removeNotice();\n\n // Add Upsell to line item.\n const { checkout } = await upsellRequest({ preview: false });\n\n handleCompletion(checkout);\n } catch (error) {\n state.loading = 'idle';\n createErrorNotice(error);\n }\n};\n\n/**\n * Decline the upsell.\n */\nexport const decline = async () => {\n try {\n if (!state.checkout_id || state.loading === 'busy') {\n return;\n }\n\n state.loading = 'busy';\n removeNotice();\n\n // Add Upsell to line item.\n const checkout = (await apiFetch({\n path: addQueryArgs(`surecart/v1/checkouts/${state.checkout_id}/decline_upsell/${state.upsell?.id}`, {\n expand: ['checkout', 'checkout.current_upsell', 'fees'],\n }),\n method: 'POST',\n data: {\n ...productState[state.product?.id]?.line_item,\n price_id: (state.upsell?.price as Price)?.id,\n upsell: state.upsell?.id,\n checkout: state.checkout_id,\n },\n })) as Checkout;\n\n handleCompletion(checkout);\n } catch (error) {\n state.loading = 'idle';\n createErrorNotice(error);\n }\n};\n\n/**\n * Make the request to the upsell endpoing\n */\nexport const upsellRequest = args =>\n apiFetch({\n path: addQueryArgs('surecart/v1/line_items/upsell', {\n ...args,\n expand: ['checkout', 'checkout.current_upsell', 'checkout.manual_payment_method', 'fees', 'line_item', 'line_item.price'],\n }),\n method: 'POST',\n data: {\n ...productState[state.product?.id]?.line_item,\n price_id: (state.upsell?.price as Price)?.id,\n upsell: state.upsell?.id,\n checkout: state.checkout_id,\n },\n }) as Promise<LineItem>;\n\n/**\n * Handle what to do on completion.\n */\nexport const handleCompletion = checkout => {\n // There is no more upsells, or the link is the same.\n if (!checkout.current_upsell?.permalink || checkout?.current_upsell?.permalink === state.upsell?.permalink) {\n return (state.loading = 'complete');\n }\n\n // redirect to next upsell.\n state.loading = 'redirecting';\n window.location.assign(\n addQueryArgs(checkout.current_upsell?.permalink, {\n sc_checkout_id: state.checkout?.id,\n sc_form_id: state.form_id,\n }),\n );\n};\n"],"mappings":"u1BA8CgEA,GAAAC,KAAAC,GAAE,0D,qLAKdF,GAAAC,KAAAC,GAAE,wC","ignoreList":[]}
Copyright ©2021 || Defacer Indonesia