@simpleapps-com/augur-hooks 2.2.29 → 2.3.1
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/EXPORTS.md +28 -9
- package/README.md +20 -25
- package/dist/{cart-pricing-CTMlA3nE.d.cts → batch-query-CTlvxSmL.d.cts} +3 -35
- package/dist/{cart-pricing-CTMlA3nE.d.ts → batch-query-CTlvxSmL.d.ts} +3 -35
- package/dist/checkout/index.cjs +110 -39
- package/dist/checkout/index.cjs.map +1 -1
- package/dist/checkout/index.d.cts +55 -6
- package/dist/checkout/index.d.ts +55 -6
- package/dist/checkout/index.js +87 -16
- package/dist/checkout/index.js.map +1 -1
- package/dist/chunk-6Z6JGK2C.cjs +41 -0
- package/dist/chunk-6Z6JGK2C.cjs.map +1 -0
- package/dist/chunk-D5C6WWFO.js +41 -0
- package/dist/chunk-D5C6WWFO.js.map +1 -0
- package/dist/{chunk-XLBU5PCT.cjs → chunk-I4A5L2I6.cjs} +3 -2
- package/dist/chunk-I4A5L2I6.cjs.map +1 -0
- package/dist/{chunk-5YN2RPZ4.js → chunk-NRWH2BMN.js} +3 -2
- package/dist/{chunk-5YN2RPZ4.js.map → chunk-NRWH2BMN.js.map} +1 -1
- package/dist/index.cjs +12 -18
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +4 -45
- package/dist/index.d.ts +4 -45
- package/dist/index.js +2 -8
- package/dist/index.js.map +1 -1
- package/dist/server.cjs +3 -9
- package/dist/server.cjs.map +1 -1
- package/dist/server.d.cts +1 -2
- package/dist/server.d.ts +1 -2
- package/dist/server.js +3 -9
- package/dist/server.js.map +1 -1
- package/dist/{use-payment-flow-u8RwBTbO.d.ts → use-order-readiness-DZTIfRzw.d.cts} +48 -1
- package/dist/{use-payment-flow-u8RwBTbO.d.cts → use-order-readiness-DZTIfRzw.d.ts} +48 -1
- package/llms.txt +31 -22
- package/package.json +3 -3
- package/dist/chunk-GHON6UMJ.js +0 -144
- package/dist/chunk-GHON6UMJ.js.map +0 -1
- package/dist/chunk-XJJ6DZDK.cjs +0 -144
- package/dist/chunk-XJJ6DZDK.cjs.map +0 -1
- package/dist/chunk-XLBU5PCT.cjs.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/home/runner/work/augur-packages/augur-packages/packages/augur-hooks/dist/checkout/index.cjs","../../src/checkout/create-checkout-provider.tsx"],"names":["value"],"mappings":"AAAA;AACE;AACA;AACA;AACA;AACA;AACF,yDAA8B;AAC9B;AACA;ACNA;AACE;AACA;AACA;AACA;AACA;AACA;AAAA,8BAEK;AAqkBI,+CAAA;AApjBJ,IAAM,uBAAA,EAAyB,mBAAA;AAGtC,SAAS,eAAA,CAAgB,GAAA,EAAmB;AAC1C,EAAA,MAAA,CAAO,QAAA,CAAS,KAAA,EAAO,GAAA;AACzB;AAmBA,SAAS,kBAAA,CACP,MAAA,EACA,GAAA,EACA,eAAA,EACe;AACf,EAAA,GAAA,iBAAI,MAAA,mBAAO,KAAA,6BAAO,YAAA,EAAY;AAC5B,IAAA,MAAM,MAAA,EAAQ,MAAA,CAAO,KAAA,CAAM,UAAA,CAAW,GAAG,CAAA;AACzC,IAAA,GAAA,CAAI,KAAA,EAAO,OAAO,KAAA;AAAA,EACpB;AACA,EAAA,GAAA,iBAAI,MAAA,qBAAO,KAAA,6BAAO,gBAAA,EAAgB;AAChC,IAAA,MAAM,OAAA,EAAS,MAAA,CAAO,KAAA,CAAM,cAAA,CAAe,GAAG,CAAA;AAC9C,IAAA,GAAA,CAAI,OAAA,IAAW,KAAA,EAAO,OAAO,eAAA;AAAA,EAC/B;AACA,EAAA,GAAA,CAAI,CAAC,eAAA,EAAiB,OAAO,+BAAA;AAC7B,EAAA,OAAO,IAAA;AACT;AAGA,SAAS,cAAA,CAAe,CAAA,EAAgD;AACtE,EAAA,OAAO;AAAA,IACL,eAAA,EAAiB,CAAA,CAAE,eAAA;AAAA,IACnB,cAAA,EAAgB,CAAA,CAAE,cA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,IAAA,EAAM,+BAAA,GAAc,CAAA;AAC1B,IAAA,GAAA,CAAI,CAAC,GAAA,EAAK;AACR,MAAA,MAAM,IAAI,KAAA,CAAM,oDAAoD,CAAA;AAAA,IACtE;AACA,IAAA,OAAO,GAAA;AAAA,EACT;AAEA,EAAA,OAAO,EAAE,gBAAA,EAAkB,YAAY,CAAA;AACzC;ADlMA;AACE;AACA;AACF,iHAAC","file":"/home/runner/work/augur-packages/augur-packages/packages/augur-hooks/dist/checkout/index.cjs","sourcesContent":[null,"\"use client\";\n\nimport React, {\n createContext,\n useContext,\n useState,\n useCallback,\n useEffect,\n useRef,\n type ReactElement,\n} from \"react\";\nimport { usePaymentFlow, PAYMENT_STORAGE_KEY } from \"../hooks/use-payment-flow\";\nimport type { PaymentFlowCallbacks } from \"../hooks/use-payment-flow\";\nimport { clearFromSession } from \"../hooks/use-checkout-persistence\";\nimport { useOrderReadiness } from \"../hooks/use-order-readiness\";\nimport { useCartHdrUid } from \"../stores/cart-store\";\nimport type { CustomerDocument } from \"@simpleapps-com/augur-utils\";\nimport type {\n CheckoutAddress,\n CheckoutContextValue,\n CheckoutContext,\n CheckoutPaymentModal,\n CheckoutProviderConfig,\n CheckoutProviderProps,\n} from \"./types\";\n\n/** sessionStorage key for persisted order confirmation data. */\nexport const ORDER_CONFIRMATION_KEY = \"orderConfirmation\";\n\n/** Default redirect via full page navigation. */\nfunction defaultRedirect(url: string): void {\n window.location.href = url;\n}\n\n/** Shape of the order state snapshot taken via ref. */\ninterface OrderStateSnapshot {\n shippingAddress: CheckoutAddress | undefined;\n billingAddress: CheckoutAddress | undefined;\n carrierId: string;\n shippingMethod: string | undefined;\n shippingFee: number | undefined;\n paymentMethod: string;\n taxRate: number | undefined;\n clientIp: string | undefined;\n isFreeShipping: boolean;\n identity: CheckoutProviderConfig[\"identity\"];\n unifiedPayment: unknown;\n unifiedCc: unknown;\n}\n\n/** Run pre-submit validation hooks. Returns error string or null. */\nfunction runPreSubmitChecks<TCustom extends Record<string, unknown>>(\n config: CheckoutProviderConfig<TCustom>,\n ctx: CheckoutContext<TCustom>,\n shippingAddress: CheckoutAddress | undefined,\n): string | null {\n if (config.hooks?.onValidate) {\n const error = config.hooks.onValidate(ctx);\n if (error) return error;\n }\n if (config.hooks?.onBeforeSubmit) {\n const result = config.hooks.onBeforeSubmit(ctx);\n if (result === false) return \"__cancelled__\";\n }\n if (!shippingAddress) return \"Shipping address is required.\";\n return null;\n}\n\n/** Build the order data payload from current state. */\nfunction buildOrderData(s: OrderStateSnapshot): Record<string, unknown> {\n return {\n shippingAddress: s.shippingAddress,\n billingAddress: s.billingAddress,\n carrierId: s.carrierId,\n shippingMethod: s.shippingMethod,\n shippingFee: s.shippingFee,\n paymentMethod: s.paymentMethod,\n taxRate: s.taxRate,\n clientIp: s.clientIp,\n isFreeShipping: s.isFreeShipping,\n customerId: s.identity?.customerId,\n contactId: s.identity?.contactId,\n companyId: s.identity?.companyId,\n userId: s.identity?.userId,\n userEmail: s.identity?.userEmail,\n unifiedPayment: s.unifiedPayment,\n unifiedCc: s.unifiedCc,\n };\n}\n\n/** Handle order submission failure. */\nfunction handleOrderError<TCustom extends Record<string, unknown>>(\n config: CheckoutProviderConfig<TCustom>,\n setProcessingOrder: (v: boolean) => void,\n error: unknown,\n): void {\n setProcessingOrder(false);\n const message = error instanceof Error ? error.message : \"Something went wrong.\";\n config.ui?.onError?.(\"Order Failed\", message);\n}\n\n/** Coerce cartHdrUid from store (string | number | undefined) to number. */\nfunction resolveCartHdrUid(cartHdrUid: number | string | undefined): number {\n if (typeof cartHdrUid === \"string\") return Number(cartHdrUid);\n return cartHdrUid ?? 0;\n}\n\n/** Build order payload via assembleOrder hook or fallback to buildOrderData. */\nfunction assembleOrderPayload<TCustom extends Record<string, unknown>>(\n config: CheckoutProviderConfig<TCustom>,\n ctx: CheckoutContext<TCustom>,\n contextValue: CheckoutContextValue<TCustom>,\n stateSnapshot: OrderStateSnapshot,\n): { orderData: Record<string, unknown>; error?: string } {\n if (config.hooks?.assembleOrder) {\n const assembled = config.hooks.assembleOrder(ctx, contextValue);\n if (assembled.error) return { orderData: {}, error: assembled.error };\n return { orderData: assembled.order };\n }\n return { orderData: buildOrderData(stateSnapshot) };\n}\n\n/** Shape of persisted order confirmation data. */\nexport interface OrderConfirmation {\n orderData: Record<string, unknown>;\n result: unknown;\n shippingAddress: CheckoutAddress | undefined;\n billingAddress: CheckoutAddress | undefined;\n shippingFee: number | undefined;\n shippingMethod: string | undefined;\n taxRate: number | undefined;\n paymentMethod: string;\n carrierId: string;\n orderCartLines: unknown[] | undefined;\n}\n\n/** Build the confirmation snapshot from checkout state + API result. */\nfunction buildOrderConfirmation(\n orderData: Record<string, unknown>,\n resultData: unknown,\n state: OrderStateSnapshot,\n orderCartLines: unknown[] | undefined,\n): OrderConfirmation {\n return {\n orderData,\n result: resultData,\n shippingAddress: state.shippingAddress,\n billingAddress: state.billingAddress,\n shippingFee: state.shippingFee,\n shippingMethod: state.shippingMethod,\n taxRate: state.taxRate,\n paymentMethod: state.paymentMethod,\n carrierId: state.carrierId,\n orderCartLines,\n };\n}\n\n/** Handle successful order submission. */\nfunction handleOrderSuccess<TCustom extends Record<string, unknown>>(\n config: CheckoutProviderConfig<TCustom>,\n ctx: CheckoutContext<TCustom>,\n resultData: unknown,\n confirmation: OrderConfirmation,\n setProcessingOrder: (v: boolean) => void,\n redirect: (url: string) => void,\n): void {\n if (config.payments?.persistence) {\n clearFromSession(PAYMENT_STORAGE_KEY);\n }\n config.hooks?.onAfterSubmit?.(ctx, resultData);\n if (config.order.persistence !== false) {\n try {\n sessionStorage.setItem(ORDER_CONFIRMATION_KEY, JSON.stringify(confirmation));\n } catch {\n // sessionStorage unavailable (private browsing, quota)\n }\n }\n redirect(config.order.successRedirect);\n setProcessingOrder(false);\n}\n\n/** Execute order submission -- extracted to reduce component complexity. */\nasync function executeOrder<TCustom extends Record<string, unknown>>(\n config: CheckoutProviderConfig<TCustom>,\n ctxRef: React.RefObject<CheckoutContext<TCustom>>,\n stateRef: React.RefObject<OrderStateSnapshot>,\n contextValueRef: React.RefObject<CheckoutContextValue<TCustom>>,\n cartHdrUid: number | string | undefined,\n setProcessingOrder: (v: boolean) => void,\n redirect: (url: string) => void,\n): Promise<void> {\n const ctx = ctxRef.current;\n const s = stateRef.current;\n\n const preCheck = runPreSubmitChecks(config, ctx, s.shippingAddress);\n if (preCheck === \"__cancelled__\") return;\n if (preCheck) {\n config.ui?.onError?.(\"Missing Information\", preCheck);\n return;\n }\n\n setProcessingOrder(true);\n\n const { orderData, error: assemblyError } = assembleOrderPayload(\n config,\n ctx,\n contextValueRef.current,\n s,\n );\n if (assemblyError) {\n setProcessingOrder(false);\n config.ui?.onError?.(\"Order Error\", assemblyError);\n return;\n }\n\n let result: { ok: boolean; data?: unknown; error?: string };\n try {\n result = await config.order.submitOrder(orderData, resolveCartHdrUid(cartHdrUid));\n } catch (error) {\n handleOrderError(config, setProcessingOrder, error);\n return;\n }\n\n if (!result.ok) {\n setProcessingOrder(false);\n config.ui?.onError?.(\"Order Failed\", result.error ?? \"Something went wrong.\");\n return;\n }\n\n const confirmation = buildOrderConfirmation(\n orderData,\n result.data,\n s,\n contextValueRef.current.orderCartLines,\n );\n handleOrderSuccess(config, ctx, result.data, confirmation, setProcessingOrder, redirect);\n}\n\n/** No-op callbacks for when payment is not configured. */\nconst NOOP_PAYMENT_CALLBACKS: PaymentFlowCallbacks = {\n transactionSetup: async () => undefined,\n cardInfo: async () => undefined,\n validatePayment: async () => undefined,\n accountQuery: async () => undefined,\n billingUpdate: async () => undefined,\n};\n\n/**\n * Creates a CheckoutProvider component and useCheckout() hook from site config.\n *\n * The package owns all state, transitions, validation, and order submission.\n * Sites own layout and inject configuration + lifecycle hooks.\n *\n * Steps are string-based -- sites define their own step names.\n * Payment flow is optional -- B2B sites without payment processing omit payments.callbacks.\n *\n * @example\n * ```ts\n * // Full checkout with payment\n * const { CheckoutProvider, useCheckout } = createCheckoutProvider({\n * shipping: { carriers: { \"100008\": \"UPS Ground\" }, defaultCarrierId: \"100008\" },\n * payments: { callbacks: { transactionSetup, cardInfo, validatePayment, accountQuery, billingUpdate } },\n * order: { successRedirect: \"/thank-you\", submitOrder },\n * });\n *\n * // B2B checkout without payment\n * const { CheckoutProvider, useCheckout } = createCheckoutProvider({\n * shipping: { carriers: { \"100008\": \"UPS Ground\" }, defaultCarrierId: \"100008\" },\n * order: { successRedirect: \"/thank-you\", submitOrder },\n * });\n * ```\n */\n// Single context instance at module scope. Prevents stale context references\n// when createCheckoutProvider is re-called during HMR or page navigation.\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nconst Ctx = createContext<any>(null);\n\nexport function createCheckoutProvider<\n TCustom extends Record<string, unknown> = Record<string, never>,\n>(config: CheckoutProviderConfig<TCustom>) {\n const hasPaymentFlow = !!config.payments?.callbacks;\n\n function CheckoutProvider({\n children,\n identity: propsIdentity,\n }: CheckoutProviderProps): ReactElement {\n // -- Shipping state --\n const [shippingAddress, setShippingAddress] = useState<CheckoutAddress | undefined>();\n const [shippingFee, setShippingFee] = useState<number | undefined>();\n const [shippingMethod, setShippingMethod] = useState<string | undefined>();\n const [shippingAccepted, setShippingAccepted] = useState(false);\n const [shippingMethodSaved, setShippingMethodSaved] = useState(false);\n const [isFreeShipping, setIsFreeShipping] = useState(false);\n const [carrierId, setCarrierId] = useState(config.shipping.defaultCarrierId);\n const [showShippingMethod, setShowShippingMethod] = useState(false);\n\n // -- Billing state --\n const [billingAddress, setBillingAddress] = useState<CheckoutAddress | undefined>();\n const defaultPaymentMethod = config.hooks?.getDefaultPaymentMethod?.() ?? \"credit-card\";\n const [paymentMethod, setPaymentMethod] = useState(defaultPaymentMethod);\n const [showBillingInfoSummary, setShowBillingInfoSummary] = useState(false);\n\n // -- Order state --\n const [orderCartLines, setOrderCartLines] = useState<unknown[] | undefined>();\n const [processingOrder, setProcessingOrder] = useState(false);\n const [taxRate, setTaxRate] = useState<number | undefined>(undefined);\n const [clientIp, setClientIp] = useState<string | undefined>();\n const [cartToken, setCartToken] = useState<string>(\"\");\n const [customerDoc, setCustomerDoc] = useState<CustomerDocument | null>(null);\n\n // -- Edit flags --\n const [isEditShippingInfo, setIsEditShippingInfo] = useState(false);\n const [isEditShippingMethods, setIsEditShippingMethods] = useState(false);\n const [isEditBillingInfo, setIsEditBillingInfo] = useState(false);\n\n // -- Step navigation (string-based, sites define their own steps) --\n const [currentStep, setCurrentStep] = useState<string>(config.initialStep ?? \"shipping\");\n\n // -- Custom state --\n const [customState, setCustomState] = useState<TCustom>(\n () => (config.customState ?? {}) as TCustom,\n );\n\n const setCustomField = useCallback(<K extends keyof TCustom>(key: K, value: TCustom[K]) => {\n setCustomState((prev) => ({ ...prev, [key]: value }));\n }, []);\n\n // -- Identity (props override config for runtime hook values) --\n const identity = propsIdentity ?? config.identity;\n const payment = usePaymentFlow({\n callbacks: config.payments?.callbacks ?? NOOP_PAYMENT_CALLBACKS,\n customerId: identity?.customerId,\n billingAddress,\n paymentMethod,\n shippingAccepted,\n persistPayment: config.payments?.persistence,\n });\n\n const paymentModal: CheckoutPaymentModal | undefined = hasPaymentFlow\n ? {\n isOpen: payment.isOpen,\n setIsOpen: payment.setIsOpen,\n editCc: payment.editCc,\n setEditCc: payment.setEditCc,\n unified: payment.unified,\n unifiedCc: payment.unifiedCc,\n unifiedResponse: payment.unifiedResponse,\n unifiedBilling: payment.unifiedBilling,\n unifiedPayment: payment.unifiedPayment,\n handleBinCapture: payment.handleBinCapture,\n hasValidPayment: !!payment.unifiedPayment?.PaymentAccountID,\n }\n : undefined;\n\n // -- Lifecycle context (passed to hooks) --\n const ctxRef = useRef<CheckoutContext<TCustom>>(null!);\n ctxRef.current = {\n get: <K extends keyof TCustom>(key: K) => customState[key],\n set: setCustomField,\n skipToStep: setCurrentStep,\n setBillingAddress,\n setCarrierId,\n };\n\n // -- Edit flag transitions --\n const handleSetIsEditShippingInfo = useCallback((editing: boolean) => {\n setIsEditShippingInfo(editing);\n if (editing) {\n setShippingMethodSaved(false);\n setShowShippingMethod(false);\n }\n }, []);\n\n const handleSetIsEditShippingMethods = useCallback((editing: boolean) => {\n setIsEditShippingMethods(editing);\n if (editing) {\n setShippingMethodSaved(false);\n }\n }, []);\n\n // -- Step transitions with lifecycle hook --\n const goToStep = useCallback(\n (step: string) => {\n const from = currentStep;\n if (config.hooks?.onStepChange) {\n config.hooks.onStepChange(ctxRef.current, from, step);\n }\n setCurrentStep(step);\n },\n [currentStep],\n );\n\n // -- Cart store integration --\n const cartHdrUid = useCartHdrUid();\n\n // -- Order readiness --\n const { enableProcessOrderBtn, processingValidation } = useOrderReadiness({\n cartHdrUid,\n shippingAddress,\n billingAddress,\n shippingMethodSaved,\n showBillingInfoSummary,\n processingOrder,\n paymentMethod,\n unifiedPaymentAccountId: payment.unifiedPayment?.PaymentAccountID,\n unifiedBilling: payment.unifiedBilling,\n isFreeShipping,\n carrierId,\n shippingFee,\n isEditShippingInfo,\n isEditShippingMethods,\n isEditBillingInfo,\n editCc: payment.editCc,\n });\n\n // -- Effects: data fetching on mount --\n\n useEffect(() => {\n if (config.order.fetchClientIp) {\n void config.order.fetchClientIp().then(setClientIp);\n }\n }, []);\n\n useEffect(() => {\n const custId = identity?.customerId;\n if (custId && identity?.fetchCustomerDoc) {\n void identity\n .fetchCustomerDoc(custId)\n .then(setCustomerDoc)\n .catch(() => setCustomerDoc(null));\n }\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [identity?.customerId]);\n\n // -- Effect: tax calculation when billing address changes --\n useEffect(() => {\n if (!config.order.calculateTax || !billingAddress?.postalCode) return;\n void config.order\n .calculateTax({\n customerId: identity?.customerId,\n postalCode: billingAddress.postalCode,\n items: orderCartLines ?? [],\n customerDoc,\n })\n .then((tax) => {\n if (tax !== undefined) setTaxRate(tax);\n });\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [billingAddress?.postalCode, orderCartLines]);\n\n // -- Effect: auto-copy shipping to billing (default \"same as shipping\") --\n useEffect(() => {\n if (shippingAccepted && shippingAddress && !billingAddress) {\n setBillingAddress(shippingAddress);\n }\n }, [shippingAccepted, shippingAddress, billingAddress]);\n\n // -- Effect: fire onShippingAccepted lifecycle hook --\n useEffect(() => {\n if (config.hooks?.onShippingAccepted && shippingAccepted && shippingAddress) {\n config.hooks.onShippingAccepted(ctxRef.current, shippingAddress, orderCartLines ?? []);\n }\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [shippingAccepted, shippingAddress]);\n\n // -- Effect: cart token from cookie --\n useEffect(() => {\n if (typeof document === \"undefined\") return;\n const cookies = document.cookie.split(\";\");\n const match = cookies.find((c) => c.trim().startsWith(\"cartToken=\"));\n if (match) {\n const token = match.split(\"=\")[1];\n if (token) setCartToken(token);\n }\n }, []);\n\n // -- Order submission with double-submit prevention --\n\n const resetProcessing = useCallback(() => setProcessingOrder(false), []);\n\n const isProcessingRef = useRef(false);\n\n const orderStateRef = useRef<OrderStateSnapshot>({\n shippingAddress,\n billingAddress,\n carrierId,\n shippingMethod,\n shippingFee,\n paymentMethod,\n taxRate,\n clientIp,\n isFreeShipping,\n identity,\n unifiedPayment: payment.unifiedPayment,\n unifiedCc: payment.unifiedCc,\n });\n orderStateRef.current = {\n shippingAddress,\n billingAddress,\n carrierId,\n shippingMethod,\n shippingFee,\n paymentMethod,\n taxRate,\n clientIp,\n isFreeShipping,\n identity,\n unifiedPayment: payment.unifiedPayment,\n unifiedCc: payment.unifiedCc,\n };\n\n const contextValueRef = useRef<CheckoutContextValue<TCustom>>(null!);\n\n const redirect = useCallback((url: string) => {\n if (config.order.redirect) {\n config.order.redirect(url);\n } else {\n defaultRedirect(url);\n }\n }, []);\n\n const processOrder = useCallback(async () => {\n if (isProcessingRef.current) return;\n isProcessingRef.current = true;\n try {\n await executeOrder(\n config,\n ctxRef,\n orderStateRef,\n contextValueRef,\n cartHdrUid,\n setProcessingOrder,\n redirect,\n );\n } finally {\n isProcessingRef.current = false;\n }\n }, [cartHdrUid, redirect]);\n\n // -- Context value --\n const value: CheckoutContextValue<TCustom> = {\n shippingAddress,\n setShippingAddress,\n shippingFee,\n setShippingFee,\n shippingMethod,\n setShippingMethod,\n shippingAccepted,\n setShippingAccepted,\n shippingMethodSaved,\n setShippingMethodSaved,\n isFreeShipping,\n setIsFreeShipping,\n carrierId,\n setCarrierId,\n showShippingMethod,\n setShowShippingMethod,\n billingAddress,\n setBillingAddress,\n paymentMethod,\n setPaymentMethod,\n showBillingInfoSummary,\n setShowBillingInfoSummary,\n paymentModal,\n orderCartLines,\n setOrderCartLines,\n processingOrder,\n processOrder,\n resetProcessing,\n customerDoc,\n taxRate,\n setTaxRate,\n clientIp,\n cartToken,\n isEditShippingInfo,\n setIsEditShippingInfo: handleSetIsEditShippingInfo,\n isEditShippingMethods,\n setIsEditShippingMethods: handleSetIsEditShippingMethods,\n isEditBillingInfo,\n setIsEditBillingInfo,\n enableProcessOrderBtn,\n processingValidation,\n currentStep,\n goToStep,\n custom: customState,\n setCustom: setCustomField,\n config,\n };\n\n contextValueRef.current = value;\n\n return <Ctx.Provider value={value}>{children}</Ctx.Provider>;\n }\n\n /** Access checkout state from any child of CheckoutProvider. */\n function useCheckout(): CheckoutContextValue<TCustom> {\n const ctx = useContext(Ctx);\n if (!ctx) {\n throw new Error(\"useCheckout must be used within a CheckoutProvider\");\n }\n return ctx;\n }\n\n return { CheckoutProvider, useCheckout };\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["/home/runner/work/augur-packages/augur-packages/packages/augur-hooks/dist/checkout/index.cjs","../../src/checkout/create-checkout-provider.tsx"],"names":["value"],"mappings":"AAAA;AACE;AACA;AACA;AACA;AACA;AACA;AACA;AACF,yDAA8B;AAC9B;AACA;ACRA;AACE;AACA;AACA;AACA;AACA;AACA;AAAA,8BAEK;AACP,mDAAiD;AA2sBtC,+CAAA;AAzrBJ,IAAM,uBAAA,EAAyB,mBAAA;AAGtC,SAAS,eAAA,CAAgB,GAAA,EAAmB;AAC1C,EAAA,MAAA,CAAO,QAAA,CAAS,KAAA,EAA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F,iHAAC","file":"/home/runner/work/augur-packages/augur-packages/packages/augur-hooks/dist/checkout/index.cjs","sourcesContent":[null,"\"use client\";\n\nimport React, {\n createContext,\n useContext,\n useState,\n useCallback,\n useEffect,\n useRef,\n type ReactElement,\n} from \"react\";\nimport { useQueryClient, type QueryClient } from \"@tanstack/react-query\";\nimport { usePaymentFlow, PAYMENT_STORAGE_KEY } from \"../hooks/use-payment-flow\";\nimport type { PaymentFlowCallbacks } from \"../hooks/use-payment-flow\";\nimport { clearFromSession } from \"../hooks/use-checkout-persistence\";\nimport { useOrderReadiness } from \"../hooks/use-order-readiness\";\nimport type { OrderReadinessParams } from \"../hooks/use-order-readiness\";\nimport { useCartHdrUid, useCartLines, useClearCart } from \"../stores/cart-store\";\nimport type { CustomerDocument } from \"@simpleapps-com/augur-utils\";\nimport type {\n CheckoutAddress,\n CheckoutContextValue,\n CheckoutContext,\n CheckoutPaymentModal,\n CheckoutProviderConfig,\n CheckoutProviderProps,\n} from \"./types\";\n\n/** sessionStorage key for persisted order confirmation data. */\nexport const ORDER_CONFIRMATION_KEY = \"orderConfirmation\";\n\n/** Default redirect via full page navigation. */\nfunction defaultRedirect(url: string): void {\n window.location.href = url;\n}\n\n/** Shape of the order state snapshot taken via ref. */\ninterface OrderStateSnapshot {\n shippingAddress: CheckoutAddress | undefined;\n billingAddress: CheckoutAddress | undefined;\n carrierId: string;\n shippingMethod: string | undefined;\n shippingFee: number | undefined;\n paymentMethod: string;\n taxRate: number | undefined;\n clientIp: string | undefined;\n isFreeShipping: boolean;\n identity: CheckoutProviderConfig[\"identity\"];\n unifiedPayment: unknown;\n unifiedCc: unknown;\n}\n\n/** Run pre-submit validation hooks. Returns error string or null. */\nfunction runPreSubmitChecks<TCustom extends Record<string, unknown>>(\n config: CheckoutProviderConfig<TCustom>,\n ctx: CheckoutContext<TCustom>,\n shippingAddress: CheckoutAddress | undefined,\n): string | null {\n if (config.hooks?.onValidate) {\n const error = config.hooks.onValidate(ctx);\n if (error) return error;\n }\n if (config.hooks?.onBeforeSubmit) {\n const result = config.hooks.onBeforeSubmit(ctx);\n if (result === false) return \"__cancelled__\";\n }\n if (!shippingAddress) return \"Shipping address is required.\";\n return null;\n}\n\n/** Build the order data payload from current state. */\nfunction buildOrderData(s: OrderStateSnapshot): Record<string, unknown> {\n return {\n shippingAddress: s.shippingAddress,\n billingAddress: s.billingAddress,\n carrierId: s.carrierId,\n shippingMethod: s.shippingMethod,\n shippingFee: s.shippingFee,\n paymentMethod: s.paymentMethod,\n taxRate: s.taxRate,\n clientIp: s.clientIp,\n isFreeShipping: s.isFreeShipping,\n customerId: s.identity?.customerId,\n contactId: s.identity?.contactId,\n companyId: s.identity?.companyId,\n userId: s.identity?.userId,\n userEmail: s.identity?.userEmail,\n unifiedPayment: s.unifiedPayment,\n unifiedCc: s.unifiedCc,\n };\n}\n\n/** Handle order submission failure. */\nfunction handleOrderError<TCustom extends Record<string, unknown>>(\n config: CheckoutProviderConfig<TCustom>,\n setProcessingOrder: (v: boolean) => void,\n error: unknown,\n): void {\n setProcessingOrder(false);\n const message = error instanceof Error ? error.message : \"Something went wrong.\";\n config.ui?.onError?.(\"Order Failed\", message);\n}\n\n/** Coerce cartHdrUid from store (string | number | undefined) to number. */\nfunction resolveCartHdrUid(cartHdrUid: number | string | undefined): number {\n if (typeof cartHdrUid === \"string\") return Number(cartHdrUid);\n return cartHdrUid ?? 0;\n}\n\n/**\n * Resolve the initial payment method. Honors `hooks.getDefaultPaymentMethod`\n * when provided; otherwise falls back to `\"credit-card\"` when payment\n * processing is configured and `\"invoice\"` when it is not.\n */\nfunction resolveDefaultPaymentMethod<TCustom extends Record<string, unknown>>(\n config: CheckoutProviderConfig<TCustom>,\n): string {\n const explicit = config.hooks?.getDefaultPaymentMethod?.();\n if (explicit) return explicit;\n return config.payments?.callbacks ? \"credit-card\" : \"invoice\";\n}\n\n/**\n * Build the `customReadinessCheck` adapter for useOrderReadiness from the\n * site's `hooks.isOrderReady`. Returns `undefined` when no site hook is\n * provided so useOrderReadiness runs its default gates.\n */\nfunction buildReadinessOverride<TCustom extends Record<string, unknown>>(\n config: CheckoutProviderConfig<TCustom>,\n ctxRef: React.RefObject<CheckoutContext<TCustom>>,\n): ((params: OrderReadinessParams) => boolean | undefined) | undefined {\n const siteIsOrderReady = config.hooks?.isOrderReady;\n if (!siteIsOrderReady) return undefined;\n return (params) => siteIsOrderReady(ctxRef.current, params);\n}\n\n/** Build order payload via assembleOrder hook or fallback to buildOrderData. */\nfunction assembleOrderPayload<TCustom extends Record<string, unknown>>(\n config: CheckoutProviderConfig<TCustom>,\n ctx: CheckoutContext<TCustom>,\n contextValue: CheckoutContextValue<TCustom>,\n stateSnapshot: OrderStateSnapshot,\n): { orderData: Record<string, unknown>; error?: string } {\n if (config.hooks?.assembleOrder) {\n const assembled = config.hooks.assembleOrder(ctx, contextValue);\n if (assembled.error) return { orderData: {}, error: assembled.error };\n return { orderData: assembled.order };\n }\n return { orderData: buildOrderData(stateSnapshot) };\n}\n\n/**\n * Validate the minimum viable shape of an assembled order payload.\n *\n * Returns an error message when the payload is obviously broken, or `null`\n * when it passes. Invariants are conditional on key presence so sites using\n * the legacy `oe_hdr`/`oe_line` payload shape (or any shape without top-level\n * `lines`/`header`) pass through unchecked.\n *\n * Enforced invariants:\n * - `orderData` MUST be a non-null, non-array object.\n * - If `orderData.lines` is present, it MUST be a non-empty array.\n * - If `orderData.header` is present and is an object, it MUST include a\n * non-empty `customer_id`.\n */\nfunction validateOrderPayload(orderData: Record<string, unknown>): string | null {\n if (orderData === null || typeof orderData !== \"object\" || Array.isArray(orderData)) {\n return \"Order payload is empty or malformed.\";\n }\n\n if (\"lines\" in orderData) {\n const lines = orderData[\"lines\"];\n if (!Array.isArray(lines) || lines.length === 0) {\n return \"Order has no line items.\";\n }\n }\n\n if (\"header\" in orderData) {\n const header = orderData[\"header\"];\n if (header !== null && typeof header === \"object\" && !Array.isArray(header)) {\n const customerId = (header as Record<string, unknown>)[\"customer_id\"];\n if (customerId == null || String(customerId).trim() === \"\") {\n return \"Order is missing a customer.\";\n }\n }\n }\n\n return null;\n}\n\n/**\n * Assemble and validate the order payload. Surfaces any failure via\n * `config.ui.onError` + `setProcessingOrder(false)`, and additionally logs\n * the offending payload to `console.error` on validation failure. Returns\n * `null` when the payload was not produced or was rejected; returns the\n * `orderData` ready for `submitOrder` otherwise.\n */\nfunction prepareOrderPayload<TCustom extends Record<string, unknown>>(\n config: CheckoutProviderConfig<TCustom>,\n ctx: CheckoutContext<TCustom>,\n contextValue: CheckoutContextValue<TCustom>,\n stateSnapshot: OrderStateSnapshot,\n setProcessingOrder: (v: boolean) => void,\n): Record<string, unknown> | null {\n const { orderData, error: assemblyError } = assembleOrderPayload(\n config,\n ctx,\n contextValue,\n stateSnapshot,\n );\n if (assemblyError) {\n setProcessingOrder(false);\n config.ui?.onError?.(\"Order Error\", assemblyError);\n return null;\n }\n\n const validationError = validateOrderPayload(orderData);\n if (validationError) {\n console.error(\"Order payload validation failed:\", orderData);\n setProcessingOrder(false);\n config.ui?.onError?.(\"Order Error\", validationError);\n return null;\n }\n\n return orderData;\n}\n\n/** Shape of persisted order confirmation data. */\nexport interface OrderConfirmation {\n orderData: Record<string, unknown>;\n result: unknown;\n shippingAddress: CheckoutAddress | undefined;\n billingAddress: CheckoutAddress | undefined;\n shippingFee: number | undefined;\n shippingMethod: string | undefined;\n taxRate: number | undefined;\n paymentMethod: string;\n carrierId: string;\n orderCartLines: unknown[] | undefined;\n}\n\n/** Build the confirmation snapshot from checkout state + API result. */\nfunction buildOrderConfirmation(\n orderData: Record<string, unknown>,\n resultData: unknown,\n state: OrderStateSnapshot,\n orderCartLines: unknown[] | undefined,\n): OrderConfirmation {\n return {\n orderData,\n result: resultData,\n shippingAddress: state.shippingAddress,\n billingAddress: state.billingAddress,\n shippingFee: state.shippingFee,\n shippingMethod: state.shippingMethod,\n taxRate: state.taxRate,\n paymentMethod: state.paymentMethod,\n carrierId: state.carrierId,\n orderCartLines,\n };\n}\n\n/**\n * Handle successful order submission.\n *\n * After running the site's `onAfterSubmit` hook and persisting the order\n * confirmation snapshot, the package clears its own client-side cart state:\n * the zustand cart store is reset, and the cart-related React Query caches\n * (`cartLines`, `cart-also-bought`, and the proxy-shape `commerce.cartLine`)\n * are invalidated so any subsequent page mount refetches from the server.\n * The redirect fires last. Sites retain responsibility for backend cart\n * cleanup inside `onAfterSubmit` or their `submitOrder` wrapper.\n */\nfunction handleOrderSuccess<TCustom extends Record<string, unknown>>(\n config: CheckoutProviderConfig<TCustom>,\n ctx: CheckoutContext<TCustom>,\n resultData: unknown,\n confirmation: OrderConfirmation,\n setProcessingOrder: (v: boolean) => void,\n redirect: (url: string) => void,\n queryClient: QueryClient,\n clearCart: () => void,\n): void {\n if (config.payments?.persistence) {\n clearFromSession(PAYMENT_STORAGE_KEY);\n }\n config.hooks?.onAfterSubmit?.(ctx, resultData);\n if (config.order.persistence !== false) {\n try {\n sessionStorage.setItem(ORDER_CONFIRMATION_KEY, JSON.stringify(confirmation));\n } catch {\n // sessionStorage unavailable (private browsing, quota)\n }\n }\n clearCart();\n void queryClient.invalidateQueries({ queryKey: [\"cartLines\"] });\n void queryClient.invalidateQueries({ queryKey: [\"cart-also-bought\"] });\n void queryClient.invalidateQueries({ queryKey: [\"commerce\", \"cartLine\"] });\n redirect(config.order.successRedirect);\n setProcessingOrder(false);\n}\n\n/** Execute order submission -- extracted to reduce component complexity. */\nasync function executeOrder<TCustom extends Record<string, unknown>>(\n config: CheckoutProviderConfig<TCustom>,\n ctxRef: React.RefObject<CheckoutContext<TCustom>>,\n stateRef: React.RefObject<OrderStateSnapshot>,\n contextValueRef: React.RefObject<CheckoutContextValue<TCustom>>,\n cartHdrUid: number | string | undefined,\n setProcessingOrder: (v: boolean) => void,\n redirect: (url: string) => void,\n queryClient: QueryClient,\n clearCart: () => void,\n): Promise<void> {\n const ctx = ctxRef.current;\n const s = stateRef.current;\n\n const preCheck = runPreSubmitChecks(config, ctx, s.shippingAddress);\n if (preCheck === \"__cancelled__\") return;\n if (preCheck) {\n config.ui?.onError?.(\"Missing Information\", preCheck);\n return;\n }\n\n setProcessingOrder(true);\n\n const orderData = prepareOrderPayload(\n config,\n ctx,\n contextValueRef.current,\n s,\n setProcessingOrder,\n );\n if (!orderData) return;\n\n let result: { ok: boolean; data?: unknown; error?: string };\n try {\n result = await config.order.submitOrder(orderData, resolveCartHdrUid(cartHdrUid));\n } catch (error) {\n handleOrderError(config, setProcessingOrder, error);\n return;\n }\n\n if (!result.ok) {\n setProcessingOrder(false);\n config.ui?.onError?.(\"Order Failed\", result.error ?? \"Something went wrong.\");\n return;\n }\n\n const confirmation = buildOrderConfirmation(\n orderData,\n result.data,\n s,\n contextValueRef.current.orderCartLines,\n );\n handleOrderSuccess(\n config,\n ctx,\n result.data,\n confirmation,\n setProcessingOrder,\n redirect,\n queryClient,\n clearCart,\n );\n}\n\n/** No-op callbacks for when payment is not configured. */\nconst NOOP_PAYMENT_CALLBACKS: PaymentFlowCallbacks = {\n transactionSetup: async () => undefined,\n cardInfo: async () => undefined,\n validatePayment: async () => undefined,\n accountQuery: async () => undefined,\n billingUpdate: async () => undefined,\n};\n\n/**\n * Creates a CheckoutProvider component and useCheckout() hook from site config.\n *\n * The package owns all state, transitions, validation, and order submission.\n * Sites own layout and inject configuration + lifecycle hooks.\n *\n * Steps are string-based -- sites define their own step names.\n * Payment flow is optional -- B2B sites without payment processing omit payments.callbacks.\n *\n * @example\n * ```ts\n * // Full checkout with payment\n * const { CheckoutProvider, useCheckout } = createCheckoutProvider({\n * shipping: { carriers: { \"100008\": \"UPS Ground\" }, defaultCarrierId: \"100008\" },\n * payments: { callbacks: { transactionSetup, cardInfo, validatePayment, accountQuery, billingUpdate } },\n * order: { successRedirect: \"/thank-you\", submitOrder },\n * });\n *\n * // B2B checkout without payment\n * const { CheckoutProvider, useCheckout } = createCheckoutProvider({\n * shipping: { carriers: { \"100008\": \"UPS Ground\" }, defaultCarrierId: \"100008\" },\n * order: { successRedirect: \"/thank-you\", submitOrder },\n * });\n * ```\n */\n// Single context instance at module scope. Prevents stale context references\n// when createCheckoutProvider is re-called during HMR or page navigation.\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nconst Ctx = createContext<any>(null);\n\nexport function createCheckoutProvider<\n TCustom extends Record<string, unknown> = Record<string, never>,\n>(config: CheckoutProviderConfig<TCustom>) {\n const hasPaymentFlow = !!config.payments?.callbacks;\n\n function CheckoutProvider({\n children,\n identity: propsIdentity,\n }: CheckoutProviderProps): ReactElement {\n // -- Shipping state --\n const [shippingAddress, setShippingAddress] = useState<CheckoutAddress | undefined>();\n const [shippingFee, setShippingFee] = useState<number | undefined>();\n const [shippingMethod, setShippingMethod] = useState<string | undefined>();\n const [shippingAccepted, setShippingAccepted] = useState(false);\n const [shippingMethodSaved, setShippingMethodSaved] = useState(false);\n const [isFreeShipping, setIsFreeShipping] = useState(false);\n const [carrierId, setCarrierId] = useState(config.shipping.defaultCarrierId);\n const [showShippingMethod, setShowShippingMethod] = useState(false);\n\n // -- Billing state --\n const [billingAddress, setBillingAddress] = useState<CheckoutAddress | undefined>();\n const [paymentMethod, setPaymentMethod] = useState(() => resolveDefaultPaymentMethod(config));\n const [showBillingInfoSummary, setShowBillingInfoSummary] = useState(false);\n\n // -- Order state --\n const [orderCartLines, setOrderCartLines] = useState<unknown[] | undefined>();\n const [processingOrder, setProcessingOrder] = useState(false);\n const [taxRate, setTaxRate] = useState<number | undefined>(undefined);\n const [clientIp, setClientIp] = useState<string | undefined>();\n const [cartToken, setCartToken] = useState<string>(\"\");\n const [customerDoc, setCustomerDoc] = useState<CustomerDocument | null>(null);\n\n // -- Edit flags --\n const [isEditShippingInfo, setIsEditShippingInfo] = useState(false);\n const [isEditShippingMethods, setIsEditShippingMethods] = useState(false);\n const [isEditBillingInfo, setIsEditBillingInfo] = useState(false);\n\n // -- Step navigation (string-based, sites define their own steps) --\n const [currentStep, setCurrentStep] = useState<string>(config.initialStep ?? \"shipping\");\n\n // -- Custom state --\n const [customState, setCustomState] = useState<TCustom>(\n () => (config.customState ?? {}) as TCustom,\n );\n\n const setCustomField = useCallback(<K extends keyof TCustom>(key: K, value: TCustom[K]) => {\n setCustomState((prev) => ({ ...prev, [key]: value }));\n }, []);\n\n // -- Identity (props override config for runtime hook values) --\n const identity = propsIdentity ?? config.identity;\n const payment = usePaymentFlow({\n callbacks: config.payments?.callbacks ?? NOOP_PAYMENT_CALLBACKS,\n customerId: identity?.customerId,\n billingAddress,\n paymentMethod,\n shippingAccepted,\n persistPayment: config.payments?.persistence,\n });\n\n const paymentModal: CheckoutPaymentModal | undefined = hasPaymentFlow\n ? {\n isOpen: payment.isOpen,\n setIsOpen: payment.setIsOpen,\n editCc: payment.editCc,\n setEditCc: payment.setEditCc,\n unified: payment.unified,\n unifiedCc: payment.unifiedCc,\n unifiedResponse: payment.unifiedResponse,\n unifiedBilling: payment.unifiedBilling,\n unifiedPayment: payment.unifiedPayment,\n handleBinCapture: payment.handleBinCapture,\n hasValidPayment: !!payment.unifiedPayment?.PaymentAccountID,\n }\n : undefined;\n\n // -- Lifecycle context (passed to hooks) --\n const ctxRef = useRef<CheckoutContext<TCustom>>(null!);\n ctxRef.current = {\n get: <K extends keyof TCustom>(key: K) => customState[key],\n set: setCustomField,\n skipToStep: setCurrentStep,\n setBillingAddress,\n setCarrierId,\n };\n\n // -- Edit flag transitions --\n const handleSetIsEditShippingInfo = useCallback((editing: boolean) => {\n setIsEditShippingInfo(editing);\n if (editing) {\n setShippingMethodSaved(false);\n setShowShippingMethod(false);\n }\n }, []);\n\n const handleSetIsEditShippingMethods = useCallback((editing: boolean) => {\n setIsEditShippingMethods(editing);\n if (editing) {\n setShippingMethodSaved(false);\n }\n }, []);\n\n // -- Step transitions with lifecycle hook --\n const goToStep = useCallback(\n (step: string) => {\n const from = currentStep;\n if (config.hooks?.onStepChange) {\n config.hooks.onStepChange(ctxRef.current, from, step);\n }\n setCurrentStep(step);\n },\n [currentStep],\n );\n\n // -- Cart store integration --\n const cartHdrUid = useCartHdrUid();\n const cartLines = useCartLines();\n const clearCart = useClearCart();\n const queryClient = useQueryClient();\n\n // -- Order readiness --\n const { enableProcessOrderBtn, processingValidation } = useOrderReadiness({\n cartHdrUid,\n shippingAddress,\n billingAddress,\n shippingMethodSaved,\n showBillingInfoSummary,\n processingOrder,\n paymentMethod,\n unifiedPaymentAccountId: payment.unifiedPayment?.PaymentAccountID,\n unifiedBilling: payment.unifiedBilling,\n isFreeShipping,\n carrierId,\n shippingFee,\n isEditShippingInfo,\n isEditShippingMethods,\n isEditBillingInfo,\n editCc: payment.editCc,\n customReadinessCheck: buildReadinessOverride(config, ctxRef),\n });\n\n // -- Effects: data fetching on mount --\n\n useEffect(() => {\n if (config.order.fetchClientIp) {\n void config.order.fetchClientIp().then(setClientIp);\n }\n }, []);\n\n useEffect(() => {\n const custId = identity?.customerId;\n if (custId && identity?.fetchCustomerDoc) {\n void identity\n .fetchCustomerDoc(custId)\n .then(setCustomerDoc)\n .catch(() => setCustomerDoc(null));\n }\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [identity?.customerId]);\n\n // -- Effect: tax calculation when billing address changes --\n useEffect(() => {\n if (!config.order.calculateTax || !billingAddress?.postalCode) return;\n void config.order\n .calculateTax({\n customerId: identity?.customerId,\n postalCode: billingAddress.postalCode,\n items: orderCartLines ?? [],\n customerDoc,\n })\n .then((tax) => {\n if (tax !== undefined) setTaxRate(tax);\n });\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [billingAddress?.postalCode, orderCartLines]);\n\n // -- Effect: auto-copy shipping to billing (default \"same as shipping\") --\n useEffect(() => {\n if (shippingAccepted && shippingAddress && !billingAddress) {\n setBillingAddress(shippingAddress);\n }\n }, [shippingAccepted, shippingAddress, billingAddress]);\n\n // -- Effect: fire onShippingAccepted lifecycle hook --\n useEffect(() => {\n if (config.hooks?.onShippingAccepted && shippingAccepted && shippingAddress) {\n config.hooks.onShippingAccepted(ctxRef.current, shippingAddress, orderCartLines ?? []);\n }\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [shippingAccepted, shippingAddress]);\n\n // -- Effect: cart token from cookie --\n useEffect(() => {\n if (typeof document === \"undefined\") return;\n const cookies = document.cookie.split(\";\");\n const match = cookies.find((c) => c.trim().startsWith(\"cartToken=\"));\n if (match) {\n const token = match.split(\"=\")[1];\n if (token) setCartToken(token);\n }\n }, []);\n\n // -- Order submission with double-submit prevention --\n\n const resetProcessing = useCallback(() => setProcessingOrder(false), []);\n\n const isProcessingRef = useRef(false);\n\n const orderStateRef = useRef<OrderStateSnapshot>({\n shippingAddress,\n billingAddress,\n carrierId,\n shippingMethod,\n shippingFee,\n paymentMethod,\n taxRate,\n clientIp,\n isFreeShipping,\n identity,\n unifiedPayment: payment.unifiedPayment,\n unifiedCc: payment.unifiedCc,\n });\n orderStateRef.current = {\n shippingAddress,\n billingAddress,\n carrierId,\n shippingMethod,\n shippingFee,\n paymentMethod,\n taxRate,\n clientIp,\n isFreeShipping,\n identity,\n unifiedPayment: payment.unifiedPayment,\n unifiedCc: payment.unifiedCc,\n };\n\n const contextValueRef = useRef<CheckoutContextValue<TCustom>>(null!);\n\n const redirect = useCallback((url: string) => {\n if (config.order.redirect) {\n config.order.redirect(url);\n } else {\n defaultRedirect(url);\n }\n }, []);\n\n const processOrder = useCallback(async () => {\n if (isProcessingRef.current) return;\n isProcessingRef.current = true;\n try {\n await executeOrder(\n config,\n ctxRef,\n orderStateRef,\n contextValueRef,\n cartHdrUid,\n setProcessingOrder,\n redirect,\n queryClient,\n clearCart,\n );\n } finally {\n isProcessingRef.current = false;\n }\n }, [cartHdrUid, redirect, queryClient, clearCart]);\n\n // -- Context value --\n const value: CheckoutContextValue<TCustom> = {\n shippingAddress,\n setShippingAddress,\n shippingFee,\n setShippingFee,\n shippingMethod,\n setShippingMethod,\n shippingAccepted,\n setShippingAccepted,\n shippingMethodSaved,\n setShippingMethodSaved,\n isFreeShipping,\n setIsFreeShipping,\n carrierId,\n setCarrierId,\n showShippingMethod,\n setShowShippingMethod,\n billingAddress,\n setBillingAddress,\n paymentMethod,\n setPaymentMethod,\n showBillingInfoSummary,\n setShowBillingInfoSummary,\n paymentModal,\n cartLines,\n orderCartLines,\n setOrderCartLines,\n processingOrder,\n processOrder,\n resetProcessing,\n customerDoc,\n taxRate,\n setTaxRate,\n clientIp,\n cartToken,\n isEditShippingInfo,\n setIsEditShippingInfo: handleSetIsEditShippingInfo,\n isEditShippingMethods,\n setIsEditShippingMethods: handleSetIsEditShippingMethods,\n isEditBillingInfo,\n setIsEditBillingInfo,\n enableProcessOrderBtn,\n processingValidation,\n currentStep,\n goToStep,\n custom: customState,\n setCustom: setCustomField,\n config,\n };\n\n contextValueRef.current = value;\n\n return <Ctx.Provider value={value}>{children}</Ctx.Provider>;\n }\n\n /** Access checkout state from any child of CheckoutProvider. */\n function useCheckout(): CheckoutContextValue<TCustom> {\n const ctx = useContext(Ctx);\n if (!ctx) {\n throw new Error(\"useCheckout must be used within a CheckoutProvider\");\n }\n return ctx;\n }\n\n return { CheckoutProvider, useCheckout };\n}\n"]}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { ReactNode, ReactElement } from 'react';
|
|
2
|
-
import { a as PaymentFlowCallbacks } from '../use-
|
|
3
|
-
import { TCardInfo, TAccountQuery, CustomerDocument } from '@simpleapps-com/augur-utils';
|
|
2
|
+
import { a as PaymentFlowCallbacks, O as OrderReadinessParams } from '../use-order-readiness-DZTIfRzw.cjs';
|
|
3
|
+
import { TCardInfo, TAccountQuery, TCartLine, CustomerDocument } from '@simpleapps-com/augur-utils';
|
|
4
|
+
export { TCartLine } from '@simpleapps-com/augur-utils';
|
|
4
5
|
|
|
5
6
|
/**
|
|
6
7
|
* Address shape used by the checkout state machine.
|
|
@@ -103,10 +104,23 @@ interface CheckoutIdentityConfig {
|
|
|
103
104
|
/** Fetch customer document. Called once on mount with customerId. */
|
|
104
105
|
fetchCustomerDoc?: (customerId: string | number) => Promise<CustomerDocument | null>;
|
|
105
106
|
}
|
|
106
|
-
/**
|
|
107
|
+
/**
|
|
108
|
+
* Lifecycle hooks that sites inject for customization.
|
|
109
|
+
*
|
|
110
|
+
* Hooks SHOULD be referenced stably (defined at module scope or memoized
|
|
111
|
+
* with `useMemo` / `useCallback`). A fresh function identity on every render
|
|
112
|
+
* is tolerated today but may cause redundant effect runs if dependency
|
|
113
|
+
* handling tightens in future versions.
|
|
114
|
+
*/
|
|
107
115
|
interface CheckoutLifecycleHooks<TCustom extends Record<string, unknown>> {
|
|
108
|
-
/**
|
|
109
|
-
|
|
116
|
+
/**
|
|
117
|
+
* Called after shipping address is accepted.
|
|
118
|
+
*
|
|
119
|
+
* The 3rd argument is the shipping-resolved `TOrderCartLine[]` shape
|
|
120
|
+
* (snake_case P21 payload), not the raw `TCartLine[]` from the cart store.
|
|
121
|
+
* Read raw cart lines from `CheckoutContextValue.cartLines` instead.
|
|
122
|
+
*/
|
|
123
|
+
onShippingAccepted?: (ctx: CheckoutContext<TCustom>, address: CheckoutAddress, orderCartLines: unknown[]) => void;
|
|
110
124
|
/** Called before order submission. Return false to cancel. */
|
|
111
125
|
onBeforeSubmit?: (ctx: CheckoutContext<TCustom>) => boolean | void;
|
|
112
126
|
/** Called after successful order submission. */
|
|
@@ -115,13 +129,39 @@ interface CheckoutLifecycleHooks<TCustom extends Record<string, unknown>> {
|
|
|
115
129
|
onStepChange?: (ctx: CheckoutContext<TCustom>, fromStep: string, toStep: string) => void;
|
|
116
130
|
/** Custom validation. Return a string to block submission with a message. */
|
|
117
131
|
onValidate?: (ctx: CheckoutContext<TCustom>) => string | undefined;
|
|
118
|
-
/**
|
|
132
|
+
/**
|
|
133
|
+
* Resolve the default payment method. Called once on mount.
|
|
134
|
+
*
|
|
135
|
+
* When omitted, the provider defaults to `"credit-card"` if
|
|
136
|
+
* `config.payments.callbacks` is configured and `"invoice"` otherwise.
|
|
137
|
+
* Sites with non-standard flows (sample-only, invoice-only) SHOULD
|
|
138
|
+
* return the correct default for their flow from here.
|
|
139
|
+
*/
|
|
119
140
|
getDefaultPaymentMethod?: () => string;
|
|
120
141
|
/** Assemble the order payload from checkout state. If not provided, uses buildCheckoutPayload. */
|
|
121
142
|
assembleOrder?: (ctx: CheckoutContext<TCustom>, state: CheckoutContextValue<TCustom>) => {
|
|
122
143
|
order: Record<string, unknown>;
|
|
123
144
|
error?: string;
|
|
124
145
|
};
|
|
146
|
+
/**
|
|
147
|
+
* Custom order-readiness check for non-standard order flows
|
|
148
|
+
* (sample-only, pickup-only, invoice-only, quote-only).
|
|
149
|
+
*
|
|
150
|
+
* Return `true` or `false` to override the default Process Order
|
|
151
|
+
* button gates (shipping-method, billing, credit-card validation).
|
|
152
|
+
* Return `undefined` to defer to the default gates.
|
|
153
|
+
*
|
|
154
|
+
* Compose default gates with site-specific logic by invoking
|
|
155
|
+
* `determineOrderReadiness` with a nulled override:
|
|
156
|
+
*
|
|
157
|
+
* ```ts
|
|
158
|
+
* isOrderReady: (ctx, params) => {
|
|
159
|
+
* if (!ctx.get("isSampleItems")) return undefined; // defer
|
|
160
|
+
* return determineOrderReadiness({ ...params, customReadinessCheck: undefined });
|
|
161
|
+
* }
|
|
162
|
+
* ```
|
|
163
|
+
*/
|
|
164
|
+
isOrderReady?: (ctx: CheckoutContext<TCustom>, params: OrderReadinessParams) => boolean | undefined;
|
|
125
165
|
}
|
|
126
166
|
/** Full checkout provider configuration. */
|
|
127
167
|
interface CheckoutProviderConfig<TCustom extends Record<string, unknown> = Record<string, never>> {
|
|
@@ -189,6 +229,15 @@ interface CheckoutContextValue<TCustom extends Record<string, unknown> = Record<
|
|
|
189
229
|
showBillingInfoSummary: boolean;
|
|
190
230
|
setShowBillingInfoSummary: (show: boolean) => void;
|
|
191
231
|
paymentModal: CheckoutPaymentModal | undefined;
|
|
232
|
+
/**
|
|
233
|
+
* Raw cart lines from the cart store.
|
|
234
|
+
*
|
|
235
|
+
* Use this shape (camelCase: `invMastUid`, `itemId`, `quantity`, `unitOfMeasure`)
|
|
236
|
+
* in `assembleOrder` for non-standard order paths (sample, pickup, invoice-only)
|
|
237
|
+
* that bypass shipping-method resolution. For the shipping-resolved payload shape,
|
|
238
|
+
* see `orderCartLines`.
|
|
239
|
+
*/
|
|
240
|
+
cartLines: TCartLine[];
|
|
192
241
|
orderCartLines: unknown[] | undefined;
|
|
193
242
|
setOrderCartLines: (lines: unknown[]) => void;
|
|
194
243
|
processingOrder: boolean;
|
package/dist/checkout/index.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { ReactNode, ReactElement } from 'react';
|
|
2
|
-
import { a as PaymentFlowCallbacks } from '../use-
|
|
3
|
-
import { TCardInfo, TAccountQuery, CustomerDocument } from '@simpleapps-com/augur-utils';
|
|
2
|
+
import { a as PaymentFlowCallbacks, O as OrderReadinessParams } from '../use-order-readiness-DZTIfRzw.js';
|
|
3
|
+
import { TCardInfo, TAccountQuery, TCartLine, CustomerDocument } from '@simpleapps-com/augur-utils';
|
|
4
|
+
export { TCartLine } from '@simpleapps-com/augur-utils';
|
|
4
5
|
|
|
5
6
|
/**
|
|
6
7
|
* Address shape used by the checkout state machine.
|
|
@@ -103,10 +104,23 @@ interface CheckoutIdentityConfig {
|
|
|
103
104
|
/** Fetch customer document. Called once on mount with customerId. */
|
|
104
105
|
fetchCustomerDoc?: (customerId: string | number) => Promise<CustomerDocument | null>;
|
|
105
106
|
}
|
|
106
|
-
/**
|
|
107
|
+
/**
|
|
108
|
+
* Lifecycle hooks that sites inject for customization.
|
|
109
|
+
*
|
|
110
|
+
* Hooks SHOULD be referenced stably (defined at module scope or memoized
|
|
111
|
+
* with `useMemo` / `useCallback`). A fresh function identity on every render
|
|
112
|
+
* is tolerated today but may cause redundant effect runs if dependency
|
|
113
|
+
* handling tightens in future versions.
|
|
114
|
+
*/
|
|
107
115
|
interface CheckoutLifecycleHooks<TCustom extends Record<string, unknown>> {
|
|
108
|
-
/**
|
|
109
|
-
|
|
116
|
+
/**
|
|
117
|
+
* Called after shipping address is accepted.
|
|
118
|
+
*
|
|
119
|
+
* The 3rd argument is the shipping-resolved `TOrderCartLine[]` shape
|
|
120
|
+
* (snake_case P21 payload), not the raw `TCartLine[]` from the cart store.
|
|
121
|
+
* Read raw cart lines from `CheckoutContextValue.cartLines` instead.
|
|
122
|
+
*/
|
|
123
|
+
onShippingAccepted?: (ctx: CheckoutContext<TCustom>, address: CheckoutAddress, orderCartLines: unknown[]) => void;
|
|
110
124
|
/** Called before order submission. Return false to cancel. */
|
|
111
125
|
onBeforeSubmit?: (ctx: CheckoutContext<TCustom>) => boolean | void;
|
|
112
126
|
/** Called after successful order submission. */
|
|
@@ -115,13 +129,39 @@ interface CheckoutLifecycleHooks<TCustom extends Record<string, unknown>> {
|
|
|
115
129
|
onStepChange?: (ctx: CheckoutContext<TCustom>, fromStep: string, toStep: string) => void;
|
|
116
130
|
/** Custom validation. Return a string to block submission with a message. */
|
|
117
131
|
onValidate?: (ctx: CheckoutContext<TCustom>) => string | undefined;
|
|
118
|
-
/**
|
|
132
|
+
/**
|
|
133
|
+
* Resolve the default payment method. Called once on mount.
|
|
134
|
+
*
|
|
135
|
+
* When omitted, the provider defaults to `"credit-card"` if
|
|
136
|
+
* `config.payments.callbacks` is configured and `"invoice"` otherwise.
|
|
137
|
+
* Sites with non-standard flows (sample-only, invoice-only) SHOULD
|
|
138
|
+
* return the correct default for their flow from here.
|
|
139
|
+
*/
|
|
119
140
|
getDefaultPaymentMethod?: () => string;
|
|
120
141
|
/** Assemble the order payload from checkout state. If not provided, uses buildCheckoutPayload. */
|
|
121
142
|
assembleOrder?: (ctx: CheckoutContext<TCustom>, state: CheckoutContextValue<TCustom>) => {
|
|
122
143
|
order: Record<string, unknown>;
|
|
123
144
|
error?: string;
|
|
124
145
|
};
|
|
146
|
+
/**
|
|
147
|
+
* Custom order-readiness check for non-standard order flows
|
|
148
|
+
* (sample-only, pickup-only, invoice-only, quote-only).
|
|
149
|
+
*
|
|
150
|
+
* Return `true` or `false` to override the default Process Order
|
|
151
|
+
* button gates (shipping-method, billing, credit-card validation).
|
|
152
|
+
* Return `undefined` to defer to the default gates.
|
|
153
|
+
*
|
|
154
|
+
* Compose default gates with site-specific logic by invoking
|
|
155
|
+
* `determineOrderReadiness` with a nulled override:
|
|
156
|
+
*
|
|
157
|
+
* ```ts
|
|
158
|
+
* isOrderReady: (ctx, params) => {
|
|
159
|
+
* if (!ctx.get("isSampleItems")) return undefined; // defer
|
|
160
|
+
* return determineOrderReadiness({ ...params, customReadinessCheck: undefined });
|
|
161
|
+
* }
|
|
162
|
+
* ```
|
|
163
|
+
*/
|
|
164
|
+
isOrderReady?: (ctx: CheckoutContext<TCustom>, params: OrderReadinessParams) => boolean | undefined;
|
|
125
165
|
}
|
|
126
166
|
/** Full checkout provider configuration. */
|
|
127
167
|
interface CheckoutProviderConfig<TCustom extends Record<string, unknown> = Record<string, never>> {
|
|
@@ -189,6 +229,15 @@ interface CheckoutContextValue<TCustom extends Record<string, unknown> = Record<
|
|
|
189
229
|
showBillingInfoSummary: boolean;
|
|
190
230
|
setShowBillingInfoSummary: (show: boolean) => void;
|
|
191
231
|
paymentModal: CheckoutPaymentModal | undefined;
|
|
232
|
+
/**
|
|
233
|
+
* Raw cart lines from the cart store.
|
|
234
|
+
*
|
|
235
|
+
* Use this shape (camelCase: `invMastUid`, `itemId`, `quantity`, `unitOfMeasure`)
|
|
236
|
+
* in `assembleOrder` for non-standard order paths (sample, pickup, invoice-only)
|
|
237
|
+
* that bypass shipping-method resolution. For the shipping-resolved payload shape,
|
|
238
|
+
* see `orderCartLines`.
|
|
239
|
+
*/
|
|
240
|
+
cartLines: TCartLine[];
|
|
192
241
|
orderCartLines: unknown[] | undefined;
|
|
193
242
|
setOrderCartLines: (lines: unknown[]) => void;
|
|
194
243
|
processingOrder: boolean;
|
package/dist/checkout/index.js
CHANGED
|
@@ -2,9 +2,11 @@ import {
|
|
|
2
2
|
PAYMENT_STORAGE_KEY,
|
|
3
3
|
clearFromSession,
|
|
4
4
|
useCartHdrUid,
|
|
5
|
+
useCartLines,
|
|
6
|
+
useClearCart,
|
|
5
7
|
useOrderReadiness,
|
|
6
8
|
usePaymentFlow
|
|
7
|
-
} from "../chunk-
|
|
9
|
+
} from "../chunk-NRWH2BMN.js";
|
|
8
10
|
|
|
9
11
|
// src/checkout/create-checkout-provider.tsx
|
|
10
12
|
import {
|
|
@@ -15,6 +17,7 @@ import {
|
|
|
15
17
|
useEffect,
|
|
16
18
|
useRef
|
|
17
19
|
} from "react";
|
|
20
|
+
import { useQueryClient } from "@tanstack/react-query";
|
|
18
21
|
import { jsx } from "react/jsx-runtime";
|
|
19
22
|
var ORDER_CONFIRMATION_KEY = "orderConfirmation";
|
|
20
23
|
function defaultRedirect(url) {
|
|
@@ -61,6 +64,16 @@ function resolveCartHdrUid(cartHdrUid) {
|
|
|
61
64
|
if (typeof cartHdrUid === "string") return Number(cartHdrUid);
|
|
62
65
|
return cartHdrUid ?? 0;
|
|
63
66
|
}
|
|
67
|
+
function resolveDefaultPaymentMethod(config) {
|
|
68
|
+
const explicit = config.hooks?.getDefaultPaymentMethod?.();
|
|
69
|
+
if (explicit) return explicit;
|
|
70
|
+
return config.payments?.callbacks ? "credit-card" : "invoice";
|
|
71
|
+
}
|
|
72
|
+
function buildReadinessOverride(config, ctxRef) {
|
|
73
|
+
const siteIsOrderReady = config.hooks?.isOrderReady;
|
|
74
|
+
if (!siteIsOrderReady) return void 0;
|
|
75
|
+
return (params) => siteIsOrderReady(ctxRef.current, params);
|
|
76
|
+
}
|
|
64
77
|
function assembleOrderPayload(config, ctx, contextValue, stateSnapshot) {
|
|
65
78
|
if (config.hooks?.assembleOrder) {
|
|
66
79
|
const assembled = config.hooks.assembleOrder(ctx, contextValue);
|
|
@@ -69,6 +82,48 @@ function assembleOrderPayload(config, ctx, contextValue, stateSnapshot) {
|
|
|
69
82
|
}
|
|
70
83
|
return { orderData: buildOrderData(stateSnapshot) };
|
|
71
84
|
}
|
|
85
|
+
function validateOrderPayload(orderData) {
|
|
86
|
+
if (orderData === null || typeof orderData !== "object" || Array.isArray(orderData)) {
|
|
87
|
+
return "Order payload is empty or malformed.";
|
|
88
|
+
}
|
|
89
|
+
if ("lines" in orderData) {
|
|
90
|
+
const lines = orderData["lines"];
|
|
91
|
+
if (!Array.isArray(lines) || lines.length === 0) {
|
|
92
|
+
return "Order has no line items.";
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
if ("header" in orderData) {
|
|
96
|
+
const header = orderData["header"];
|
|
97
|
+
if (header !== null && typeof header === "object" && !Array.isArray(header)) {
|
|
98
|
+
const customerId = header["customer_id"];
|
|
99
|
+
if (customerId == null || String(customerId).trim() === "") {
|
|
100
|
+
return "Order is missing a customer.";
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
return null;
|
|
105
|
+
}
|
|
106
|
+
function prepareOrderPayload(config, ctx, contextValue, stateSnapshot, setProcessingOrder) {
|
|
107
|
+
const { orderData, error: assemblyError } = assembleOrderPayload(
|
|
108
|
+
config,
|
|
109
|
+
ctx,
|
|
110
|
+
contextValue,
|
|
111
|
+
stateSnapshot
|
|
112
|
+
);
|
|
113
|
+
if (assemblyError) {
|
|
114
|
+
setProcessingOrder(false);
|
|
115
|
+
config.ui?.onError?.("Order Error", assemblyError);
|
|
116
|
+
return null;
|
|
117
|
+
}
|
|
118
|
+
const validationError = validateOrderPayload(orderData);
|
|
119
|
+
if (validationError) {
|
|
120
|
+
console.error("Order payload validation failed:", orderData);
|
|
121
|
+
setProcessingOrder(false);
|
|
122
|
+
config.ui?.onError?.("Order Error", validationError);
|
|
123
|
+
return null;
|
|
124
|
+
}
|
|
125
|
+
return orderData;
|
|
126
|
+
}
|
|
72
127
|
function buildOrderConfirmation(orderData, resultData, state, orderCartLines) {
|
|
73
128
|
return {
|
|
74
129
|
orderData,
|
|
@@ -83,7 +138,7 @@ function buildOrderConfirmation(orderData, resultData, state, orderCartLines) {
|
|
|
83
138
|
orderCartLines
|
|
84
139
|
};
|
|
85
140
|
}
|
|
86
|
-
function handleOrderSuccess(config, ctx, resultData, confirmation, setProcessingOrder, redirect) {
|
|
141
|
+
function handleOrderSuccess(config, ctx, resultData, confirmation, setProcessingOrder, redirect, queryClient, clearCart) {
|
|
87
142
|
if (config.payments?.persistence) {
|
|
88
143
|
clearFromSession(PAYMENT_STORAGE_KEY);
|
|
89
144
|
}
|
|
@@ -94,10 +149,14 @@ function handleOrderSuccess(config, ctx, resultData, confirmation, setProcessing
|
|
|
94
149
|
} catch {
|
|
95
150
|
}
|
|
96
151
|
}
|
|
152
|
+
clearCart();
|
|
153
|
+
void queryClient.invalidateQueries({ queryKey: ["cartLines"] });
|
|
154
|
+
void queryClient.invalidateQueries({ queryKey: ["cart-also-bought"] });
|
|
155
|
+
void queryClient.invalidateQueries({ queryKey: ["commerce", "cartLine"] });
|
|
97
156
|
redirect(config.order.successRedirect);
|
|
98
157
|
setProcessingOrder(false);
|
|
99
158
|
}
|
|
100
|
-
async function executeOrder(config, ctxRef, stateRef, contextValueRef, cartHdrUid, setProcessingOrder, redirect) {
|
|
159
|
+
async function executeOrder(config, ctxRef, stateRef, contextValueRef, cartHdrUid, setProcessingOrder, redirect, queryClient, clearCart) {
|
|
101
160
|
const ctx = ctxRef.current;
|
|
102
161
|
const s = stateRef.current;
|
|
103
162
|
const preCheck = runPreSubmitChecks(config, ctx, s.shippingAddress);
|
|
@@ -107,17 +166,14 @@ async function executeOrder(config, ctxRef, stateRef, contextValueRef, cartHdrUi
|
|
|
107
166
|
return;
|
|
108
167
|
}
|
|
109
168
|
setProcessingOrder(true);
|
|
110
|
-
const
|
|
169
|
+
const orderData = prepareOrderPayload(
|
|
111
170
|
config,
|
|
112
171
|
ctx,
|
|
113
172
|
contextValueRef.current,
|
|
114
|
-
s
|
|
173
|
+
s,
|
|
174
|
+
setProcessingOrder
|
|
115
175
|
);
|
|
116
|
-
if (
|
|
117
|
-
setProcessingOrder(false);
|
|
118
|
-
config.ui?.onError?.("Order Error", assemblyError);
|
|
119
|
-
return;
|
|
120
|
-
}
|
|
176
|
+
if (!orderData) return;
|
|
121
177
|
let result;
|
|
122
178
|
try {
|
|
123
179
|
result = await config.order.submitOrder(orderData, resolveCartHdrUid(cartHdrUid));
|
|
@@ -136,7 +192,16 @@ async function executeOrder(config, ctxRef, stateRef, contextValueRef, cartHdrUi
|
|
|
136
192
|
s,
|
|
137
193
|
contextValueRef.current.orderCartLines
|
|
138
194
|
);
|
|
139
|
-
handleOrderSuccess(
|
|
195
|
+
handleOrderSuccess(
|
|
196
|
+
config,
|
|
197
|
+
ctx,
|
|
198
|
+
result.data,
|
|
199
|
+
confirmation,
|
|
200
|
+
setProcessingOrder,
|
|
201
|
+
redirect,
|
|
202
|
+
queryClient,
|
|
203
|
+
clearCart
|
|
204
|
+
);
|
|
140
205
|
}
|
|
141
206
|
var NOOP_PAYMENT_CALLBACKS = {
|
|
142
207
|
transactionSetup: async () => void 0,
|
|
@@ -161,8 +226,7 @@ function createCheckoutProvider(config) {
|
|
|
161
226
|
const [carrierId, setCarrierId] = useState(config.shipping.defaultCarrierId);
|
|
162
227
|
const [showShippingMethod, setShowShippingMethod] = useState(false);
|
|
163
228
|
const [billingAddress, setBillingAddress] = useState();
|
|
164
|
-
const
|
|
165
|
-
const [paymentMethod, setPaymentMethod] = useState(defaultPaymentMethod);
|
|
229
|
+
const [paymentMethod, setPaymentMethod] = useState(() => resolveDefaultPaymentMethod(config));
|
|
166
230
|
const [showBillingInfoSummary, setShowBillingInfoSummary] = useState(false);
|
|
167
231
|
const [orderCartLines, setOrderCartLines] = useState();
|
|
168
232
|
const [processingOrder, setProcessingOrder] = useState(false);
|
|
@@ -234,6 +298,9 @@ function createCheckoutProvider(config) {
|
|
|
234
298
|
[currentStep]
|
|
235
299
|
);
|
|
236
300
|
const cartHdrUid = useCartHdrUid();
|
|
301
|
+
const cartLines = useCartLines();
|
|
302
|
+
const clearCart = useClearCart();
|
|
303
|
+
const queryClient = useQueryClient();
|
|
237
304
|
const { enableProcessOrderBtn, processingValidation } = useOrderReadiness({
|
|
238
305
|
cartHdrUid,
|
|
239
306
|
shippingAddress,
|
|
@@ -250,7 +317,8 @@ function createCheckoutProvider(config) {
|
|
|
250
317
|
isEditShippingInfo,
|
|
251
318
|
isEditShippingMethods,
|
|
252
319
|
isEditBillingInfo,
|
|
253
|
-
editCc: payment.editCc
|
|
320
|
+
editCc: payment.editCc,
|
|
321
|
+
customReadinessCheck: buildReadinessOverride(config, ctxRef)
|
|
254
322
|
});
|
|
255
323
|
useEffect(() => {
|
|
256
324
|
if (config.order.fetchClientIp) {
|
|
@@ -342,12 +410,14 @@ function createCheckoutProvider(config) {
|
|
|
342
410
|
contextValueRef,
|
|
343
411
|
cartHdrUid,
|
|
344
412
|
setProcessingOrder,
|
|
345
|
-
redirect
|
|
413
|
+
redirect,
|
|
414
|
+
queryClient,
|
|
415
|
+
clearCart
|
|
346
416
|
);
|
|
347
417
|
} finally {
|
|
348
418
|
isProcessingRef.current = false;
|
|
349
419
|
}
|
|
350
|
-
}, [cartHdrUid, redirect]);
|
|
420
|
+
}, [cartHdrUid, redirect, queryClient, clearCart]);
|
|
351
421
|
const value = {
|
|
352
422
|
shippingAddress,
|
|
353
423
|
setShippingAddress,
|
|
@@ -372,6 +442,7 @@ function createCheckoutProvider(config) {
|
|
|
372
442
|
showBillingInfoSummary,
|
|
373
443
|
setShowBillingInfoSummary,
|
|
374
444
|
paymentModal,
|
|
445
|
+
cartLines,
|
|
375
446
|
orderCartLines,
|
|
376
447
|
setOrderCartLines,
|
|
377
448
|
processingOrder,
|