whoami7 - Manager
:
/
home
/
dataiclx
/
vielorbe.com
/
wp-content
/
plugins
/
surecart
/
dist
/
components
/
esm
/
Upload File:
files >> //home/dataiclx/vielorbe.com/wp-content/plugins/surecart/dist/components/esm/index-885ece77.js.map
{"file":"index-885ece77.js","mappings":";;;;;AAOA;;AAGA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA+BA;;;;;;;;;;;;;;;;;;AAgBA;;;;;;;;;;AAQA;;;;;;;;;;;;;;AAeA;AAEA;;;;;;;AAOA;AAEA;;;;;AAKA;AAEA;;;;;;;;AAQA;AAEA;;;;;;;AAOA;AAEA;;;;;;;AAOA;AAEA;;;;;;;;;;AAaA;AAEA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA8CA;AAEA;;;;;;;;;wCAUoC,UAAE;;;AAItC;AAEA;;;;;;;;;;;;;;;;;AAkBA;;;;","names":[],"sources":["src/services/session/index.ts"],"sourcesContent":["import { state as checkoutState } from '@store/checkout';\nimport { addQueryArgs, getQueryArg } from '@wordpress/url';\n\nimport apiFetch from '../../functions/fetch';\nimport { Checkout, DeletedItem, Invoice, LineItem } from '../../types';\nimport { __ } from '@wordpress/i18n';\n\n/** The base url for this service. */\nexport const baseUrl = 'surecart/v1/checkouts/';\n\n/** Items to always expand. */\nexport const expand = [\n 'line_items',\n 'line_item.price',\n 'line_item.fees',\n 'line_item.variant',\n 'variant.image',\n 'price.product',\n 'product.product_medias',\n 'product.featured_product_media',\n 'product.product_collections',\n 'product_media.media',\n 'customer',\n 'customer.shipping_address',\n 'payment_intent',\n 'discount',\n 'discount.promotion',\n 'recommended_bumps',\n 'bump.price',\n 'current_upsell',\n 'product.variants',\n 'discount.coupon',\n 'shipping_address',\n 'billing_address',\n 'tax_identifier',\n 'manual_payment_method',\n 'shipping_choices',\n 'shipping_choice.shipping_method',\n 'invoice',\n];\n\n/** Default data we send with every request. */\nexport const withDefaultData = (data: { metadata?: any } = {}) => ({\n live_mode: checkoutState.mode !== 'test',\n group_key: checkoutState.groupId,\n abandoned_checkout_enabled: checkoutState.abandonedCheckoutEnabled,\n billing_matches_shipping: checkoutState.checkout?.billing_matches_shipping,\n metadata: {\n ...(data?.metadata || {}),\n ...(window?.scData?.page_id && { page_id: window?.scData?.page_id }),\n ...(checkoutState?.product?.id && { buy_page_product_id: checkoutState?.product?.id }),\n page_url: window.location.href,\n },\n ...(checkoutState?.checkout?.email && { email: checkoutState?.checkout?.email }),\n ...data,\n});\n\n/** Default query we send with every request. */\nexport const withDefaultQuery = (query = {}) => ({\n ...(!!checkoutState?.formId && { form_id: checkoutState?.formId }),\n ...(!!checkoutState?.product?.id && { product_id: checkoutState?.product?.id }),\n ...(!!(checkoutState?.checkout?.invoice as Invoice)?.id && { type: 'open_invoice' }),\n ...query,\n});\n\n/** Get the checkout id */\nexport const findInitialCheckoutId = () => {\n // check url first.\n const checkoutId = getQueryArg(window.location.href, 'checkout_id');\n if (!!checkoutId) {\n return checkoutId;\n }\n\n // check existing order.\n if (checkoutState?.checkout?.id) {\n return checkoutState?.checkout?.id;\n }\n\n // we don't have and order id.\n return null;\n};\n\n/** Parse the path with expansions. */\nexport const parsePath = (id, endpoint = '') => {\n let path = id ? `${baseUrl}${id}` : baseUrl;\n path = `${path}${endpoint}`;\n return addQueryArgs(path, {\n expand,\n });\n};\n\n/** Fethc a checkout by id */\nexport const fetchCheckout = async ({ id, query = {} }) => {\n return (await apiFetch({\n path: addQueryArgs(parsePath(id), withDefaultQuery(query)),\n })) as Checkout;\n};\n\n/** Create or update the checkout. */\nexport const createOrUpdateCheckout = async ({ id = null, data = {}, query = {} }) => {\n id = !id ? findInitialCheckoutId() : id;\n return await apiFetch({\n method: id ? 'PATCH' : 'POST', // create or update\n path: addQueryArgs(parsePath(id), withDefaultQuery(query)),\n data: withDefaultData(data),\n });\n};\n\n/** Create the checkout */\nexport const createCheckout = async ({ data = {}, query = {} }) => {\n return await apiFetch({\n method: 'POST', // create\n path: addQueryArgs(parsePath(null), withDefaultQuery(query)),\n data: withDefaultData(data),\n });\n};\n\n/** Update the checkout. */\nexport const updateCheckout = async ({ id, data = {}, query = {} }) => {\n return await apiFetch({\n method: 'PATCH',\n path: addQueryArgs(parsePath(id), withDefaultQuery(query)),\n data: withDefaultData(data),\n });\n};\n\n/** Finalize a checkout */\nexport const finalizeCheckout = async ({ id, data = {}, query = {}, processor }: { id: string; data?: any; query?: any; processor: { id: string; manual: boolean } }) => {\n return (await apiFetch({\n method: 'POST',\n path: addQueryArgs(\n parsePath(id, '/finalize'),\n withDefaultQuery({\n ...(processor?.manual ? { manual_payment: true, manual_payment_method_id: processor?.id } : { processor_type: processor?.id }),\n ...query,\n }),\n ),\n data: withDefaultData(data),\n })) as Checkout;\n};\n\n/**\n * Add a line item.\n */\nexport const addLineItem = async ({ checkout, data, live_mode = false }) => {\n const existingLineItem = (checkout?.line_items?.data || []).find(item => {\n if (!item?.variant?.id) {\n return item.price.id === data.price;\n }\n return item.variant.id === data.variant && item.price.id === data.price;\n });\n\n // create the checkout with the line item.\n if (!checkout?.id) {\n return (await apiFetch({\n method: 'POST', // create\n path: addQueryArgs(parsePath(null)),\n data: {\n line_items: [data],\n live_mode,\n },\n })) as Checkout;\n }\n\n // handle existing line item.\n if (!!existingLineItem) {\n return await updateLineItem({ id: existingLineItem?.id, data: { ...data, quantity: existingLineItem?.quantity + data?.quantity } });\n }\n\n const item = (await apiFetch({\n path: addQueryArgs(`surecart/v1/line_items/${existingLineItem?.id ? existingLineItem?.id : ''}`, {\n consolidate: true,\n expand: [\n ...(expand || []).map(item => {\n return item.includes('.') ? item : `checkout.${item}`;\n }),\n 'checkout',\n ],\n }),\n method: 'POST',\n data: {\n ...data,\n checkout: checkout.id,\n },\n })) as LineItem;\n\n return item?.checkout as Checkout;\n};\n\n/**\n * Remove a line item.\n */\nexport const removeLineItem = async ({ checkoutId, itemId }) => {\n const { deleted } = (await apiFetch({\n path: `surecart/v1/line_items/${itemId}`,\n method: 'DELETE',\n })) as DeletedItem;\n\n if (!deleted) {\n throw { code: 'error', message: __('Failed to delete', 'surecart') };\n }\n\n return await fetchCheckout({ id: checkoutId });\n};\n\n/**\n * Update a line item.\n */\nexport const updateLineItem = async ({ id, data }) => {\n const item = (await apiFetch({\n path: addQueryArgs(`surecart/v1/line_items/${id}`, {\n expand: [\n ...(expand || []).map(item => {\n return item.includes('.') ? item : `checkout.${item}`;\n }),\n 'checkout',\n ],\n }),\n method: 'PATCH',\n data,\n })) as LineItem;\n\n return item?.checkout as Checkout;\n};\n"],"version":3}
Copyright ©2021 || Defacer Indonesia