@dropins/storefront-checkout 2.1.0 → 2.2.0-alpha2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/api/getCompanyCredit/getCompanyCredit.d.ts +4 -0
- package/api/getCompanyCredit/graphql/getCompanyCredit.graphql.d.ts +18 -0
- package/api/getCompanyCredit/graphql/index.d.ts +18 -0
- package/api/getCompanyCredit/index.d.ts +18 -0
- package/api/graphql/NegotiableQuoteAddressFragment.graphql.d.ts +1 -1
- package/api/graphql/PaymentMethodFragment.graphql.d.ts +1 -1
- package/api/index.d.ts +1 -0
- package/api/initialize/initialize.d.ts +6 -2
- package/api.js +2 -2
- package/api.js.map +1 -1
- package/chunks/PaymentOnAccount2.js +4 -0
- package/chunks/PaymentOnAccount2.js.map +1 -0
- package/chunks/PurchaseOrder.js +4 -0
- package/chunks/PurchaseOrder.js.map +1 -0
- package/chunks/classifiers.js +4 -0
- package/chunks/classifiers.js.map +1 -0
- package/chunks/events.js +1 -1
- package/chunks/events.js.map +1 -1
- package/chunks/events2.js +1 -1
- package/chunks/events2.js.map +1 -1
- package/chunks/fetch-graphql.js +1 -1
- package/chunks/getCompanyCredit.js +15 -0
- package/chunks/getCompanyCredit.js.map +1 -0
- package/chunks/guards.js +1 -1
- package/chunks/render.js +10 -0
- package/chunks/render.js.map +1 -0
- package/chunks/setBillingAddress.js +1 -1
- package/chunks/setGuestEmailOnCart.js +1 -1
- package/chunks/setGuestEmailOnCart.js.map +1 -1
- package/chunks/setShippingAddress.js +1 -1
- package/chunks/setShippingMethods.js +2 -2
- package/chunks/synchronizeCheckout.js +6 -6
- package/chunks/synchronizeCheckout.js.map +1 -1
- package/components/PaymentOnAccount/PaymentOnAccount.d.ts +17 -0
- package/components/PaymentOnAccount/PaymentOnAccountSkeleton.d.ts +4 -0
- package/components/PaymentOnAccount/index.d.ts +20 -0
- package/components/PurchaseOrder/PurchaseOrder.d.ts +10 -0
- package/components/PurchaseOrder/index.d.ts +19 -0
- package/components/index.d.ts +3 -1
- package/containers/AddressValidation.js +1 -1
- package/containers/AddressValidation.js.map +1 -1
- package/containers/BillToShippingAddress.js +1 -1
- package/containers/BillToShippingAddress.js.map +1 -1
- package/containers/EstimateShipping.js +1 -1
- package/containers/EstimateShipping.js.map +1 -1
- package/containers/LoginForm.js +1 -1
- package/containers/LoginForm.js.map +1 -1
- package/containers/MergedCartBanner.js +1 -1
- package/containers/MergedCartBanner.js.map +1 -1
- package/containers/OutOfStock.js +1 -1
- package/containers/OutOfStock.js.map +1 -1
- package/containers/PaymentMethods/PaymentMethods.d.ts +8 -6
- package/containers/PaymentMethods/handlers.d.ts +11 -0
- package/containers/PaymentMethods.js +1 -1
- package/containers/PaymentMethods.js.map +1 -1
- package/containers/PaymentOnAccount/PaymentOnAccount.d.ts +10 -0
- package/containers/PaymentOnAccount/index.d.ts +11 -0
- package/containers/PaymentOnAccount.d.ts +3 -0
- package/containers/PaymentOnAccount.js +4 -0
- package/containers/PaymentOnAccount.js.map +1 -0
- package/containers/PlaceOrder.js +1 -1
- package/containers/PlaceOrder.js.map +1 -1
- package/containers/PurchaseOrder/PurchaseOrder.d.ts +10 -0
- package/containers/PurchaseOrder/index.d.ts +19 -0
- package/containers/PurchaseOrder.d.ts +3 -0
- package/containers/PurchaseOrder.js +4 -0
- package/containers/PurchaseOrder.js.map +1 -0
- package/containers/ServerError/ServerError.d.ts +2 -1
- package/containers/ServerError.js +1 -1
- package/containers/ServerError.js.map +1 -1
- package/containers/ShippingMethods.js +1 -1
- package/containers/ShippingMethods.js.map +1 -1
- package/containers/TermsAndConditions.js +1 -1
- package/containers/TermsAndConditions.js.map +1 -1
- package/containers/index.d.ts +2 -0
- package/data/models/address.d.ts +1 -0
- package/data/models/company-credit.d.ts +7 -0
- package/data/models/index.d.ts +1 -0
- package/data/models/payment-method.d.ts +2 -0
- package/data/transforms/index.d.ts +1 -0
- package/data/transforms/transform-company-credit.d.ts +7 -0
- package/data/transforms/transform-quote-address.d.ts +1 -0
- package/fragments.js +15 -12
- package/fragments.js.map +1 -1
- package/i18n/en_US.json.d.ts +20 -0
- package/lib/errors/classifiers.d.ts +3 -1
- package/lib/utils.js +1 -1
- package/lib/utils.js.map +1 -1
- package/package.json +1 -1
- package/render.js +5 -5
- package/render.js.map +1 -1
- package/tests/fixtures/fragments/cart.d.ts +1 -0
- package/tests/fixtures/helpers/session-storage.d.ts +68 -0
- package/tests/fixtures/index.d.ts +1 -0
- package/tests/fixtures/queries/get-company-credit.d.ts +14 -0
- package/tests/fixtures/queries/index.d.ts +1 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PaymentMethods.js","sources":["../../node_modules/@adobe-commerce/elsie/src/icons/Wallet.svg","/@dropins/storefront-checkout/src/components/PaymentMethods/PaymentMethodsSkeleton.tsx","/@dropins/storefront-checkout/src/components/PaymentMethods/PaymentMethods.tsx","/@dropins/storefront-checkout/src/containers/PaymentMethods/PaymentMethods.tsx"],"sourcesContent":["import * as React from \"react\";\nconst SvgWallet = (props) => /* @__PURE__ */ React.createElement(\"svg\", { width: 24, height: 24, viewBox: \"0 0 24 24\", fill: \"none\", xmlns: \"http://www.w3.org/2000/svg\", ...props }, /* @__PURE__ */ React.createElement(\"path\", { vectorEffect: \"non-scaling-stroke\", d: \"M17.93 14.8V18.75H5.97C4.75 18.75 3.75 17.97 3.75 17V6.5M3.75 6.5C3.75 5.53 4.74 4.75 5.97 4.75H15.94V8.25H5.97C4.75 8.25 3.75 7.47 3.75 6.5Z\", stroke: \"currentColor\", strokeWidth: 1, strokeLinecap: \"round\", strokeLinejoin: \"round\" }), /* @__PURE__ */ React.createElement(\"path\", { vectorEffect: \"non-scaling-stroke\", d: \"M19.35 11.64H14.04V14.81H19.35V11.64Z\", stroke: \"currentColor\", strokeWidth: 1, strokeLinecap: \"round\", strokeLinejoin: \"round\" }), /* @__PURE__ */ React.createElement(\"path\", { vectorEffect: \"non-scaling-stroke\", d: \"M17.9304 11.64V8.25H15.1504\", stroke: \"currentColor\", strokeWidth: 1, strokeLinecap: \"round\", strokeLinejoin: \"round\" }));\nexport default SvgWallet;\n","/********************************************************************\n * ADOBE CONFIDENTIAL\n * __________________\n *\n * Copyright 2024 Adobe\n * All Rights Reserved.\n *\n * NOTICE: All information contained herein is, and remains\n * the property of Adobe and its suppliers, if any. The intellectual\n * and technical concepts contained herein are proprietary to Adobe\n * and its suppliers and are protected by all applicable intellectual\n * property laws, including trade secret and copyright laws.\n * Dissemination of this information or reproduction of this material\n * is strictly forbidden unless prior written permission is obtained\n * from Adobe.\n *******************************************************************/\n\nimport { Skeleton, SkeletonRow } from '@adobe-commerce/elsie/components';\nimport { FunctionComponent } from 'preact';\n\nexport const PaymentMethodsSkeleton: FunctionComponent = () => {\n return (\n <Skeleton data-testid=\"payment-methods-skeleton\">\n <SkeletonRow size=\"medium\" variant=\"heading\" />\n <SkeletonRow size=\"medium\" variant=\"empty\" />\n <SkeletonRow fullWidth={true} size=\"xlarge\" />\n <SkeletonRow fullWidth={true} size=\"xlarge\" />\n </Skeleton>\n );\n};\n","/********************************************************************\n * ADOBE CONFIDENTIAL\n * __________________\n *\n * Copyright 2024 Adobe\n * All Rights Reserved.\n *\n * NOTICE: All information contained herein is, and remains\n * the property of Adobe and its suppliers, if any. The intellectual\n * and technical concepts contained herein are proprietary to Adobe\n * and its suppliers and are protected by all applicable intellectual\n * property laws, including trade secret and copyright laws.\n * Dissemination of this information or reproduction of this material\n * is strictly forbidden unless prior written permission is obtained\n * from Adobe.\n *******************************************************************/\n\nimport { WithConditionals } from '@/checkout/components/ConditionalWrapper/ConditionalWrapper';\nimport '@/checkout/components/PaymentMethods/PaymentMethods.css';\nimport { PaymentMethodsSkeleton } from '@/checkout/components/PaymentMethods/PaymentMethodsSkeleton';\nimport { PaymentMethodConfig } from '@/checkout/containers';\nimport { PaymentMethod } from '@/checkout/data/models/payment-method';\nimport { scrollToElement } from '@/checkout/lib';\nimport { UIComponentType } from '@/checkout/types';\nimport {\n Icon,\n IllustratedMessage,\n InLineAlert,\n RadioButton,\n ToggleButton,\n} from '@adobe-commerce/elsie/components';\nimport { useText } from '@adobe-commerce/elsie/i18n';\nimport { Wallet } from '@adobe-commerce/elsie/icons';\nimport { classes, VComponent } from '@adobe-commerce/elsie/lib';\nimport { FunctionComponent, VNode } from 'preact';\nimport { HTMLAttributes, useEffect, useRef } from 'preact/compat';\n\ninterface ExtendedPaymentMethod extends PaymentMethodConfig, PaymentMethod {}\n\nexport interface PaymentMethodsProps\n extends Omit<HTMLAttributes<HTMLDivElement>, 'title'> {\n error?: string | null;\n busy?: boolean;\n onDismissError?: () => void;\n onSelectionChange?: (value: PaymentMethod) => void;\n options?: ExtendedPaymentMethod[];\n paymentMethodContent?: VNode;\n selection: PaymentMethod | null;\n title?: VNode;\n UIComponentType?: UIComponentType;\n}\n\ninterface PaymentOptionProps {\n UIComponentType?: UIComponentType;\n busy?: boolean;\n code: string;\n icon?: string;\n onSelectionChange: (value: PaymentMethod) => void;\n selected: boolean;\n title: string;\n}\n\nconst PaymentOption: FunctionComponent<PaymentOptionProps> = ({\n UIComponentType = 'ToggleButton',\n busy,\n code,\n icon,\n onSelectionChange,\n selected,\n title,\n}) => {\n const commonProps = {\n busy,\n className: 'checkout-payment-methods__method',\n label: title,\n name: 'payment-method',\n onChange: () => onSelectionChange({ code, title }),\n value: code,\n };\n\n return UIComponentType === 'ToggleButton' ? (\n <ToggleButton\n {...commonProps}\n // @ts-ignore\n icon={icon ? <Icon source={icon} /> : undefined}\n selected={selected}\n />\n ) : (\n <RadioButton {...commonProps} checked={selected} icon={icon ?? undefined} />\n );\n};\n\nconst PaymentMethodsComponent: FunctionComponent<PaymentMethodsProps> = ({\n className,\n error = null,\n busy = false,\n onDismissError,\n onSelectionChange = () => {},\n options,\n paymentMethodContent,\n selection,\n title,\n UIComponentType,\n}) => {\n const translations = useText({\n EmptyState: 'Checkout.PaymentMethods.emptyState',\n });\n\n const hasError = error !== null;\n const errorRef = useRef<HTMLDivElement>(null);\n\n useEffect(() => {\n if (hasError && errorRef.current) {\n scrollToElement(errorRef.current);\n }\n }, [hasError]);\n\n return (\n <div\n className={classes(['checkout-payment-methods', className])}\n data-testid=\"checkout-payment-methods\"\n >\n {title && (\n <VComponent className=\"checkout-payment-methods__title\" node={title} />\n )}\n\n {!busy && options!.length === 0 && (\n <IllustratedMessage\n data-testid=\"checkout-payment-methods-empty\"\n icon={<Icon source={Wallet} />}\n message={<p>{translations.EmptyState}</p>}\n />\n )}\n\n <div\n className={classes([\n 'checkout-payment-methods__wrapper',\n ['checkout-payment-methods__wrapper--busy', busy],\n ])}\n data-testid=\"checkout-payment-methods-wrapper\"\n >\n <div\n className={classes([\n 'checkout-payment-methods__methods',\n ['checkout-payment-methods--full-width', options!.length % 2 !== 0],\n ])}\n >\n {options?.map((method) => (\n <PaymentOption\n key={method.code}\n UIComponentType={UIComponentType}\n busy={busy}\n code={method.code}\n icon={method.icon}\n selected={selection?.code === method.code}\n title={method.displayLabel ?? true ? method.title : ''}\n onSelectionChange={onSelectionChange}\n />\n ))}\n </div>\n\n {paymentMethodContent && (\n <div className=\"checkout-payment-methods__content\">\n {paymentMethodContent}\n </div>\n )}\n </div>\n\n {hasError && (\n <div\n ref={errorRef}\n className=\"checkout-payment-methods__error\"\n data-testid=\"checkout-payment-methods-alert\"\n >\n <InLineAlert\n heading={error}\n type=\"error\"\n variant=\"primary\"\n onDismiss={onDismissError}\n />\n </div>\n )}\n </div>\n );\n};\n\nexport const PaymentMethods = WithConditionals(\n PaymentMethodsComponent,\n PaymentMethodsSkeleton\n);\n","/********************************************************************\n * ADOBE CONFIDENTIAL\n * __________________\n *\n * Copyright 2024 Adobe\n * All Rights Reserved.\n *\n * NOTICE: All information contained herein is, and remains\n * the property of Adobe and its suppliers, if any. The intellectual\n * and technical concepts contained herein are proprietary to Adobe\n * and its suppliers and are protected by all applicable intellectual\n * property laws, including trade secret and copyright laws.\n * Dissemination of this information or reproduction of this material\n * is strictly forbidden unless prior written permission is obtained\n * from Adobe.\n *******************************************************************/\n\nimport { setPaymentMethod } from '@/checkout/api';\nimport { PaymentMethods as PaymentMethodsComponent } from '@/checkout/components/PaymentMethods/PaymentMethods';\nimport { Cart } from '@/checkout/data/models/cart';\nimport { PaymentMethod } from '@/checkout/data/models/payment-method';\nimport { NegotiableQuote } from '@/checkout/data/models/quote';\nimport {\n getLatestCheckoutUpdate,\n getValue,\n hasPendingUpdates,\n hasShippingAddress,\n isVirtualCart,\n notifyValues,\n state,\n} from '@/checkout/lib';\nimport { TitleProps, UIComponentType } from '@/checkout/types';\nimport { useText } from '@adobe-commerce/elsie/i18n';\nimport { Container, Slot, SlotProps } from '@adobe-commerce/elsie/lib';\nimport { events } from '@adobe-commerce/event-bus';\nimport { HTMLAttributes } from 'preact/compat';\nimport { useCallback, useEffect, useMemo, useState } from 'preact/hooks';\n\nexport interface PaymentMethodRenderCtx {\n cartId: string;\n replaceHTML: (domElement: HTMLElement) => void;\n}\n\nexport interface PaymentMethodConfig {\n displayLabel?: boolean;\n enabled?: boolean;\n icon?: string;\n autoSync?: boolean;\n render?: SlotProps<PaymentMethodRenderCtx>;\n}\n\nexport interface PaymentMethodsSlot {\n [code: string]: PaymentMethodConfig;\n}\n\ninterface CartSyncError {\n method: PaymentMethod;\n error: Error;\n}\n\nexport interface PaymentMethodsProps\n extends HTMLAttributes<HTMLDivElement>,\n TitleProps {\n slots?: {\n Methods?: PaymentMethodsSlot;\n } & TitleProps['slots'];\n UIComponentType?: UIComponentType;\n active?: boolean;\n autoSync?: boolean;\n onCartSyncError?: (error: CartSyncError) => void;\n onSelectionChange?: (method: PaymentMethod) => void;\n}\n\nfunction isValidSelection(\n selection: PaymentMethod | null,\n options: PaymentMethod[]\n) {\n if (!selection) return false;\n return options.some((option) => option.code === selection.code);\n}\n\nfunction isEqual(a: PaymentMethod | null, b: PaymentMethod | null) {\n if (!a || !b) return false;\n return a.code === b.code;\n}\n\nfunction isValidPaymentMethod(method: PaymentMethod | null) {\n if (!method) return false;\n return !!method.code && !!method.title;\n}\n\nexport const PaymentMethods: Container<PaymentMethodsProps> = ({\n UIComponentType = 'ToggleButton',\n active = true,\n autoSync = true,\n displayTitle = true,\n slots,\n onCartSyncError,\n onSelectionChange,\n}) => {\n const [error, setError] = useState<string | null>(null);\n const [isInitialized, setIsInitialized] = useState(false);\n const [selection, setSelection] = useState<PaymentMethod | null>(null);\n const [options, setOptions] = useState<PaymentMethod[]>([]);\n const slotMethods = slots?.Methods;\n const isBusy = hasPendingUpdates.value;\n\n const enabledOptions = options\n .filter((method) => {\n return slotMethods?.[method.code]?.enabled !== false;\n })\n .map((method) => {\n const slotMethod = slotMethods?.[method.code] || {};\n\n return {\n ...method,\n ...slotMethod,\n };\n });\n\n const { cartSyncError, defaultTitle } = useText({\n cartSyncError: 'Checkout.PaymentMethods.cartSyncError',\n defaultTitle: 'Checkout.PaymentMethods.title',\n });\n\n const handleDismissError = useCallback(() => {\n setError(null);\n }, []);\n\n const setUserSelection = useCallback((selection: PaymentMethod | null) => {\n setError(null);\n setSelection(selection);\n notifyValues({ selectedPaymentMethod: selection });\n }, []);\n\n const setUserSelectionOnCart = useCallback(\n async (selection: PaymentMethod, fallback?: PaymentMethod | null) => {\n const canSetUserSelectionOnCart = isVirtualCart() || hasShippingAddress();\n if (!canSetUserSelectionOnCart) return;\n\n const methodConfig = slotMethods?.[selection.code];\n const shouldAutoSync = methodConfig?.autoSync ?? autoSync;\n\n if (!shouldAutoSync) return;\n\n setPaymentMethod({ code: selection.code }).catch((error) => {\n setUserSelection(fallback ?? null);\n onCartSyncError?.({ method: selection, error });\n\n if (!onCartSyncError) {\n setError(cartSyncError);\n }\n });\n },\n [slotMethods, autoSync, setUserSelection, onCartSyncError, cartSyncError]\n );\n\n const handleSelectionChange = useCallback(\n async (selection: PaymentMethod) => {\n const prevSelection = getValue('selectedPaymentMethod');\n\n setUserSelection(selection);\n onSelectionChange?.(selection);\n\n await setUserSelectionOnCart(selection, prevSelection);\n },\n [onSelectionChange, setUserSelection, setUserSelectionOnCart]\n );\n\n const handleCheckoutData = useCallback(\n (data: Cart | NegotiableQuote | null) => {\n const isEmptyCart = !data || data.isEmpty;\n\n if (isEmptyCart) {\n setUserSelection(null);\n setOptions([]);\n return;\n }\n\n const availableOptions = data.availablePaymentMethods ?? [];\n setOptions(availableOptions);\n\n if (availableOptions.length === 0) {\n setUserSelection(null);\n return;\n }\n\n const cartSelection = data.selectedPaymentMethod ?? null;\n const hasCartSelection = isValidPaymentMethod(cartSelection);\n const userSelection = getValue('selectedPaymentMethod');\n const isAvailable = isValidSelection(userSelection, availableOptions);\n const haveSameSelection = isEqual(userSelection, cartSelection);\n\n // User has valid selection that differs from cart\n if (userSelection && isAvailable && !haveSameSelection) {\n setUserSelectionOnCart(userSelection, cartSelection);\n return;\n }\n\n // User has invalid selection but cart has valid selection\n if (\n (!userSelection || !isAvailable) &&\n hasCartSelection &&\n isValidSelection(cartSelection, availableOptions)\n ) {\n setUserSelection(cartSelection);\n return;\n }\n\n // Neither user nor cart has valid selection (or both selections are unavailable)\n if (\n (!userSelection || !isAvailable) &&\n (!hasCartSelection ||\n !isValidSelection(cartSelection, availableOptions))\n ) {\n const newSelection = availableOptions[0];\n setUserSelection(newSelection);\n setUserSelectionOnCart(newSelection);\n }\n },\n [setUserSelection, setUserSelectionOnCart]\n );\n\n useEffect(() => {\n if (!active) return;\n\n const pastUpdate = getLatestCheckoutUpdate();\n\n if (pastUpdate) {\n setIsInitialized(true);\n // When component becomes active, restore key state so handleCheckoutData can work properly\n const userSelection = getValue('selectedPaymentMethod');\n if (userSelection) {\n setSelection(userSelection);\n }\n handleCheckoutData(pastUpdate);\n return;\n }\n\n const onCheckoutInit = events.on(\n 'checkout/initialized',\n (data: Cart | NegotiableQuote | null) => {\n setIsInitialized(true);\n handleCheckoutData(data);\n },\n { eager: true }\n );\n\n return () => {\n onCheckoutInit?.off();\n };\n }, [active, handleCheckoutData]);\n\n useEffect(() => {\n if (!active) return;\n\n const onCheckoutUpdated = events.on(\n 'checkout/updated',\n handleCheckoutData,\n { eager: false }\n );\n\n return () => {\n onCheckoutUpdated?.off();\n };\n }, [active, handleCheckoutData]);\n\n const selectedPaymentMethodHandler = selection\n ? slots?.Methods?.[selection.code]?.render\n : null;\n\n const paymentMethodContent = selectedPaymentMethodHandler ? (\n <Slot\n key={selectedPaymentMethodHandler}\n context={{\n cartId: state.cartId ?? '',\n replaceHTML(domElement: HTMLElement) {\n this.replaceWith(domElement);\n },\n }}\n name=\"PaymentMethodContent\"\n slot={selectedPaymentMethodHandler}\n />\n ) : undefined;\n\n const titleContent = useMemo(() => {\n if (!displayTitle) return undefined;\n\n return (\n <Slot name=\"checkout-payment-methods-title\" slot={slots?.Title}>\n <h2>{defaultTitle}</h2>\n </Slot>\n );\n }, [displayTitle, slots?.Title, defaultTitle]);\n\n return (\n <PaymentMethodsComponent\n UIComponentType={UIComponentType}\n busy={isBusy}\n error={error}\n initialized={isInitialized}\n options={enabledOptions}\n paymentMethodContent={paymentMethodContent}\n selection={selection}\n title={titleContent}\n visible={active}\n onDismissError={handleDismissError}\n onSelectionChange={handleSelectionChange}\n />\n );\n};\n"],"names":["SvgWallet","props","React","PaymentMethodsSkeleton","jsxs","Skeleton","jsx","SkeletonRow","PaymentOption","UIComponentType","busy","code","icon","onSelectionChange","selected","title","commonProps","ToggleButton","Icon","RadioButton","PaymentMethodsComponent","className","error","onDismissError","options","paymentMethodContent","selection","translations","useText","hasError","errorRef","useRef","useEffect","scrollToElement","classes","VComponent","IllustratedMessage","Wallet","method","InLineAlert","PaymentMethods","WithConditionals","isValidSelection","option","isEqual","a","b","isValidPaymentMethod","active","autoSync","displayTitle","slots","onCartSyncError","setError","useState","isInitialized","setIsInitialized","setSelection","setOptions","slotMethods","isBusy","hasPendingUpdates","enabledOptions","_a","slotMethod","cartSyncError","defaultTitle","handleDismissError","useCallback","setUserSelection","notifyValues","setUserSelectionOnCart","fallback","isVirtualCart","hasShippingAddress","methodConfig","setPaymentMethod","handleSelectionChange","prevSelection","getValue","handleCheckoutData","data","availableOptions","cartSelection","hasCartSelection","userSelection","isAvailable","haveSameSelection","newSelection","pastUpdate","getLatestCheckoutUpdate","onCheckoutInit","events","onCheckoutUpdated","selectedPaymentMethodHandler","_b","Slot","state","domElement","titleContent","useMemo"],"mappings":"ysCACA,MAAMA,GAAaC,GAA0BC,EAAM,cAAc,MAAO,CAAE,MAAO,GAAI,OAAQ,GAAI,QAAS,YAAa,KAAM,OAAQ,MAAO,6BAA8B,GAAGD,CAAO,EAAkBC,EAAM,cAAc,OAAQ,CAAE,aAAc,qBAAsB,EAAG,gJAAiJ,OAAQ,eAAgB,YAAa,EAAG,cAAe,QAAS,eAAgB,OAAO,CAAE,EAAmBA,EAAM,cAAc,OAAQ,CAAE,aAAc,qBAAsB,EAAG,wCAAyC,OAAQ,eAAgB,YAAa,EAAG,cAAe,QAAS,eAAgB,OAAS,CAAA,EAAmBA,EAAM,cAAc,OAAQ,CAAE,aAAc,qBAAsB,EAAG,8BAA+B,OAAQ,eAAgB,YAAa,EAAG,cAAe,QAAS,eAAgB,OAAO,CAAE,CAAC,ECmBn5BC,GAA4C,IAErDC,EAACC,GAAS,CAAA,cAAY,2BACpB,SAAA,CAAAC,EAACC,EAAY,CAAA,KAAK,SAAS,QAAQ,UAAU,EAC5CD,EAAAC,EAAA,CAAY,KAAK,SAAS,QAAQ,QAAQ,EAC1CD,EAAAC,EAAA,CAAY,UAAW,GAAM,KAAK,SAAS,EAC3CD,EAAAC,EAAA,CAAY,UAAW,GAAM,KAAK,QAAS,CAAA,CAAA,EAC9C,ECmCEC,GAAuD,CAAC,CAC5D,gBAAAC,EAAkB,eAClB,KAAAC,EACA,KAAAC,EACA,KAAAC,EACA,kBAAAC,EACA,SAAAC,EACA,MAAAC,CACF,IAAM,CACJ,MAAMC,EAAc,CAClB,KAAAN,EACA,UAAW,mCACX,MAAOK,EACP,KAAM,iBACN,SAAU,IAAMF,EAAkB,CAAE,KAAAF,EAAM,MAAAI,EA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AM,CACXU,GAAA,MAAAA,EAAgB,KAClB,CAAA,EACC,CAAC3C,EAAQgC,CAAkB,CAAC,EAE/BhD,EAAU,IAAM,CACd,GAAI,CAACgB,EAAQ,OAEb,MAAM6C,EAAoBD,EAAO,GAC/B,mBACAZ,EACA,CAAE,MAAO,EAAM,CACjB,EAEA,MAAO,IAAM,CACXa,GAAA,MAAAA,EAAmB,KACrB,CAAA,EACC,CAAC7C,EAAQgC,CAAkB,CAAC,EAE/B,MAAMc,EAA+BpE,GACjCqE,GAAAhC,EAAAZ,GAAA,YAAAA,EAAO,UAAP,YAAAY,EAAiBrC,EAAU,QAA3B,YAAAqE,EAAkC,OAClC,KAEEtE,EAAuBqE,EAC3BxF,EAAC0F,EAAA,CAEC,QAAS,CACP,OAAQC,GAAM,QAAU,GACxB,YAAYC,EAAyB,CACnC,KAAK,YAAYA,CAAU,CAAA,CAE/B,EACA,KAAK,uBACL,KAAMJ,CAAA,EARDA,CAAA,EAUL,OAEEK,EAAeC,GAAQ,IAAM,CAC7B,GAAClD,EAGH,OAAA5C,EAAC0F,EAAK,CAAA,KAAK,iCAAiC,KAAM7C,GAAA,YAAAA,EAAO,MACvD,SAAA7C,EAAC,KAAI,CAAA,SAAA4D,CAAa,CAAA,EACpB,GAED,CAAChB,EAAcC,GAAA,YAAAA,EAAO,MAAOe,CAAY,CAAC,EAG3C,OAAA5D,EAACc,GAAA,CACC,gBAAiBX,EACjB,KAAMmD,EACN,MAAAtC,EACA,YAAaiC,EACb,QAASO,EACT,qBAAArC,EACA,UAAAC,EACA,MAAOyE,EACP,QAASnD,EACT,eAAgBmB,EAChB,kBAAmBU,CAAA,CACrB,CAEJ","x_google_ignoreList":[0]}
|
|
1
|
+
{"version":3,"file":"PaymentMethods.js","sources":["../../node_modules/@adobe-commerce/elsie/src/icons/Wallet.svg","/@dropins/storefront-checkout/src/components/PaymentMethods/PaymentMethodsSkeleton.tsx","/@dropins/storefront-checkout/src/components/PaymentMethods/PaymentMethods.tsx","../../node_modules/@adobe-commerce/elsie/src/lib/debounce.ts","/@dropins/storefront-checkout/src/containers/PaymentMethods/handlers.tsx","/@dropins/storefront-checkout/src/containers/PaymentMethods/PaymentMethods.tsx"],"sourcesContent":["import * as React from \"react\";\nconst SvgWallet = (props) => /* @__PURE__ */ React.createElement(\"svg\", { width: 24, height: 24, viewBox: \"0 0 24 24\", fill: \"none\", xmlns: \"http://www.w3.org/2000/svg\", ...props }, /* @__PURE__ */ React.createElement(\"path\", { vectorEffect: \"non-scaling-stroke\", d: \"M17.93 14.8V18.75H5.97C4.75 18.75 3.75 17.97 3.75 17V6.5M3.75 6.5C3.75 5.53 4.74 4.75 5.97 4.75H15.94V8.25H5.97C4.75 8.25 3.75 7.47 3.75 6.5Z\", stroke: \"currentColor\", strokeWidth: 1, strokeLinecap: \"round\", strokeLinejoin: \"round\" }), /* @__PURE__ */ React.createElement(\"path\", { vectorEffect: \"non-scaling-stroke\", d: \"M19.35 11.64H14.04V14.81H19.35V11.64Z\", stroke: \"currentColor\", strokeWidth: 1, strokeLinecap: \"round\", strokeLinejoin: \"round\" }), /* @__PURE__ */ React.createElement(\"path\", { vectorEffect: \"non-scaling-stroke\", d: \"M17.9304 11.64V8.25H15.1504\", stroke: \"currentColor\", strokeWidth: 1, strokeLinecap: \"round\", strokeLinejoin: \"round\" }));\nexport default SvgWallet;\n","/********************************************************************\n * ADOBE CONFIDENTIAL\n * __________________\n *\n * Copyright 2024 Adobe\n * All Rights Reserved.\n *\n * NOTICE: All information contained herein is, and remains\n * the property of Adobe and its suppliers, if any. The intellectual\n * and technical concepts contained herein are proprietary to Adobe\n * and its suppliers and are protected by all applicable intellectual\n * property laws, including trade secret and copyright laws.\n * Dissemination of this information or reproduction of this material\n * is strictly forbidden unless prior written permission is obtained\n * from Adobe.\n *******************************************************************/\n\nimport { Skeleton, SkeletonRow } from '@adobe-commerce/elsie/components';\nimport { FunctionComponent } from 'preact';\n\nexport const PaymentMethodsSkeleton: FunctionComponent = () => {\n return (\n <Skeleton data-testid=\"payment-methods-skeleton\">\n <SkeletonRow size=\"medium\" variant=\"heading\" />\n <SkeletonRow size=\"medium\" variant=\"empty\" />\n <SkeletonRow fullWidth={true} size=\"xlarge\" />\n <SkeletonRow fullWidth={true} size=\"xlarge\" />\n </Skeleton>\n );\n};\n","/********************************************************************\n * ADOBE CONFIDENTIAL\n * __________________\n *\n * Copyright 2024 Adobe\n * All Rights Reserved.\n *\n * NOTICE: All information contained herein is, and remains\n * the property of Adobe and its suppliers, if any. The intellectual\n * and technical concepts contained herein are proprietary to Adobe\n * and its suppliers and are protected by all applicable intellectual\n * property laws, including trade secret and copyright laws.\n * Dissemination of this information or reproduction of this material\n * is strictly forbidden unless prior written permission is obtained\n * from Adobe.\n *******************************************************************/\n\nimport { WithConditionals } from '@/checkout/components/ConditionalWrapper/ConditionalWrapper';\nimport '@/checkout/components/PaymentMethods/PaymentMethods.css';\nimport { PaymentMethodsSkeleton } from '@/checkout/components/PaymentMethods/PaymentMethodsSkeleton';\nimport { PaymentMethodConfig } from '@/checkout/containers';\nimport { PaymentMethod } from '@/checkout/data/models/payment-method';\nimport { scrollToElement } from '@/checkout/lib';\nimport { UIComponentType } from '@/checkout/types';\nimport {\n Icon,\n IllustratedMessage,\n InLineAlert,\n RadioButton,\n ToggleButton,\n} from '@adobe-commerce/elsie/components';\nimport { useText } from '@adobe-commerce/elsie/i18n';\nimport { Wallet } from '@adobe-commerce/elsie/icons';\nimport { classes, VComponent } from '@adobe-commerce/elsie/lib';\nimport { FunctionComponent, VNode } from 'preact';\nimport { HTMLAttributes, useEffect, useRef } from 'preact/compat';\n\ninterface ExtendedPaymentMethod extends PaymentMethodConfig, PaymentMethod {}\n\nexport interface PaymentMethodsProps\n extends Omit<HTMLAttributes<HTMLDivElement>, 'title'> {\n error?: string | null;\n busy?: boolean;\n onDismissError?: () => void;\n onSelectionChange?: (value: PaymentMethod) => void;\n options?: ExtendedPaymentMethod[];\n paymentMethodContent?: VNode;\n selection: PaymentMethod | null;\n title?: VNode;\n UIComponentType?: UIComponentType;\n}\n\ninterface PaymentOptionProps {\n UIComponentType?: UIComponentType;\n busy?: boolean;\n code: string;\n icon?: string;\n onSelectionChange: (value: PaymentMethod) => void;\n selected: boolean;\n title: string;\n}\n\nconst PaymentOption: FunctionComponent<PaymentOptionProps> = ({\n UIComponentType = 'ToggleButton',\n busy,\n code,\n icon,\n onSelectionChange,\n selected,\n title,\n}) => {\n const commonProps = {\n busy,\n className: 'checkout-payment-methods__method',\n label: title,\n name: 'payment-method',\n onChange: () => onSelectionChange({ code, title }),\n value: code,\n };\n\n return UIComponentType === 'ToggleButton' ? (\n <ToggleButton\n {...commonProps}\n // @ts-ignore\n icon={icon ? <Icon source={icon} /> : undefined}\n selected={selected}\n />\n ) : (\n <RadioButton {...commonProps} checked={selected} icon={icon ?? undefined} />\n );\n};\n\nconst PaymentMethodsComponent: FunctionComponent<PaymentMethodsProps> = ({\n className,\n error = null,\n busy = false,\n onDismissError,\n onSelectionChange = () => {},\n options,\n paymentMethodContent,\n selection,\n title,\n UIComponentType,\n}) => {\n const translations = useText({\n EmptyState: 'Checkout.PaymentMethods.emptyState',\n });\n\n const hasError = error !== null;\n const errorRef = useRef<HTMLDivElement>(null);\n\n useEffect(() => {\n if (hasError && errorRef.current) {\n scrollToElement(errorRef.current);\n }\n }, [hasError]);\n\n return (\n <div\n className={classes(['checkout-payment-methods', className])}\n data-testid=\"checkout-payment-methods\"\n >\n {title && (\n <VComponent className=\"checkout-payment-methods__title\" node={title} />\n )}\n\n {!busy && options!.length === 0 && (\n <IllustratedMessage\n data-testid=\"checkout-payment-methods-empty\"\n icon={<Icon source={Wallet} />}\n message={<p>{translations.EmptyState}</p>}\n />\n )}\n\n <div\n className={classes([\n 'checkout-payment-methods__wrapper',\n ['checkout-payment-methods__wrapper--busy', busy],\n ])}\n data-testid=\"checkout-payment-methods-wrapper\"\n >\n <div\n className={classes([\n 'checkout-payment-methods__methods',\n ['checkout-payment-methods--full-width', options!.length % 2 !== 0],\n ])}\n >\n {options?.map((method) => (\n <PaymentOption\n key={method.code}\n UIComponentType={UIComponentType}\n busy={busy}\n code={method.code}\n icon={method.icon}\n selected={selection?.code === method.code}\n title={method.displayLabel ?? true ? method.title : ''}\n onSelectionChange={onSelectionChange}\n />\n ))}\n </div>\n\n {paymentMethodContent && (\n <div className=\"checkout-payment-methods__content\">\n {paymentMethodContent}\n </div>\n )}\n </div>\n\n {hasError && (\n <div\n ref={errorRef}\n className=\"checkout-payment-methods__error\"\n data-testid=\"checkout-payment-methods-alert\"\n >\n <InLineAlert\n heading={error}\n type=\"error\"\n variant=\"primary\"\n onDismiss={onDismissError}\n />\n </div>\n )}\n </div>\n );\n};\n\nexport const PaymentMethods = WithConditionals(\n PaymentMethodsComponent,\n PaymentMethodsSkeleton\n);\n","/********************************************************************\n * Copyright 2024 Adobe\n * All Rights Reserved.\n *\n * NOTICE: Adobe permits you to use, modify, and distribute this \n * file in accordance with the terms of the Adobe license agreement \n * accompanying it. \n *******************************************************************/\n\nexport const debounce = (fn: Function, ms: number) => {\n let timeoutId: ReturnType<typeof setTimeout>;\n return function (this: any, ...args: any[]) {\n clearTimeout(timeoutId);\n timeoutId = setTimeout(() => fn.apply(this, args), ms);\n };\n};\n","/********************************************************************\n * ADOBE CONFIDENTIAL\n * __________________\n *\n * Copyright 2025 Adobe\n * All Rights Reserved.\n *\n * NOTICE: All information contained herein is, and remains\n * the property of Adobe and its suppliers, if any. The intellectual\n * and technical concepts contained herein are proprietary to Adobe\n * and its suppliers and are protected by all applicable intellectual\n * property laws, including trade secret and copyright laws.\n * Dissemination of this information or reproduction of this material\n * is strictly forbidden unless prior written permission is obtained\n * from Adobe.\n *******************************************************************/\n\nimport { setPaymentMethod } from '@/checkout/api/index';\nimport {\n PaymentMethodConfig,\n PaymentOnAccount,\n PurchaseOrder,\n} from '@/checkout/containers';\nimport { render as Checkout } from '@/checkout/render/render';\nimport { debounce } from '@adobe-commerce/elsie/lib/debounce';\nimport { Container } from '@adobe-commerce/elsie/lib/types';\n\nconst createOrderRefHandler = (\n Container: Container<{\n initialReferenceNumber: string;\n onReferenceNumberChange: (refNumber: string) => void;\n }>,\n code: string\n): PaymentMethodConfig => ({\n enabled: true,\n autoSync: false,\n render: (ctx) => {\n const initialReferenceNumber = String(\n ctx.additionalData?.purchase_order_number ?? ''\n );\n const $wrapper = document.createElement('div');\n\n const onReferenceNumberChange = debounce((refNumber: string) => {\n setPaymentMethod({\n code,\n purchase_order_number: refNumber,\n }).catch(console.error);\n }, 1000);\n\n Checkout.render(Container, {\n initialReferenceNumber,\n onReferenceNumberChange,\n })($wrapper);\n\n ctx.replaceHTML($wrapper);\n },\n});\n\nexport enum PaymentMethods {\n PaymentOnAccount = 'companycredit',\n PurchaseOrder = 'purchaseorder',\n}\n\nexport const defaultHandlers = {\n [PaymentMethods.PaymentOnAccount]: createOrderRefHandler(\n PaymentOnAccount,\n PaymentMethods.PaymentOnAccount\n ),\n [PaymentMethods.PurchaseOrder]: createOrderRefHandler(\n PurchaseOrder,\n PaymentMethods.PurchaseOrder\n ),\n};\n","/********************************************************************\n * ADOBE CONFIDENTIAL\n * __________________\n *\n * Copyright 2024 Adobe\n * All Rights Reserved.\n *\n * NOTICE: All information contained herein is, and remains\n * the property of Adobe and its suppliers, if any. The intellectual\n * and technical concepts contained herein are proprietary to Adobe\n * and its suppliers and are protected by all applicable intellectual\n * property laws, including trade secret and copyright laws.\n * Dissemination of this information or reproduction of this material\n * is strictly forbidden unless prior written permission is obtained\n * from Adobe.\n *******************************************************************/\n\nimport { setPaymentMethod } from '@/checkout/api';\nimport { PaymentMethods as PaymentMethodsComponent } from '@/checkout/components/PaymentMethods/PaymentMethods';\nimport { Cart } from '@/checkout/data/models/cart';\nimport {\n AdditionalData,\n PaymentMethod,\n} from '@/checkout/data/models/payment-method';\nimport { NegotiableQuote } from '@/checkout/data/models/quote';\nimport {\n getLatestCheckoutUpdate,\n getValue,\n hasPendingUpdates,\n hasShippingAddress,\n isVirtualCart,\n notifyValues,\n state,\n} from '@/checkout/lib';\nimport { TitleProps, UIComponentType } from '@/checkout/types';\nimport { useText } from '@adobe-commerce/elsie/i18n';\nimport {\n Container,\n deepmerge,\n Slot,\n SlotProps,\n} from '@adobe-commerce/elsie/lib';\nimport { events } from '@adobe-commerce/event-bus';\nimport { HTMLAttributes } from 'preact/compat';\nimport { useCallback, useEffect, useMemo, useState } from 'preact/hooks';\nimport { defaultHandlers } from './handlers';\n\ninterface RenderContext {\n additionalData?: AdditionalData;\n cartId: string;\n replaceHTML: (domElement: HTMLElement) => void;\n setAdditionalData: (data: AdditionalData) => void;\n}\n\nexport interface PaymentMethodConfig {\n autoSync?: boolean;\n displayLabel?: boolean;\n enabled?: boolean;\n icon?: string;\n render?: SlotProps<RenderContext>;\n}\n\nexport interface PaymentMethodHandlers {\n [code: string]: PaymentMethodConfig;\n}\n\ninterface CartSyncError {\n method: PaymentMethod;\n error: Error;\n}\n\nexport interface PaymentMethodsProps\n extends HTMLAttributes<HTMLDivElement>,\n TitleProps {\n slots?: {\n Methods?: PaymentMethodHandlers;\n } & TitleProps['slots'];\n UIComponentType?: UIComponentType;\n active?: boolean;\n autoSync?: boolean;\n onCartSyncError?: (error: CartSyncError) => void;\n onSelectionChange?: (method: PaymentMethod) => void;\n}\n\nfunction isValidSelection(\n selection: PaymentMethod | null,\n options: PaymentMethod[]\n) {\n if (!selection) return false;\n return options.some((option) => option.code === selection.code);\n}\n\nfunction isEqual(a: PaymentMethod | null, b: PaymentMethod | null) {\n if (!a || !b) return false;\n return a.code === b.code;\n}\n\nfunction isValidPaymentMethod(method: PaymentMethod | null) {\n if (!method) return false;\n return !!method.code && !!method.title;\n}\n\nexport const PaymentMethods: Container<PaymentMethodsProps> = ({\n UIComponentType = 'ToggleButton',\n active = true,\n autoSync = true,\n displayTitle = true,\n slots,\n onCartSyncError,\n onSelectionChange,\n}) => {\n const [error, setError] = useState<string | null>(null);\n const [isInitialized, setIsInitialized] = useState(false);\n const [selection, setSelection] = useState<PaymentMethod | null>(null);\n const [options, setOptions] = useState<PaymentMethod[]>([]);\n const isBusy = hasPendingUpdates.value;\n\n const availableHandlers = useMemo(() => {\n const customHandlers = slots?.Methods ?? {};\n return deepmerge(defaultHandlers, customHandlers);\n }, [slots?.Methods]);\n\n const enabledOptions = options\n .filter((method) => {\n return availableHandlers?.[method.code]?.enabled !== false;\n })\n .map((method) => {\n const slotMethod = availableHandlers?.[method.code] || {};\n\n return {\n ...method,\n ...slotMethod,\n };\n });\n\n const { cartSyncError, defaultTitle } = useText({\n cartSyncError: 'Checkout.PaymentMethods.cartSyncError',\n defaultTitle: 'Checkout.PaymentMethods.title',\n });\n\n const setAdditionalData = useCallback((additionalData: AdditionalData) => {\n setSelection((prev) => {\n if (!prev) return prev;\n return { ...prev, additionalData };\n });\n\n const currentSelection = getValue('selectedPaymentMethod');\n\n if (!currentSelection) return;\n\n notifyValues({\n selectedPaymentMethod: {\n ...currentSelection,\n additionalData,\n },\n });\n }, []);\n\n const handleDismissError = useCallback(() => {\n setError(null);\n }, []);\n\n const setUserSelection = useCallback((selection: PaymentMethod | null) => {\n setError(null);\n setSelection(selection);\n notifyValues({ selectedPaymentMethod: selection });\n }, []);\n\n const setUserSelectionOnCart = useCallback(\n async (selection: PaymentMethod, fallback?: PaymentMethod | null) => {\n const canSetUserSelectionOnCart = isVirtualCart() || hasShippingAddress();\n if (!canSetUserSelectionOnCart) return;\n\n const methodConfig = availableHandlers?.[selection.code];\n const shouldAutoSync = methodConfig?.autoSync ?? autoSync;\n\n if (!shouldAutoSync) return;\n\n setPaymentMethod({ code: selection.code }).catch((error) => {\n setUserSelection(fallback ?? null);\n onCartSyncError?.({ method: selection, error });\n\n if (!onCartSyncError) {\n setError(cartSyncError);\n }\n });\n },\n [\n availableHandlers,\n autoSync,\n setUserSelection,\n onCartSyncError,\n cartSyncError,\n ]\n );\n\n const handleSelectionChange = useCallback(\n async (selection: PaymentMethod) => {\n const prevSelection = getValue('selectedPaymentMethod');\n\n setUserSelection(selection);\n onSelectionChange?.(selection);\n\n await setUserSelectionOnCart(selection, prevSelection);\n },\n [onSelectionChange, setUserSelection, setUserSelectionOnCart]\n );\n\n const handleCheckoutData = useCallback(\n (data: Cart | NegotiableQuote | null) => {\n const isEmptyCart = !data || data.isEmpty;\n\n if (isEmptyCart) {\n setUserSelection(null);\n setOptions([]);\n return;\n }\n\n const availableOptions = data.availablePaymentMethods ?? [];\n setOptions(availableOptions);\n\n if (availableOptions.length === 0) {\n setUserSelection(null);\n return;\n }\n\n const cartSelection = data.selectedPaymentMethod ?? null;\n const hasCartSelection = isValidPaymentMethod(cartSelection);\n const userSelection = getValue('selectedPaymentMethod');\n const isAvailable = isValidSelection(userSelection, availableOptions);\n const haveSameSelection = isEqual(userSelection, cartSelection);\n\n // User has valid selection that differs from cart\n if (userSelection && isAvailable && !haveSameSelection) {\n setUserSelectionOnCart(userSelection, cartSelection);\n return;\n }\n\n // User has invalid selection but cart has valid selection\n if (\n (!userSelection || !isAvailable) &&\n hasCartSelection &&\n isValidSelection(cartSelection, availableOptions)\n ) {\n setUserSelection(cartSelection);\n return;\n }\n\n // Neither user nor cart has valid selection (or both selections are unavailable)\n if (\n (!userSelection || !isAvailable) &&\n (!hasCartSelection ||\n !isValidSelection(cartSelection, availableOptions))\n ) {\n const newSelection = availableOptions[0];\n setUserSelection(newSelection);\n setUserSelectionOnCart(newSelection);\n }\n },\n [setUserSelection, setUserSelectionOnCart]\n );\n\n useEffect(() => {\n if (!active) return;\n\n const pastUpdate = getLatestCheckoutUpdate();\n\n if (pastUpdate) {\n setIsInitialized(true);\n // When component becomes active, restore key state so handleCheckoutData can work properly\n const userSelection = getValue('selectedPaymentMethod');\n if (userSelection) {\n setSelection(userSelection);\n }\n handleCheckoutData(pastUpdate);\n return;\n }\n\n const onCheckoutInit = events.on(\n 'checkout/initialized',\n (data: Cart | NegotiableQuote | null) => {\n setIsInitialized(true);\n handleCheckoutData(data);\n },\n { eager: true }\n );\n\n return () => {\n onCheckoutInit?.off();\n };\n }, [active, handleCheckoutData]);\n\n useEffect(() => {\n if (!active) return;\n\n const onCheckoutUpdated = events.on(\n 'checkout/updated',\n handleCheckoutData,\n { eager: false }\n );\n\n return () => {\n onCheckoutUpdated?.off();\n };\n }, [active, handleCheckoutData]);\n\n const selectionConfig = availableHandlers[selection?.code || ''];\n\n const paymentMethodContent = selectionConfig ? (\n <Slot\n key={selection?.code}\n context={{\n additionalData: selection?.additionalData,\n cartId: state.cartId ?? '',\n replaceHTML(domElement: HTMLElement) {\n this.replaceWith(domElement);\n },\n setAdditionalData,\n }}\n name=\"PaymentMethodContent\"\n slot={selectionConfig.render}\n />\n ) : undefined;\n\n const titleContent = useMemo(() => {\n if (!displayTitle) return undefined;\n\n return (\n <Slot name=\"checkout-payment-methods-title\" slot={slots?.Title}>\n <h2>{defaultTitle}</h2>\n </Slot>\n );\n }, [displayTitle, slots?.Title, defaultTitle]);\n\n return (\n <PaymentMethodsComponent\n UIComponentType={UIComponentType}\n busy={isBusy}\n error={error}\n initialized={isInitialized}\n options={enabledOptions}\n paymentMethodContent={paymentMethodContent}\n selection={selection}\n title={titleContent}\n visible={active}\n onDismissError={handleDismissError}\n onSelectionChange={handleSelectionChange}\n />\n );\n};\n"],"names":["SvgWallet","props","React","PaymentMethodsSkeleton","jsxs","Skeleton","jsx","SkeletonRow","PaymentOption","UIComponentType","busy","code","icon","onSelectionChange","selected","title","commonProps","ToggleButton","Icon","RadioButton","PaymentMethodsComponent","className","error","onDismissError","options","paymentMethodContent","selection","translations","useText","hasError","errorRef","useRef","useEffect","scrollToElement","classes","VComponent","IllustratedMessage","Wallet","method","InLineAlert","PaymentMethods","WithConditionals","debounce","fn","ms","timeoutId","args","createOrderRefHandler","Container","ctx","initialReferenceNumber","_a","$wrapper","onReferenceNumberChange","refNumber","setPaymentMethod","Checkout","defaultHandlers","PaymentOnAccount","PurchaseOrder","isValidSelection","option","isEqual","a","b","isValidPaymentMethod","active","autoSync","displayTitle","slots","onCartSyncError","setError","useState","isInitialized","setIsInitialized","setSelection","setOptions","isBusy","hasPendingUpdates","availableHandlers","useMemo","customHandlers","deepmerge","enabledOptions","slotMethod","cartSyncError","defaultTitle","setAdditionalData","useCallback","additionalData","prev","currentSelection","getValue","notifyValues","handleDismissError","setUserSelection","setUserSelectionOnCart","fallback","isVirtualCart","hasShippingAddress","methodConfig","handleSelectionChange","prevSelection","handleCheckoutData","data","availableOptions","cartSelection","hasCartSelection","userSelection","isAvailable","haveSameSelection","newSelection","pastUpdate","getLatestCheckoutUpdate","onCheckoutInit","events","onCheckoutUpdated","selectionConfig","Slot","state","domElement","titleContent"],"mappings":"2mDACA,MAAMA,GAAaC,GAA0BC,EAAM,cAAc,MAAO,CAAE,MAAO,GAAI,OAAQ,GAAI,QAAS,YAAa,KAAM,OAAQ,MAAO,6BAA8B,GAAGD,CAAO,EAAkBC,EAAM,cAAc,OAAQ,CAAE,aAAc,qBAAsB,EAAG,gJAAiJ,OAAQ,eAAgB,YAAa,EAAG,cAAe,QAAS,eAAgB,OAAO,CAAE,EAAmBA,EAAM,cAAc,OAAQ,CAAE,aAAc,qBAAsB,EAAG,wCAAyC,OAAQ,eAAgB,YAAa,EAAG,cAAe,QAAS,eAAgB,OAAS,CAAA,EAAmBA,EAAM,cAAc,OAAQ,CAAE,aAAc,qBAAsB,EAAG,8BAA+B,OAAQ,eAAgB,YAAa,EAAG,cAAe,QAAS,eAAgB,OAAO,CAAE,CAAC,ECmBn5BC,GAA4C,IAErDC,EAACC,GAAS,CAAA,cAAY,2BACpB,SAAA,CAAAC,EAACC,EAAY,CAAA,KAAK,SAAS,QAAQ,UAAU,EAC5CD,EAAAC,EAAA,CAAY,KAAK,SAAS,QAAQ,QAAQ,EAC1CD,EAAAC,EAAA,CAAY,UAAW,GAAM,KAAK,SAAS,EAC3CD,EAAAC,EAAA,CAAY,UAAW,GAAM,KAAK,QAAS,CAAA,CAAA,EAC9C,ECmCEC,GAAuD,CAAC,CAC5D,gBAAAC,EAAkB,eA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AChB,EAEA,MAAO,IAAM,CACXU,GAAA,MAAAA,EAAgB,KAClB,CAAA,EACC,CAAChD,EAAQqC,CAAkB,CAAC,EAE/BvE,EAAU,IAAM,CACd,GAAI,CAACkC,EAAQ,OAEb,MAAMkD,EAAoBD,EAAO,GAC/B,mBACAZ,EACA,CAAE,MAAO,EAAM,CACjB,EAEA,MAAO,IAAM,CACXa,GAAA,MAAAA,EAAmB,KACrB,CAAA,EACC,CAAClD,EAAQqC,CAAkB,CAAC,EAE/B,MAAMc,EAAkBtC,GAAkBrD,GAAA,YAAAA,EAAW,OAAQ,EAAE,EAEzDD,EAAuB4F,EAC3B/G,EAACgH,EAAA,CAEC,QAAS,CACP,eAAgB5F,GAAA,YAAAA,EAAW,eAC3B,OAAQ6F,GAAM,QAAU,GACxB,YAAYC,EAAyB,CACnC,KAAK,YAAYA,CAAU,CAC7B,EACA,kBAAAjC,CACF,EACA,KAAK,uBACL,KAAM8B,EAAgB,MAAA,EAVjB3F,GAAA,YAAAA,EAAW,IAAA,EAYhB,OAEE+F,GAAezC,EAAQ,IAAM,CAC7B,GAACZ,EAGH,OAAA9D,EAACgH,EAAK,CAAA,KAAK,iCAAiC,KAAMjD,GAAA,YAAAA,EAAO,MACvD,SAAA/D,EAAC,KAAI,CAAA,SAAAgF,CAAa,CAAA,EACpB,GAED,CAAClB,EAAcC,GAAA,YAAAA,EAAO,MAAOiB,CAAY,CAAC,EAG3C,OAAAhF,EAACc,GAAA,CACC,gBAAiBX,EACjB,KAAMoE,EACN,MAAAvD,EACA,YAAamD,EACb,QAASU,EACT,qBAAA1D,EACA,UAAAC,EACA,MAAO+F,GACP,QAASvD,EACT,eAAgB4B,EAChB,kBAAmBO,CAAA,CACrB,CAEJ","x_google_ignoreList":[0,3]}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { HTMLAttributes } from 'preact/compat';
|
|
2
|
+
import { Container } from '@dropins/tools/types/elsie/src/lib';
|
|
3
|
+
|
|
4
|
+
export interface PaymentOnAccountProps extends HTMLAttributes<HTMLDivElement> {
|
|
5
|
+
initialReferenceNumber?: string;
|
|
6
|
+
onReferenceNumberChange?: (referenceNumber: string) => void;
|
|
7
|
+
onReferenceNumberBlur?: (referenceNumber: string) => void;
|
|
8
|
+
}
|
|
9
|
+
export declare const PaymentOnAccount: Container<PaymentOnAccountProps>;
|
|
10
|
+
//# sourceMappingURL=PaymentOnAccount.d.ts.map
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/********************************************************************
|
|
2
|
+
* Copyright 2025 Adobe
|
|
3
|
+
* All Rights Reserved.
|
|
4
|
+
*
|
|
5
|
+
* NOTICE: Adobe permits you to use, modify, and distribute this
|
|
6
|
+
* file in accordance with the terms of the Adobe license agreement
|
|
7
|
+
* accompanying it.
|
|
8
|
+
*******************************************************************/
|
|
9
|
+
export * from './PaymentOnAccount';
|
|
10
|
+
export { PaymentOnAccount as default } from './PaymentOnAccount';
|
|
11
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
/*! Copyright 2025 Adobe
|
|
2
|
+
All Rights Reserved. */
|
|
3
|
+
import{P as d,P as l}from"../chunks/PaymentOnAccount2.js";import"@dropins/tools/preact-jsx-runtime.js";import"@dropins/tools/preact-compat.js";import"@dropins/tools/components.js";import"@dropins/tools/lib.js";/* empty css */import"../chunks/ConditionalWrapper.js";import"@dropins/tools/i18n.js";import"../chunks/fetch-graphql.js";import"@dropins/tools/event-bus.js";import"@dropins/tools/signals.js";import"@dropins/tools/fetch-graphql.js";import"../chunks/getCompanyCredit.js";export{d as PaymentOnAccount,l as default};
|
|
4
|
+
//# sourceMappingURL=PaymentOnAccount.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PaymentOnAccount.js","sources":[],"sourcesContent":[],"names":[],"mappings":""}
|
package/containers/PlaceOrder.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
/*! Copyright 2025 Adobe
|
|
2
2
|
All Rights Reserved. */
|
|
3
|
-
import{jsxs as
|
|
3
|
+
import{jsxs as R,jsx as s}from"@dropins/tools/preact-jsx-runtime.js";import{W as U}from"../chunks/ConditionalWrapper.js";/* empty css */import{Skeleton as W,SkeletonRow as E,Button as _}from"@dropins/tools/components.js";import{classes as B,Slot as j}from"@dropins/tools/lib.js";import{h as q,s as y}from"../chunks/fetch-graphql.js";import{c as w,E as b}from"../chunks/classifiers.js";import{events as u}from"@dropins/tools/event-bus.js";import{a as K}from"../chunks/events2.js";import{g}from"../chunks/values.js";import{useState as S,useCallback as m,useEffect as f}from"@dropins/tools/preact-hooks.js";import{useText as M}from"@dropins/tools/i18n.js";import"@dropins/tools/signals.js";import"@dropins/tools/fetch-graphql.js";function Q(n){const r=w.find(o=>o.matches(n));return r?r.code:b.UNKNOWN_ERROR}const T=()=>R(W,{"data-testid":"place-order-skeleton",children:[s(E,{size:"small",variant:"empty"}),s(E,{size:"small"})]}),v=({children:n,className:r,disabled:o=!1,onClick:a})=>s("div",{className:B(["checkout-place-order",r]),children:s(_,{className:"checkout-place-order__button","data-testid":"place-order-button",disabled:o,size:"medium",type:"button",variant:"primary",onClick:a,children:n},"placeOrder")}),H=U(v,T),oe=({disabled:n=!1,active:r=!0,handleValidation:o,handlePlaceOrder:a,slots:d,...x})=>{var O;const[z,p]=S(!1),[I,h]=S(!1),N=q.value,l=M({CheckoutUnexpectedError:"Checkout.ServerError.unexpected",placeOrderButton:"Checkout.PlaceOrder.button"}),k=m(e=>{const t=Q(e),i=t===b.UNKNOWN_ERROR?l.CheckoutUnexpectedError:e.message;u.emit("checkout/error",{message:i,code:t})},[l]),P=m(async()=>{var e;try{if(o&&!o())return;await a({cartId:y.cartId,quoteId:y.quoteId,code:((e=g("selectedPaymentMethod"))==null?void 0:e.code)??""})}catch(t){k(t)}},[o,a,k]),c=m(e=>{(!e||"isEmpty"in e&&e.isEmpty)&&h(!1)},[]);return f(()=>{if(r===!1)return;const e=u.on("cart/initialized",t=>{const i=(t==null?void 0:t.items)||[];h(i.some(C=>C.outOfStock||C.insufficientQuantity))},{eager:!0});return()=>{e==null||e.off()}},[r]),f(()=>{if(!r)return;const e=K();if(e){p(!0),c(e);return}const t=u.on("checkout/initialized",i=>{p(!0),c(i)},{eager:!0});return()=>{t==null||t.off()}},[r,c]),f(()=>{if(!r)return;const e=u.on("checkout/updated",t=>{c(t)},{eager:!1});return()=>{e==null||e.off()}},[r,c]),s(H,{...x,disabled:n||I||N,initialized:z,visible:r,onClick:P,children:s(j,{context:{code:((O=g("selectedPaymentMethod"))==null?void 0:O.code)??""},name:"Content",slot:d==null?void 0:d.Content,children:l.placeOrderButton})})};export{oe as PlaceOrder,oe as default};
|
|
4
4
|
//# sourceMappingURL=PlaceOrder.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PlaceOrder.js","sources":["/@dropins/storefront-checkout/src/lib/errors/classifiers.ts","/@dropins/storefront-checkout/src/lib/errors/mapErrorToCode.ts","/@dropins/storefront-checkout/src/components/PlaceOrder/PlaceOrderSkeleton.tsx","/@dropins/storefront-checkout/src/components/PlaceOrder/PlaceOrder.tsx","/@dropins/storefront-checkout/src/containers/PlaceOrder/PlaceOrder.tsx"],"sourcesContent":["/********************************************************************\n * ADOBE CONFIDENTIAL\n * __________________\n *\n * Copyright 2025 Adobe\n * All Rights Reserved.\n *\n * NOTICE: All information contained herein is, and remains\n * the property of Adobe and its suppliers, if any. The intellectual\n * and technical concepts contained herein are proprietary to Adobe\n * and its suppliers and are protected by all applicable intellectual\n * property laws, including trade secret and copyright laws.\n * Dissemination of this information or reproduction of this material\n * is strictly forbidden unless prior written permission is obtained\n * from Adobe.\n *******************************************************************/\n\nimport { InvalidInput, Unauthenticated } from './customErrors';\n\nexport type ErrorCode = string;\n\nexport enum ErrorCodes {\n INVALID_INPUT = 'INVALID_INPUT',\n SERVER_ERROR = 'SERVER_ERROR',\n UNAUTHENTICATED = 'UNAUTHENTICATED',\n UNKNOWN_ERROR = 'UNKNOWN_ERROR',\n}\n\nconst KNOWN_SERVER_ERRORS = ['PlaceOrderError'];\n\nexport interface ErrorClassifier {\n /**\n * The specific code to return if this classifier matches.\n */\n code: ErrorCode;\n /**\n * A function that returns `true` if it recognizes the error.\n * It must safely handle `unknown` inputs.\n */\n matches: (error: unknown) => boolean;\n}\n\n// Array of all known error classifiers.\n// The order is important! The first one to match will be used.\nexport const classifiers: ErrorClassifier[] = [\n {\n code: ErrorCodes.INVALID_INPUT,\n matches: (error: unknown): boolean => {\n return error instanceof InvalidInput;\n },\n },\n {\n code: ErrorCodes.UNAUTHENTICATED,\n matches: (error: unknown): boolean => {\n return error instanceof Unauthenticated;\n },\n },\n {\n code: ErrorCodes.SERVER_ERROR,\n matches: (error: unknown): boolean => {\n if (!error || typeof error !== 'object' || !('name' in error)) {\n return false;\n }\n\n return KNOWN_SERVER_ERRORS.includes((error as { name: string }).name);\n },\n },\n];\n","/********************************************************************\n * ADOBE CONFIDENTIAL\n * __________________\n *\n * Copyright 2025 Adobe\n * All Rights Reserved.\n *\n * NOTICE: All information contained herein is, and remains\n * the property of Adobe and its suppliers, if any. The intellectual\n * and technical concepts contained herein are proprietary to Adobe\n * and its suppliers and are protected by all applicable intellectual\n * property laws, including trade secret and copyright laws.\n * Dissemination of this information or reproduction of this material\n * is strictly forbidden unless prior written permission is obtained\n * from Adobe.\n *******************************************************************/\n\nimport {\n classifiers,\n ErrorCode,\n ErrorCodes,\n} from '@/checkout/lib/errors/classifiers';\n\nexport function mapErrorToCode(error: unknown): ErrorCode {\n const matchingClassifier = classifiers.find((classifier) =>\n classifier.matches(error)\n );\n\n if (matchingClassifier) {\n return matchingClassifier.code;\n }\n\n return ErrorCodes.UNKNOWN_ERROR;\n}\n","/********************************************************************\n * ADOBE CONFIDENTIAL\n * __________________\n *\n * Copyright 2024 Adobe\n * All Rights Reserved.\n *\n * NOTICE: All information contained herein is, and remains\n * the property of Adobe and its suppliers, if any. The intellectual\n * and technical concepts contained herein are proprietary to Adobe\n * and its suppliers and are protected by all applicable intellectual\n * property laws, including trade secret and copyright laws.\n * Dissemination of this information or reproduction of this material\n * is strictly forbidden unless prior written permission is obtained\n * from Adobe.\n *******************************************************************/\n\nimport { Skeleton, SkeletonRow } from '@adobe-commerce/elsie/components';\nimport { FunctionComponent } from 'preact';\n\nexport const PlaceOrderSkeleton: FunctionComponent = () => {\n return (\n <Skeleton data-testid=\"place-order-skeleton\">\n <SkeletonRow size=\"small\" variant=\"empty\" />\n <SkeletonRow size=\"small\" />\n </Skeleton>\n );\n};\n","/********************************************************************\n * ADOBE CONFIDENTIAL\n * __________________\n *\n * Copyright 2024 Adobe\n * All Rights Reserved.\n *\n * NOTICE: All information contained herein is, and remains\n * the property of Adobe and its suppliers, if any. The intellectual\n * and technical concepts contained herein are proprietary to Adobe\n * and its suppliers and are protected by all applicable intellectual\n * property laws, including trade secret and copyright laws.\n * Dissemination of this information or reproduction of this material\n * is strictly forbidden unless prior written permission is obtained\n * from Adobe.\n *******************************************************************/\n\nimport { WithConditionals } from '@/checkout/components/ConditionalWrapper/index';\nimport '@/checkout/components/PlaceOrder/PlaceOrder.css';\nimport { PlaceOrderSkeleton } from '@/checkout/components/PlaceOrder/PlaceOrderSkeleton';\nimport { Button } from '@adobe-commerce/elsie/components';\nimport { classes } from '@adobe-commerce/elsie/lib';\nimport { FunctionComponent } from 'preact';\nimport { HTMLAttributes } from 'preact/compat';\n\nexport interface PlaceOrderProps extends HTMLAttributes<HTMLDivElement> {\n disabled?: boolean;\n onClick: (event: Event) => Promise<void>;\n}\n\nconst PlaceOrderComponent: FunctionComponent<PlaceOrderProps> = ({\n children,\n className,\n disabled = false,\n onClick,\n}) => {\n return (\n <div className={classes(['checkout-place-order', className])}>\n <Button\n key=\"placeOrder\"\n className=\"checkout-place-order__button\"\n data-testid=\"place-order-button\"\n disabled={disabled}\n size=\"medium\"\n type=\"button\"\n variant=\"primary\"\n onClick={onClick}\n >\n {children}\n </Button>\n </div>\n );\n};\n\nexport const PlaceOrder = WithConditionals(\n PlaceOrderComponent,\n PlaceOrderSkeleton\n);\n","/********************************************************************\n * ADOBE CONFIDENTIAL\n * __________________\n *\n * Copyright 2024 Adobe\n * All Rights Reserved.\n *\n * NOTICE: All information contained herein is, and remains\n * the property of Adobe and its suppliers, if any. The intellectual\n * and technical concepts contained herein are proprietary to Adobe\n * and its suppliers and are protected by all applicable intellectual\n * property laws, including trade secret and copyright laws.\n * Dissemination of this information or reproduction of this material\n * is strictly forbidden unless prior written permission is obtained\n * from Adobe.\n *******************************************************************/\n\nimport { PlaceOrder as PlaceOrderComponent } from '@/checkout/components/PlaceOrder/PlaceOrder';\nimport { Cart, NegotiableQuote } from '@/checkout/data/models';\nimport {\n getLatestCheckoutUpdate,\n getValue,\n hasPendingUpdates,\n state,\n} from '@/checkout/lib';\nimport { ErrorCodes, mapErrorToCode } from '@/checkout/lib/errors';\nimport { Item as ItemModel } from '@/checkout/types';\nimport { useText } from '@adobe-commerce/elsie/i18n';\nimport { Container, Slot, SlotProps } from '@adobe-commerce/elsie/lib';\nimport { events } from '@adobe-commerce/event-bus';\nimport { HTMLAttributes } from 'preact/compat';\nimport { useCallback, useEffect, useState } from 'preact/hooks';\n\nexport interface ContentSlotContext {\n code: string;\n}\n\nexport interface HandlePlaceOrderContext {\n code: string;\n cartId?: string | null;\n quoteId?: string | null;\n}\n\nexport interface PlaceOrderProps extends HTMLAttributes<HTMLDivElement> {\n disabled?: boolean;\n active?: boolean;\n handleValidation?: () => boolean;\n handlePlaceOrder: (ctx: HandlePlaceOrderContext) => Promise<void>;\n slots?: {\n Content?: SlotProps<ContentSlotContext>;\n };\n}\n\nexport const PlaceOrder: Container<PlaceOrderProps> = ({\n disabled: disabledViaProp = false,\n active = true,\n handleValidation,\n handlePlaceOrder,\n slots,\n ...props\n}) => {\n const [isInitialized, setIsInitialized] = useState(false);\n const [hasOutOfStockItems, setHasOutOfStockItems] = useState(false);\n\n const hasQueuedUpdates = hasPendingUpdates.value;\n\n const translations = useText({\n CheckoutUnexpectedError: 'Checkout.ServerError.unexpected',\n placeOrderButton: 'Checkout.PlaceOrder.button',\n });\n\n const handlePlaceOrderError = useCallback(\n (error: any) => {\n const code = mapErrorToCode(error);\n\n const message =\n code === ErrorCodes.UNKNOWN_ERROR\n ? translations.CheckoutUnexpectedError\n : error.message;\n\n events.emit('checkout/error', { message, code });\n },\n [translations]\n );\n\n const handleClick = useCallback(async () => {\n try {\n if (handleValidation && !handleValidation()) return;\n\n await handlePlaceOrder({\n cartId: state.cartId,\n quoteId: state.quoteId,\n code: getValue('selectedPaymentMethod')?.code ?? '',\n });\n } catch (error: any) {\n handlePlaceOrderError(error);\n }\n }, [handleValidation, handlePlaceOrder, handlePlaceOrderError]);\n\n const handleCheckoutData = useCallback(\n (data: Cart | NegotiableQuote | null) => {\n const isEmptyCart = !data || ('isEmpty' in data && data.isEmpty);\n\n if (isEmptyCart) {\n setHasOutOfStockItems(false);\n }\n },\n []\n );\n\n useEffect(() => {\n if (active === false) return;\n\n const onCartData = events.on(\n 'cart/initialized',\n (data) => {\n const items = (data?.items || []) as ItemModel[];\n setHasOutOfStockItems(\n items.some((item) => item.outOfStock || item.insufficientQuantity)\n );\n },\n { eager: true }\n );\n\n return () => {\n onCartData?.off();\n };\n }, [active]);\n\n useEffect(() => {\n if (!active) return;\n\n const pastUpdate = getLatestCheckoutUpdate();\n\n if (pastUpdate) {\n setIsInitialized(true);\n handleCheckoutData(pastUpdate);\n return;\n }\n\n const onCheckoutInit = events.on(\n 'checkout/initialized',\n (data) => {\n setIsInitialized(true);\n handleCheckoutData(data);\n },\n { eager: true }\n );\n\n return () => {\n onCheckoutInit?.off();\n };\n }, [active, handleCheckoutData]);\n\n useEffect(() => {\n if (!active) return;\n\n const onCheckoutUpdated = events.on(\n 'checkout/updated',\n (data) => {\n handleCheckoutData(data);\n },\n { eager: false }\n );\n\n return () => {\n onCheckoutUpdated?.off();\n };\n }, [active, handleCheckoutData]);\n\n return (\n <PlaceOrderComponent\n {...props}\n disabled={disabledViaProp || hasOutOfStockItems || hasQueuedUpdates}\n initialized={isInitialized}\n visible={active}\n onClick={handleClick}\n >\n <Slot\n context={{ code: getValue('selectedPaymentMethod')?.code ?? '' }}\n name=\"Content\"\n slot={slots?.Content}\n >\n {translations.placeOrderButton}\n </Slot>\n </PlaceOrderComponent>\n );\n};\n"],"names":["ErrorCodes","KNOWN_SERVER_ERRORS","classifiers","error","InvalidInput","Unauthenticated","mapErrorToCode","matchingClassifier","classifier","PlaceOrderSkeleton","jsxs","Skeleton","jsx","SkeletonRow","PlaceOrderComponent","children","className","disabled","onClick","classes","Button","PlaceOrder","WithConditionals","disabledViaProp","active","handleValidation","handlePlaceOrder","slots","props","isInitialized","setIsInitialized","useState","hasOutOfStockItems","setHasOutOfStockItems","hasQueuedUpdates","hasPendingUpdates","translations","useText","handlePlaceOrderError","useCallback","code","message","events","handleClick","state","_a","getValue","handleCheckoutData","data","useEffect","onCartData","items","item","pastUpdate","getLatestCheckoutUpdate","onCheckoutInit","onCheckoutUpdated","Slot"],"mappings":"ssBAqBY,IAAAA,GAAAA,IACVA,EAAA,cAAgB,gBAChBA,EAAA,aAAe,eACfA,EAAA,gBAAkB,kBAClBA,EAAA,cAAgB,gBAJNA,IAAAA,GAAA,CAAA,CAAA,EAOZ,MAAMC,EAAsB,CAAC,iBAAiB,EAgBjCC,EAAiC,CAC5C,CACE,KAAM,gBACN,QAAUC,GACDA,aAAiBC,CAE5B,EACA,CACE,KAAM,kBACN,QAAUD,GACDA,aAAiBE,CAE5B,EACA,CACE,KAAM,eACN,QAAUF,GACJ,CAACA,GAAS,OAAOA,GAAU,UAAY,EAAE,SAAUA,GAC9C,GAGFF,EAAoB,SAAUE,EAA2B,IAAI,CACtE,CAEJ,EC5CO,SAASG,EAAeH,EAA2B,CACxD,MAAMI,EAAqBL,EAAY,KAAMM,GAC3CA,EAAW,QAAQL,CAAK,CAC1B,EAEA,OAAII,EACKA,EAAmB,KAGrBP,EAAW,aACpB,CC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,EACT,QAASmB,EAET,SAAA/B,EAAC6C,EAAA,CACC,QAAS,CAAE,OAAMZ,EAAAC,EAAS,uBAAuB,IAAhC,YAAAD,EAAmC,OAAQ,EAAG,EAC/D,KAAK,UACL,KAAMlB,GAAA,YAAAA,EAAO,QAEZ,SAAaS,EAAA,gBAAA,CAAA,CAChB,CACF,CAEJ"}
|
|
1
|
+
{"version":3,"file":"PlaceOrder.js","sources":["/@dropins/storefront-checkout/src/lib/errors/mapErrorToCode.ts","/@dropins/storefront-checkout/src/components/PlaceOrder/PlaceOrderSkeleton.tsx","/@dropins/storefront-checkout/src/components/PlaceOrder/PlaceOrder.tsx","/@dropins/storefront-checkout/src/containers/PlaceOrder/PlaceOrder.tsx"],"sourcesContent":["/********************************************************************\n * ADOBE CONFIDENTIAL\n * __________________\n *\n * Copyright 2025 Adobe\n * All Rights Reserved.\n *\n * NOTICE: All information contained herein is, and remains\n * the property of Adobe and its suppliers, if any. The intellectual\n * and technical concepts contained herein are proprietary to Adobe\n * and its suppliers and are protected by all applicable intellectual\n * property laws, including trade secret and copyright laws.\n * Dissemination of this information or reproduction of this material\n * is strictly forbidden unless prior written permission is obtained\n * from Adobe.\n *******************************************************************/\n\nimport {\n classifiers,\n ErrorCode,\n ErrorCodes,\n} from '@/checkout/lib/errors/classifiers';\n\nexport function mapErrorToCode(error: unknown): ErrorCode {\n const matchingClassifier = classifiers.find((classifier) =>\n classifier.matches(error)\n );\n\n if (matchingClassifier) {\n return matchingClassifier.code;\n }\n\n return ErrorCodes.UNKNOWN_ERROR;\n}\n","/********************************************************************\n * ADOBE CONFIDENTIAL\n * __________________\n *\n * Copyright 2024 Adobe\n * All Rights Reserved.\n *\n * NOTICE: All information contained herein is, and remains\n * the property of Adobe and its suppliers, if any. The intellectual\n * and technical concepts contained herein are proprietary to Adobe\n * and its suppliers and are protected by all applicable intellectual\n * property laws, including trade secret and copyright laws.\n * Dissemination of this information or reproduction of this material\n * is strictly forbidden unless prior written permission is obtained\n * from Adobe.\n *******************************************************************/\n\nimport { Skeleton, SkeletonRow } from '@adobe-commerce/elsie/components';\nimport { FunctionComponent } from 'preact';\n\nexport const PlaceOrderSkeleton: FunctionComponent = () => {\n return (\n <Skeleton data-testid=\"place-order-skeleton\">\n <SkeletonRow size=\"small\" variant=\"empty\" />\n <SkeletonRow size=\"small\" />\n </Skeleton>\n );\n};\n","/********************************************************************\n * ADOBE CONFIDENTIAL\n * __________________\n *\n * Copyright 2024 Adobe\n * All Rights Reserved.\n *\n * NOTICE: All information contained herein is, and remains\n * the property of Adobe and its suppliers, if any. The intellectual\n * and technical concepts contained herein are proprietary to Adobe\n * and its suppliers and are protected by all applicable intellectual\n * property laws, including trade secret and copyright laws.\n * Dissemination of this information or reproduction of this material\n * is strictly forbidden unless prior written permission is obtained\n * from Adobe.\n *******************************************************************/\n\nimport { WithConditionals } from '@/checkout/components/ConditionalWrapper/index';\nimport '@/checkout/components/PlaceOrder/PlaceOrder.css';\nimport { PlaceOrderSkeleton } from '@/checkout/components/PlaceOrder/PlaceOrderSkeleton';\nimport { Button } from '@adobe-commerce/elsie/components';\nimport { classes } from '@adobe-commerce/elsie/lib';\nimport { FunctionComponent } from 'preact';\nimport { HTMLAttributes } from 'preact/compat';\n\nexport interface PlaceOrderProps extends HTMLAttributes<HTMLDivElement> {\n disabled?: boolean;\n onClick: (event: Event) => Promise<void>;\n}\n\nconst PlaceOrderComponent: FunctionComponent<PlaceOrderProps> = ({\n children,\n className,\n disabled = false,\n onClick,\n}) => {\n return (\n <div className={classes(['checkout-place-order', className])}>\n <Button\n key=\"placeOrder\"\n className=\"checkout-place-order__button\"\n data-testid=\"place-order-button\"\n disabled={disabled}\n size=\"medium\"\n type=\"button\"\n variant=\"primary\"\n onClick={onClick}\n >\n {children}\n </Button>\n </div>\n );\n};\n\nexport const PlaceOrder = WithConditionals(\n PlaceOrderComponent,\n PlaceOrderSkeleton\n);\n","/********************************************************************\n * ADOBE CONFIDENTIAL\n * __________________\n *\n * Copyright 2024 Adobe\n * All Rights Reserved.\n *\n * NOTICE: All information contained herein is, and remains\n * the property of Adobe and its suppliers, if any. The intellectual\n * and technical concepts contained herein are proprietary to Adobe\n * and its suppliers and are protected by all applicable intellectual\n * property laws, including trade secret and copyright laws.\n * Dissemination of this information or reproduction of this material\n * is strictly forbidden unless prior written permission is obtained\n * from Adobe.\n *******************************************************************/\n\nimport { PlaceOrder as PlaceOrderComponent } from '@/checkout/components/PlaceOrder/PlaceOrder';\nimport { Cart, NegotiableQuote } from '@/checkout/data/models';\nimport {\n getLatestCheckoutUpdate,\n getValue,\n hasPendingUpdates,\n state,\n} from '@/checkout/lib';\nimport { ErrorCodes, mapErrorToCode } from '@/checkout/lib/errors';\nimport { Item as ItemModel } from '@/checkout/types';\nimport { useText } from '@adobe-commerce/elsie/i18n';\nimport { Container, Slot, SlotProps } from '@adobe-commerce/elsie/lib';\nimport { events } from '@adobe-commerce/event-bus';\nimport { HTMLAttributes } from 'preact/compat';\nimport { useCallback, useEffect, useState } from 'preact/hooks';\n\nexport interface ContentSlotContext {\n code: string;\n}\n\nexport interface HandlePlaceOrderContext {\n code: string;\n cartId?: string | null;\n quoteId?: string | null;\n}\n\nexport interface PlaceOrderProps extends HTMLAttributes<HTMLDivElement> {\n disabled?: boolean;\n active?: boolean;\n handleValidation?: () => boolean;\n handlePlaceOrder: (ctx: HandlePlaceOrderContext) => Promise<void>;\n slots?: {\n Content?: SlotProps<ContentSlotContext>;\n };\n}\n\nexport const PlaceOrder: Container<PlaceOrderProps> = ({\n disabled: disabledViaProp = false,\n active = true,\n handleValidation,\n handlePlaceOrder,\n slots,\n ...props\n}) => {\n const [isInitialized, setIsInitialized] = useState(false);\n const [hasOutOfStockItems, setHasOutOfStockItems] = useState(false);\n\n const hasQueuedUpdates = hasPendingUpdates.value;\n\n const translations = useText({\n CheckoutUnexpectedError: 'Checkout.ServerError.unexpected',\n placeOrderButton: 'Checkout.PlaceOrder.button',\n });\n\n const handlePlaceOrderError = useCallback(\n (error: any) => {\n const code = mapErrorToCode(error);\n\n const message =\n code === ErrorCodes.UNKNOWN_ERROR\n ? translations.CheckoutUnexpectedError\n : error.message;\n\n events.emit('checkout/error', { message, code });\n },\n [translations]\n );\n\n const handleClick = useCallback(async () => {\n try {\n if (handleValidation && !handleValidation()) return;\n\n await handlePlaceOrder({\n cartId: state.cartId,\n quoteId: state.quoteId,\n code: getValue('selectedPaymentMethod')?.code ?? '',\n });\n } catch (error: any) {\n handlePlaceOrderError(error);\n }\n }, [handleValidation, handlePlaceOrder, handlePlaceOrderError]);\n\n const handleCheckoutData = useCallback(\n (data: Cart | NegotiableQuote | null) => {\n const isEmptyCart = !data || ('isEmpty' in data && data.isEmpty);\n\n if (isEmptyCart) {\n setHasOutOfStockItems(false);\n }\n },\n []\n );\n\n useEffect(() => {\n if (active === false) return;\n\n const onCartData = events.on(\n 'cart/initialized',\n (data) => {\n const items = (data?.items || []) as ItemModel[];\n setHasOutOfStockItems(\n items.some((item) => item.outOfStock || item.insufficientQuantity)\n );\n },\n { eager: true }\n );\n\n return () => {\n onCartData?.off();\n };\n }, [active]);\n\n useEffect(() => {\n if (!active) return;\n\n const pastUpdate = getLatestCheckoutUpdate();\n\n if (pastUpdate) {\n setIsInitialized(true);\n handleCheckoutData(pastUpdate);\n return;\n }\n\n const onCheckoutInit = events.on(\n 'checkout/initialized',\n (data) => {\n setIsInitialized(true);\n handleCheckoutData(data);\n },\n { eager: true }\n );\n\n return () => {\n onCheckoutInit?.off();\n };\n }, [active, handleCheckoutData]);\n\n useEffect(() => {\n if (!active) return;\n\n const onCheckoutUpdated = events.on(\n 'checkout/updated',\n (data) => {\n handleCheckoutData(data);\n },\n { eager: false }\n );\n\n return () => {\n onCheckoutUpdated?.off();\n };\n }, [active, handleCheckoutData]);\n\n return (\n <PlaceOrderComponent\n {...props}\n disabled={disabledViaProp || hasOutOfStockItems || hasQueuedUpdates}\n initialized={isInitialized}\n visible={active}\n onClick={handleClick}\n >\n <Slot\n context={{ code: getValue('selectedPaymentMethod')?.code ?? '' }}\n name=\"Content\"\n slot={slots?.Content}\n >\n {translations.placeOrderButton}\n </Slot>\n </PlaceOrderComponent>\n );\n};\n"],"names":["mapErrorToCode","error","matchingClassifier","classifiers","classifier","ErrorCodes","PlaceOrderSkeleton","jsxs","Skeleton","jsx","SkeletonRow","PlaceOrderComponent","children","className","disabled","onClick","classes","Button","PlaceOrder","WithConditionals","disabledViaProp","active","handleValidation","handlePlaceOrder","slots","props","isInitialized","setIsInitialized","useState","hasOutOfStockItems","setHasOutOfStockItems","hasQueuedUpdates","hasPendingUpdates","translations","useText","handlePlaceOrderError","useCallback","code","message","events","handleClick","state","_a","getValue","handleCheckoutData","data","useEffect","onCartData","items","item","pastUpdate","getLatestCheckoutUpdate","onCheckoutInit","onCheckoutUpdated","Slot"],"mappings":"wuBAuBO,SAASA,EAAeC,EAA2B,CACxD,MAAMC,EAAqBC,EAAY,KAAMC,GAC3CA,EAAW,QAAQH,CAAK,CAC1B,EAEA,OAAIC,EACKA,EAAmB,KAGrBG,EAAW,aACpB,CCbO,MAAMC,EAAwC,IAEjDC,EAACC,EAAS,CAAA,cAAY,uBACpB,SAAA,CAAAC,EAACC,EAAY,CAAA,KAAK,QAAQ,QAAQ,QAAQ,EAC1CD,EAACC,EAAY,CAAA,KAAK,OAAQ,CAAA,CAAA,EAC5B,ECKEC,EAA0D,CAAC,CAC/D,SAAAC,EACA,UAAAC,EACA,SAAAC,EAAW,GACX,QAAAC,CACF,IAEIN,EAAC,OAAI,UAAWO,EAAQ,CAAC,uBAAwBH,CAAS,CAAC,EACzD,SAAAJ,EAACQ,EAAA,CAEC,UAAU,+BACV,cAAY,qBACZ,SAAAH,EACA,KAAK,SACL,KAAK,SACL,QAAQ,UACR,QAAAC,EAEC,SAAAH,CAAA,EATG,YAAA,EAWR,EAISM,EAAaC,EACxBR,EACAL,CACF,ECJaY,GAAyC,CAAC,CACrD,SAAUE,EAAkB,GAC5B,OAAAC,EAAS,GACT,iBAAAC,EACA,iBA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,OAEb,MAAM6B,EAAaC,EAAwB,EAE3C,GAAID,EAAY,CACdvB,EAAiB,EAAI,EACrBiB,EAAmBM,CAAU,EAC7B,MAAA,CAGF,MAAME,EAAiBb,EAAO,GAC5B,uBACCM,GAAS,CACRlB,EAAiB,EAAI,EACrBiB,EAAmBC,CAAI,CACzB,EACA,CAAE,MAAO,EAAK,CAChB,EAEA,MAAO,IAAM,CACXO,GAAA,MAAAA,EAAgB,KAClB,CAAA,EACC,CAAC/B,EAAQuB,CAAkB,CAAC,EAE/BE,EAAU,IAAM,CACd,GAAI,CAACzB,EAAQ,OAEb,MAAMgC,EAAoBd,EAAO,GAC/B,mBACCM,GAAS,CACRD,EAAmBC,CAAI,CACzB,EACA,CAAE,MAAO,EAAM,CACjB,EAEA,MAAO,IAAM,CACXQ,GAAA,MAAAA,EAAmB,KACrB,CAAA,EACC,CAAChC,EAAQuB,CAAkB,CAAC,EAG7BnC,EAACE,EAAA,CACE,GAAGc,EACJ,SAAUL,GAAmBS,GAAsBE,EACnD,YAAaL,EACb,QAASL,EACT,QAASmB,EAET,SAAA/B,EAAC6C,EAAA,CACC,QAAS,CAAE,OAAMZ,EAAAC,EAAS,uBAAuB,IAAhC,YAAAD,EAAmC,OAAQ,EAAG,EAC/D,KAAK,UACL,KAAMlB,GAAA,YAAAA,EAAO,QAEZ,SAAaS,EAAA,gBAAA,CAAA,CAChB,CACF,CAEJ"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Container } from '@dropins/tools/types/elsie/src/lib';
|
|
2
|
+
import { HTMLAttributes } from 'preact/compat';
|
|
3
|
+
|
|
4
|
+
export interface PurchaseOrderProps extends HTMLAttributes<HTMLFormElement> {
|
|
5
|
+
initialReferenceNumber?: string;
|
|
6
|
+
onReferenceNumberChange?: (referenceNumber: string) => void;
|
|
7
|
+
onReferenceNumberBlur?: (referenceNumber: string) => void;
|
|
8
|
+
}
|
|
9
|
+
export declare const PurchaseOrder: Container<PurchaseOrderProps>;
|
|
10
|
+
//# sourceMappingURL=PurchaseOrder.d.ts.map
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/********************************************************************
|
|
2
|
+
* ADOBE CONFIDENTIAL
|
|
3
|
+
* __________________
|
|
4
|
+
*
|
|
5
|
+
* Copyright 2025 Adobe
|
|
6
|
+
* All Rights Reserved.
|
|
7
|
+
*
|
|
8
|
+
* NOTICE: All information contained herein is, and remains
|
|
9
|
+
* the property of Adobe and its suppliers, if any. The intellectual
|
|
10
|
+
* and technical concepts contained herein are proprietary to Adobe
|
|
11
|
+
* and its suppliers and are protected by all applicable intellectual
|
|
12
|
+
* property laws, including trade secret and copyright laws.
|
|
13
|
+
* Dissemination of this information or reproduction of this material
|
|
14
|
+
* is strictly forbidden unless prior written permission is obtained
|
|
15
|
+
* from Adobe.
|
|
16
|
+
*******************************************************************/
|
|
17
|
+
export * from './PurchaseOrder';
|
|
18
|
+
export { PurchaseOrder as default } from './PurchaseOrder';
|
|
19
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
/*! Copyright 2025 Adobe
|
|
2
|
+
All Rights Reserved. */
|
|
3
|
+
import{P as O,P as b}from"../chunks/PurchaseOrder.js";import"@dropins/tools/preact-jsx-runtime.js";import"../chunks/TermsAndConditions.js";import"@dropins/tools/lib.js";import"@dropins/tools/components.js";/* empty css */import"../chunks/fetch-graphql.js";import"@dropins/tools/event-bus.js";import"@dropins/tools/signals.js";import"@dropins/tools/fetch-graphql.js";import"@dropins/tools/preact-compat.js";/* empty css *//* empty css */import"@dropins/tools/i18n.js";/* empty css */import"@dropins/tools/preact-hooks.js";export{O as PurchaseOrder,b as default};
|
|
4
|
+
//# sourceMappingURL=PurchaseOrder.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PurchaseOrder.js","sources":[],"sourcesContent":[],"names":[],"mappings":""}
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
+
import { CheckoutError } from '../../data/models/checkout';
|
|
1
2
|
import { Container } from '@dropins/tools/types/elsie/src/lib';
|
|
2
3
|
|
|
3
4
|
export interface ServerErrorProps {
|
|
4
5
|
autoScroll?: boolean;
|
|
5
|
-
onRetry?: () => void;
|
|
6
|
+
onRetry?: (error: CheckoutError | null) => void;
|
|
6
7
|
onServerError?: (error: string) => void;
|
|
7
8
|
active?: boolean;
|
|
8
9
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
/*! Copyright 2025 Adobe
|
|
2
2
|
All Rights Reserved. */
|
|
3
|
-
import{jsx as o,jsxs as f}from"@dropins/tools/preact-jsx-runtime.js";import"../chunks/TermsAndConditions.js";import{classes as i}from"@dropins/tools/lib.js";import{IllustratedMessage as h,Icon as d,Button as v}from"@dropins/tools/components.js";/* empty css
|
|
3
|
+
import{jsx as o,jsxs as f}from"@dropins/tools/preact-jsx-runtime.js";import"../chunks/TermsAndConditions.js";import{classes as i}from"@dropins/tools/lib.js";import{IllustratedMessage as h,Icon as d,Button as v}from"@dropins/tools/components.js";/* empty css */import"../chunks/fetch-graphql.js";import{events as g}from"@dropins/tools/event-bus.js";import{s as k}from"../chunks/dom.js";import"@dropins/tools/preact-compat.js";/* empty css *//* empty css */import{S}from"../chunks/OrderError.js";import{useText as C}from"@dropins/tools/i18n.js";/* empty css */import{useState as E,useRef as _,useEffect as l}from"@dropins/tools/preact-hooks.js";import"@dropins/tools/signals.js";import"@dropins/tools/fetch-graphql.js";const b=({className:n,contactSupport:s,errorMessage:t,onClick:a,errorMessageRef:r})=>{const e=C({Title:"Checkout.ServerError.title",Message:"Checkout.ServerError.message",ContactSupport:"Checkout.ServerError.contactSupport",Button:"Checkout.ServerError.button"}),c=t!==""?t:e.Title;return o(h,{action:o(v,{className:i(["checkout-server-error__button"]),name:"server-error-button",onClick:a,children:e.Button}),"aria-describedby":"checkout-server-error__message","aria-invalid":"true","aria-live":"polite",className:i(["checkout-server-error",n]),"data-testid":"checkout-server-error",heading:c,icon:o(d,{className:i(["checkout-server-error__icon"]),source:S}),message:f("p",{ref:r,"data-testid":"checkout-server-error-message",id:i(["checkout-server-error__message"]),children:[e.Message,o("br",{}),o("span",{children:s??e.ContactSupport})]})})},J=({active:n=!0,onRetry:s,onServerError:t,autoScroll:a=!1})=>{const[r,e]=E(null),c=_(null),p=async()=>{s==null||s(r),e(null)};return l(()=>{const u=g.on("checkout/error",m=>{e(m||null),m&&t&&t(m.message)},{eager:!0});return()=>{u==null||u.off()}},[t]),l(()=>{!a||!r||!c.current||k(c.current)},[r,a]),!n||!r?null:o(b,{errorMessage:r.message,errorMessageRef:c,onClick:p})};export{J as ServerError,J as default};
|
|
4
4
|
//# sourceMappingURL=ServerError.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ServerError.js","sources":["/@dropins/storefront-checkout/src/components/ServerError/ServerError.tsx","/@dropins/storefront-checkout/src/containers/ServerError/ServerError.tsx"],"sourcesContent":["/********************************************************************\n * ADOBE CONFIDENTIAL\n * __________________\n *\n * Copyright 2024 Adobe\n * All Rights Reserved.\n *\n * NOTICE: All information contained herein is, and remains\n * the property of Adobe and its suppliers, if any. The intellectual\n * and technical concepts contained herein are proprietary to Adobe\n * and its suppliers and are protected by all applicable intellectual\n * property laws, including trade secret and copyright laws.\n * Dissemination of this information or reproduction of this material\n * is strictly forbidden unless prior written permission is obtained\n * from Adobe.\n *******************************************************************/\n\nimport '@/checkout/components/ServerError/ServerError.css';\nimport {\n Button,\n Icon,\n IllustratedMessage,\n} from '@adobe-commerce/elsie/components';\nimport { useText } from '@adobe-commerce/elsie/i18n';\nimport { OrderError } from '@adobe-commerce/elsie/icons';\nimport { classes } from '@adobe-commerce/elsie/lib';\nimport { FunctionComponent, RefObject } from 'preact';\nimport { HTMLAttributes } from 'preact/compat';\n\nexport interface ServerErrorProps\n extends Omit<HTMLAttributes<HTMLDivElement>, 'icon'> {\n errorMessageRef?: RefObject<HTMLParagraphElement>;\n errorMessage: string;\n contactSupport?: string;\n onClick?: (e: any) => void;\n}\n\nexport const ServerError: FunctionComponent<ServerErrorProps> = ({\n className,\n contactSupport,\n errorMessage,\n onClick,\n errorMessageRef,\n}) => {\n const translations = useText({\n Title: 'Checkout.ServerError.title',\n Message: 'Checkout.ServerError.message',\n ContactSupport: 'Checkout.ServerError.contactSupport',\n Button: 'Checkout.ServerError.button',\n });\n\n const heading = errorMessage !== '' ? errorMessage : translations.Title;\n\n return (\n <IllustratedMessage\n action={\n <Button\n className={classes(['checkout-server-error__button'])}\n name=\"server-error-button\"\n onClick={onClick}\n >\n {translations.Button}\n </Button>\n }\n aria-describedby=\"checkout-server-error__message\"\n aria-invalid=\"true\"\n aria-live=\"polite\"\n className={classes(['checkout-server-error', className])}\n data-testid=\"checkout-server-error\"\n heading={heading}\n icon={\n <Icon\n className={classes(['checkout-server-error__icon'])}\n source={OrderError}\n />\n }\n message={\n <p\n ref={errorMessageRef}\n data-testid=\"checkout-server-error-message\"\n id={classes(['checkout-server-error__message'])}\n >\n {translations.Message}\n <br />\n <span>{contactSupport ?? translations.ContactSupport}</span>\n </p>\n }\n />\n );\n};\n","/********************************************************************\n * ADOBE CONFIDENTIAL\n * __________________\n *\n * Copyright 2024 Adobe\n * All Rights Reserved.\n *\n * NOTICE: All information contained herein is, and remains\n * the property of Adobe and its suppliers, if any. The intellectual\n * and technical concepts contained herein are proprietary to Adobe\n * and its suppliers and are protected by all applicable intellectual\n * property laws, including trade secret and copyright laws.\n * Dissemination of this information or reproduction of this material\n * is strictly forbidden unless prior written permission is obtained\n * from Adobe.\n *******************************************************************/\n\nimport { ServerError as ServerErrorComponent } from '@/checkout/components';\nimport { CheckoutError } from '@/checkout/data/models/checkout';\nimport { scrollToElement } from '@/checkout/lib';\nimport { Container } from '@adobe-commerce/elsie/lib';\nimport { events } from '@adobe-commerce/event-bus';\nimport { useEffect, useRef, useState } from 'preact/hooks';\n\nexport interface ServerErrorProps {\n autoScroll?: boolean;\n onRetry?: () => void;\n onServerError?: (error: string) => void;\n active?: boolean;\n}\n\nexport const ServerError: Container<ServerErrorProps> = ({\n active = true,\n onRetry,\n onServerError,\n autoScroll = false,\n}) => {\n const [error, setError] = useState<CheckoutError | null>(null);\n const errorMessageRef = useRef<HTMLParagraphElement>(null);\n\n const handleClick = async () => {\n onRetry?.();\n setError(null);\n };\n\n useEffect(() => {\n const subscription = events.on(\n 'checkout/error',\n (error: CheckoutError | undefined) => {\n setError(error || null);\n if (error && onServerError) {\n onServerError(error.message);\n }\n },\n { eager: true }\n );\n\n return () => {\n subscription?.off();\n };\n }, [onServerError]);\n\n useEffect(() => {\n if (!autoScroll || !error || !errorMessageRef.current) return;\n scrollToElement(errorMessageRef.current);\n }, [error, autoScroll]);\n\n if (!active || !error) return null;\n\n return (\n <ServerErrorComponent\n errorMessage={error.message}\n errorMessageRef={errorMessageRef}\n onClick={handleClick}\n />\n );\n};\n"],"names":["ServerError","className","contactSupport","errorMessage","onClick","errorMessageRef","translations","useText","heading","jsx","IllustratedMessage","Button","classes","Icon","OrderError","jsxs","active","onRetry","onServerError","autoScroll","error","setError","useState","useRef","handleClick","useEffect","subscription","events","scrollToElement","ServerErrorComponent"],"mappings":"
|
|
1
|
+
{"version":3,"file":"ServerError.js","sources":["/@dropins/storefront-checkout/src/components/ServerError/ServerError.tsx","/@dropins/storefront-checkout/src/containers/ServerError/ServerError.tsx"],"sourcesContent":["/********************************************************************\n * ADOBE CONFIDENTIAL\n * __________________\n *\n * Copyright 2024 Adobe\n * All Rights Reserved.\n *\n * NOTICE: All information contained herein is, and remains\n * the property of Adobe and its suppliers, if any. The intellectual\n * and technical concepts contained herein are proprietary to Adobe\n * and its suppliers and are protected by all applicable intellectual\n * property laws, including trade secret and copyright laws.\n * Dissemination of this information or reproduction of this material\n * is strictly forbidden unless prior written permission is obtained\n * from Adobe.\n *******************************************************************/\n\nimport '@/checkout/components/ServerError/ServerError.css';\nimport {\n Button,\n Icon,\n IllustratedMessage,\n} from '@adobe-commerce/elsie/components';\nimport { useText } from '@adobe-commerce/elsie/i18n';\nimport { OrderError } from '@adobe-commerce/elsie/icons';\nimport { classes } from '@adobe-commerce/elsie/lib';\nimport { FunctionComponent, RefObject } from 'preact';\nimport { HTMLAttributes } from 'preact/compat';\n\nexport interface ServerErrorProps\n extends Omit<HTMLAttributes<HTMLDivElement>, 'icon'> {\n errorMessageRef?: RefObject<HTMLParagraphElement>;\n errorMessage: string;\n contactSupport?: string;\n onClick?: (e: any) => void;\n}\n\nexport const ServerError: FunctionComponent<ServerErrorProps> = ({\n className,\n contactSupport,\n errorMessage,\n onClick,\n errorMessageRef,\n}) => {\n const translations = useText({\n Title: 'Checkout.ServerError.title',\n Message: 'Checkout.ServerError.message',\n ContactSupport: 'Checkout.ServerError.contactSupport',\n Button: 'Checkout.ServerError.button',\n });\n\n const heading = errorMessage !== '' ? errorMessage : translations.Title;\n\n return (\n <IllustratedMessage\n action={\n <Button\n className={classes(['checkout-server-error__button'])}\n name=\"server-error-button\"\n onClick={onClick}\n >\n {translations.Button}\n </Button>\n }\n aria-describedby=\"checkout-server-error__message\"\n aria-invalid=\"true\"\n aria-live=\"polite\"\n className={classes(['checkout-server-error', className])}\n data-testid=\"checkout-server-error\"\n heading={heading}\n icon={\n <Icon\n className={classes(['checkout-server-error__icon'])}\n source={OrderError}\n />\n }\n message={\n <p\n ref={errorMessageRef}\n data-testid=\"checkout-server-error-message\"\n id={classes(['checkout-server-error__message'])}\n >\n {translations.Message}\n <br />\n <span>{contactSupport ?? translations.ContactSupport}</span>\n </p>\n }\n />\n );\n};\n","/********************************************************************\n * ADOBE CONFIDENTIAL\n * __________________\n *\n * Copyright 2024 Adobe\n * All Rights Reserved.\n *\n * NOTICE: All information contained herein is, and remains\n * the property of Adobe and its suppliers, if any. The intellectual\n * and technical concepts contained herein are proprietary to Adobe\n * and its suppliers and are protected by all applicable intellectual\n * property laws, including trade secret and copyright laws.\n * Dissemination of this information or reproduction of this material\n * is strictly forbidden unless prior written permission is obtained\n * from Adobe.\n *******************************************************************/\n\nimport { ServerError as ServerErrorComponent } from '@/checkout/components';\nimport { CheckoutError } from '@/checkout/data/models/checkout';\nimport { scrollToElement } from '@/checkout/lib';\nimport { Container } from '@adobe-commerce/elsie/lib';\nimport { events } from '@adobe-commerce/event-bus';\nimport { useEffect, useRef, useState } from 'preact/hooks';\n\nexport interface ServerErrorProps {\n autoScroll?: boolean;\n onRetry?: (error: CheckoutError | null) => void;\n onServerError?: (error: string) => void;\n active?: boolean;\n}\n\nexport const ServerError: Container<ServerErrorProps> = ({\n active = true,\n onRetry,\n onServerError,\n autoScroll = false,\n}) => {\n const [error, setError] = useState<CheckoutError | null>(null);\n const errorMessageRef = useRef<HTMLParagraphElement>(null);\n\n const handleClick = async () => {\n onRetry?.(error);\n setError(null);\n };\n\n useEffect(() => {\n const subscription = events.on(\n 'checkout/error',\n (error: CheckoutError | undefined) => {\n setError(error || null);\n if (error && onServerError) {\n onServerError(error.message);\n }\n },\n { eager: true }\n );\n\n return () => {\n subscription?.off();\n };\n }, [onServerError]);\n\n useEffect(() => {\n if (!autoScroll || !error || !errorMessageRef.current) return;\n scrollToElement(errorMessageRef.current);\n }, [error, autoScroll]);\n\n if (!active || !error) return null;\n\n return (\n <ServerErrorComponent\n errorMessage={error.message}\n errorMessageRef={errorMessageRef}\n onClick={handleClick}\n />\n );\n};\n"],"names":["ServerError","className","contactSupport","errorMessage","onClick","errorMessageRef","translations","useText","heading","jsx","IllustratedMessage","Button","classes","Icon","OrderError","jsxs","active","onRetry","onServerError","autoScroll","error","setError","useState","useRef","handleClick","useEffect","subscription","events","scrollToElement","ServerErrorComponent"],"mappings":"uyBAqCO,MAAMA,EAAmD,CAAC,CAC/D,UAAAC,EACA,eAAAC,EACA,aAAAC,EACA,QAAAC,EACA,gBAAAC,CACF,IAAM,CACJ,MAAMC,EAAeC,EAAQ,CAC3B,MAAO,6BACP,QAAS,+BACT,eAAgB,sCAChB,OAAQ,6BAAA,CACT,EAEKC,EAAUL,IAAiB,GAAKA,EAAeG,EAAa,MA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c,KAG5BX,EAACoB,EAAA,CACC,aAAcT,EAAM,QACpB,gBAAAf,EACA,QAASmB,CAAA,CACX,CAEJ"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
/*! Copyright 2025 Adobe
|
|
2
2
|
All Rights Reserved. */
|
|
3
|
-
import{jsxs as V,jsx as n,Fragment as G}from"@dropins/tools/preact-jsx-runtime.js";import{h as ce,
|
|
3
|
+
import{jsxs as V,jsx as n,Fragment as G}from"@dropins/tools/preact-jsx-runtime.js";import{h as ce,m as ae}from"../chunks/fetch-graphql.js";import{classes as z,VComponent as le,Slot as ue}from"@dropins/tools/lib.js";import{t as pe}from"../chunks/transform-shipping-estimate.js";import{h as D,a as de}from"../chunks/events2.js";import{n as he,g as I}from"../chunks/values.js";import{events as B}from"@dropins/tools/event-bus.js";import{c as J}from"../chunks/synchronizeCheckout.js";import{s as me}from"../chunks/setShippingMethods.js";import{W as fe}from"../chunks/ConditionalWrapper.js";/* empty css */import{Skeleton as ge,SkeletonRow as O,IllustratedMessage as ke,Icon as ve,InLineAlert as Se,RadioButton as Ee,Price as K,ToggleButton as Ce}from"@dropins/tools/components.js";import{s as Le}from"../chunks/dom.js";import{useRef as Me,useEffect as A,useState as T,useCallback as p,useMemo as X}from"@dropins/tools/preact-hooks.js";import*as a from"@dropins/tools/preact-compat.js";import{useText as Y}from"@dropins/tools/i18n.js";import"@dropins/tools/signals.js";import"@dropins/tools/fetch-graphql.js";import"../fragments.js";import"../chunks/transform-shipping-methods.js";import"../chunks/classifiers.js";import"../chunks/guards.js";const ye=i=>a.createElement("svg",{width:24,height:24,viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg",...i},a.createElement("path",{vectorEffect:"non-scaling-stroke",d:"M2.47266 4.90002H15.1851V10.9645H21.2495L23 12.715V17.6124H20.073",stroke:"currentColor",strokeWidth:1,strokeLinecap:"round",strokeLinejoin:"round"}),a.createElement("path",{vectorEffect:"non-scaling-stroke",d:"M15.1758 5.87573H19.0019L21.0394 10.7636",stroke:"currentColor",strokeWidth:1,strokeLinecap:"round",strokeLinejoin:"round"}),a.createElement("path",{vectorEffect:"non-scaling-stroke",d:"M9.76151 16.7898C9.76151 18.0525 8.72845 19.076 7.46582 19.076C6.20318 19.076 5.17969 18.0429 5.17969 16.7803C5.17969 15.5176 6.20318 14.4941 7.46582 14.4941C8.72845 14.4941 9.75195 15.5176 9.76151 16.7803C9.76151 16.7803 9.76151 16.7803 9.76151 16.7898Z",stroke:"currentColor",strokeWidth:1,strokeLinecap:"round",strokeLinejoin:"round"}),a.createElement("path",{vectorEffect:"non-scaling-stroke",d:"M19.8726 16.7898C19.8726 18.062 18.8491 19.0855 17.5769 19.0855C16.3047 19.0855 15.2812 18.062 15.2812 16.7898C15.2812 15.5176 16.3047 14.4941 17.5769 14.4941C18.8491 14.4941 19.8726 15.5176 19.8726 16.7898Z",stroke:"currentColor",strokeWidth:1,strokeLinecap:"round",strokeLinejoin:"round"}),a.createElement("path",{vectorEffect:"non-scaling-stroke",d:"M8.08792 7.63574H1.69824",stroke:"currentColor",strokeWidth:1,strokeLinecap:"round",strokeLinejoin:"round"}),a.createElement("path",{vectorEffect:"non-scaling-stroke",d:"M7.11229 10.3619H1",stroke:"currentColor",strokeWidth:1,strokeLinecap:"round",strokeLinejoin:"round"}),a.createElement("path",{vectorEffect:"non-scaling-stroke",d:"M5.16084 13.0402H1.92773",stroke:"currentColor",strokeWidth:1,strokeLinecap:"round",strokeLinejoin:"round"}),a.createElement("path",{vectorEffect:"non-scaling-stroke",d:"M9.76172 16.7611H15.2809",stroke:"currentColor",strokeWidth:1,strokeLinecap:"round",strokeLinejoin:"round"}),a.createElement("path",{vectorEffect:"non-scaling-stroke",d:"M2.38672 16.7611H5.17025",stroke:"currentColor",strokeWidth:1,strokeLinecap:"round",strokeLinejoin:"round"})),_e=()=>V(ge,{"data-testid":"shipping-methods-skeleton",children:[n(O,{size:"small",variant:"heading"}),n(O,{size:"small",variant:"empty"}),n(O,{fullWidth:!0,size:"medium"}),n(O,{fullWidth:!0,size:"medium"})]}),We=({className:i,busy:r=!1,onSelectionChange:g=()=>{},options:v,selection:d,title:l,UIComponentType:u="RadioButton",error:h=null,onDismissError:R=()=>{},...b})=>{const S=Y({EmptyState:"Checkout.ShippingMethods.emptyState"}),E=h!==null,C=Me(null);A(()=>{E&&C.current&&Le(C.current)},[E]);const L=(o,U)=>{const M={busy:r,className:"checkout-shipping-methods__method",key:o.value,name:"shipping-method",value:o.value,onChange:()=>g(o)};return U==="RadioButton"?n(Ee,{...M,checked:(d==null?void 0:d.value)===o.value,"data-testid":"shipping-method-radioButton",description:o.title,disabled:r,id:o.value,label:V(G,{children:[n(K,{amount:o.amount.value,currency:o.amount.currency})," ",n("span",{children:o.carrier.title})]})}):n(Ce,{...M,"data-testid":"shipping-method-toggleButton",label:V(G,{children:[n("span",{children:o.carrier.title}),n(K,{amount:o.amount.value,currency:o.amount.currency})]}),selected:(d==null?void 0:d.value)===o.value})};return V("div",{...b,className:z(["checkout-shipping-methods",i]),"data-testid":"checkout-shipping-methods",children:[l&&n(le,{className:"checkout-shipping-methods__title",node:l}),n("div",{className:z(["checkout-shipping-methods__content"]),children:n("div",{className:z(["checkout-shipping-methods__options",["checkout-shipping-methods__options--busy",r],["checkout-shipping-methods__options--toggleButton",u==="ToggleButton"]]),"data-testid":"checkout-shipping-methods-options",children:v.length===0?n(ke,{"data-testid":"checkout-shipping-methods-empty",icon:n(ve,{source:ye}),message:n("p",{children:S.EmptyState})}):v.map(o=>L(o,u))})}),E&&n("div",{ref:C,className:"checkout-shipping-methods__error","data-testid":"checkout-shipping-methods-alert",children:n(Se,{heading:h,type:"error",variant:"primary",onDismiss:R})})]})},je=fe(We,_e);function N(i,r){return i?r.some(g=>P(g,i)):!1}function P(i,r){return!i||!r||i.amount.value!==r.amount.value?!1:i.code===r.code&&i.carrier.code===r.carrier.code}function Be(i){const r=B.lastPayload("shipping/estimate");r&&B.emit("shipping/estimate",{...r,shippingMethod:pe(i)})}const Je=({UIComponentType:i="RadioButton",active:r=!0,autoSync:g=!0,displayTitle:v=!0,initialData:d,slots:l,onCartSyncError:u,onSelectionChange:h,...R})=>{const[b,S]=T(null),[E,C]=T(!1),[L,o]=T(),[U,M]=T(null),ee=ce.value,te=ae.value,{cartSyncError:Z,defaultTitle:q}=Y({cartSyncError:"Checkout.ShippingMethods.cartSyncError",defaultTitle:"Checkout.ShippingMethods.title"}),w=p(e=>{if(!e||e.length===0)return[];const{shipping:t}=J.getConfig();return t!=null&&t.filterOptions?e.filter(t.filterOptions):e},[]),F=p(e=>{if(e.length===0)return null;const{defaults:t}=J.getConfig();return t.selectedShippingMethod(e)},[]),re=X(()=>w(L),[L,w]),ne=p(()=>{S(null)},[]),c=p(e=>{S(null),M(t=>P(t,e)?t:(he({selectedShippingMethod:e}),e))},[]),y=p(async(e,t)=>{if(!g||!D())return;const s={carrierCode:e.carrier.code,methodCode:e.code};me([s]).catch(m=>{c(t??null),u==null||u({method:e,error:m}),u||S(Z)})},[g,c,u,Z]),oe=p(async e=>{const t=I("selectedShippingMethod");c(e),h==null||h(e),D()||Be(e),await y(e,t)},[h,c,y]),_=p(e=>{var $;const t=!e||e.isEmpty,s=!!(e!=null&&e.isVirtual);if(t||s){C(s),c(null),o([]);return}const m=($=e.shippingAddresses)==null?void 0:$[0];if(!m)return;const W=m.availableShippingMethods??[],j=w(W);if(o(W),j.length===0){c(null);return}const f=m.selectedShippingMethod??null,k=I("selectedShippingMethod"),x=N(k,j),se=P(k,f);if(k&&x&&!se){y(k,f);return}if((!k||!x)&&f&&N(f,j)){c(f);return}if((!k||!x)&&(!f||!N(f,j))){const H=F(j);c(H),H&&y(H)}},[w,F,c,y]),Q=p(e=>{if(e===void 0)return;const{shippingMethod:t,availableShippingMethods:s}=e,m=(s==null?void 0:s.find(W=>W.code===(t==null?void 0:t.methodCode)&&W.carrier.code===(t==null?void 0:t.carrierCode)))??null;o(s),c(m)},[c]);A(()=>{if(!r)return;const e=de();if(e){const s=I("selectedShippingMethod");s&&M(s),_(e);return}const t=B.on("checkout/initialized",_,{eager:!0});return()=>{t==null||t.off()}},[r,_]),A(()=>{if(!r)return;const e=B.on("checkout/updated",_,{eager:!1});return()=>{e==null||e.off()}},[r,_]),A(()=>{if(!r||D())return;const e=B.on("shipping/estimate",Q,{eager:!0});return()=>{e==null||e.off()}},[r,Q]);const ie=X(()=>{if(v)return n(ue,{name:"checkout-shipping-methods-title",slot:l==null?void 0:l.Title,children:n("h3",{children:q})})},[v,l==null?void 0:l.Title,q]);return n(je,{...R,UIComponentType:i,busy:ee||te,error:b,initialized:L!==void 0,options:re,selection:U,title:ie,visible:r&&!E,onDismissError:ne,onSelectionChange:oe})};export{Je as ShippingMethods,Je as default,Be as emitShippingEstimateEvent};
|
|
4
4
|
//# sourceMappingURL=ShippingMethods.js.map
|