@simpleapps-com/augur-hooks 2.0.18 → 2.0.21
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/dist/index.cjs +194 -33
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +87 -2
- package/dist/index.d.ts +87 -2
- package/dist/index.js +174 -13
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
package/dist/index.d.cts
CHANGED
|
@@ -4,10 +4,11 @@ import { InfiniteScrollPage, ListResult, CacheConfig, AugurAuthContext } from '@
|
|
|
4
4
|
export { AugurAuthContext, AugurSiteConfig, AugurSiteDefaults, AugurSiteFormatting, CacheConfig, CacheProvider, CacheTierConfig, DeepQueryOptions, EdgeCacheValue, InfiniteScrollPage, ProxyMutationOptions, ProxyQueryOptions } from '@simpleapps-com/augur-core';
|
|
5
5
|
import * as zustand from 'zustand';
|
|
6
6
|
import * as _simpleapps_com_augur_utils from '@simpleapps-com/augur-utils';
|
|
7
|
-
import { TCartLine, TItemsFilters, TPriceData, TInvMastDoc, TCategory, TItemDetails, TStock, TAttribute, TSearchSuggestionsResponse, TJoomlaContent, TJoomlaContentFilters, MenuItem, TMenuFilters, ImageConfig, ImageUrlOptions } from '@simpleapps-com/augur-utils';
|
|
7
|
+
import { TCartLine, TItemsFilters, TPriceData, TInvMastDoc, TCategory, TItemDetails, TStock, TAttribute, TSearchSuggestionsResponse, TTransactionSetup, TCardInfo, TPaymentValidation, TAccountQuery, TBillingUpdate, TJoomlaContent, TJoomlaContentFilters, MenuItem, TMenuFilters, ImageConfig, ImageUrlOptions } from '@simpleapps-com/augur-utils';
|
|
8
8
|
export { DerivePriceInput, DerivedPrice, ResolveStockInput, ResolvedStock, TSearchSuggestion as SearchSuggestion, TSearchSuggestionsResponse as SearchSuggestionsResponse } from '@simpleapps-com/augur-utils';
|
|
9
9
|
import * as _tanstack_react_query from '@tanstack/react-query';
|
|
10
10
|
import { QueryKey } from '@tanstack/react-query';
|
|
11
|
+
import * as react from 'react';
|
|
11
12
|
import { ReactNode, createElement } from 'react';
|
|
12
13
|
import { u as useImageWithFallback } from './use-image-with-fallback-DgmtrGZU.cjs';
|
|
13
14
|
import * as _tanstack_react_query_persist_client from '@tanstack/react-query-persist-client';
|
|
@@ -575,6 +576,90 @@ declare function useCartActions(callbacks: CartActionCallbacks): {
|
|
|
575
576
|
invalidateCartCache: () => void;
|
|
576
577
|
};
|
|
577
578
|
|
|
579
|
+
/** Site-specific payment action callbacks injected into usePaymentFlow. */
|
|
580
|
+
interface PaymentFlowCallbacks {
|
|
581
|
+
/** Initialize a payment session. Returns transaction setup or undefined on failure. */
|
|
582
|
+
transactionSetup: (params: {
|
|
583
|
+
customerId: string;
|
|
584
|
+
}) => Promise<TTransactionSetup | undefined>;
|
|
585
|
+
/** Retrieve card details after iframe entry. */
|
|
586
|
+
cardInfo: (params: {
|
|
587
|
+
transactionSetupId: string;
|
|
588
|
+
}) => Promise<TCardInfo | undefined>;
|
|
589
|
+
/** Verify card is valid. */
|
|
590
|
+
validatePayment: (params: {
|
|
591
|
+
transactionSetupId: string;
|
|
592
|
+
customerId: string;
|
|
593
|
+
}) => Promise<TPaymentValidation | undefined>;
|
|
594
|
+
/** Get payment account ID. */
|
|
595
|
+
accountQuery: (params: {
|
|
596
|
+
transactionSetupId: string;
|
|
597
|
+
customerId: string;
|
|
598
|
+
}) => Promise<TAccountQuery | undefined>;
|
|
599
|
+
/** Send billing address to payment processor. */
|
|
600
|
+
billingUpdate: (params: {
|
|
601
|
+
transactionSetupId: string;
|
|
602
|
+
address1: string;
|
|
603
|
+
address2?: string;
|
|
604
|
+
city: string;
|
|
605
|
+
state: string;
|
|
606
|
+
zip: string;
|
|
607
|
+
}) => Promise<TBillingUpdate | undefined>;
|
|
608
|
+
/** Optional toast notification callback. */
|
|
609
|
+
toast?: {
|
|
610
|
+
error?: (message: string) => void;
|
|
611
|
+
};
|
|
612
|
+
}
|
|
613
|
+
/** Billing address shape accepted by the payment flow. */
|
|
614
|
+
interface PaymentBillingAddress {
|
|
615
|
+
address1: string;
|
|
616
|
+
address2?: string;
|
|
617
|
+
city: string;
|
|
618
|
+
state: string;
|
|
619
|
+
postalCode: string;
|
|
620
|
+
}
|
|
621
|
+
interface UsePaymentFlowParams {
|
|
622
|
+
callbacks: PaymentFlowCallbacks;
|
|
623
|
+
customerId: string | number | undefined;
|
|
624
|
+
billingAddress: PaymentBillingAddress | undefined;
|
|
625
|
+
paymentMethod: string;
|
|
626
|
+
shippingAccepted: boolean;
|
|
627
|
+
}
|
|
628
|
+
/**
|
|
629
|
+
* Manages the full Element/Unified payment lifecycle:
|
|
630
|
+
* transactionSetup -> cardInfo -> validatePayment -> accountQuery -> billingUpdate
|
|
631
|
+
*
|
|
632
|
+
* Accepts site-specific server action callbacks so the hook has no dependency
|
|
633
|
+
* on any particular server action implementation.
|
|
634
|
+
*
|
|
635
|
+
* @example
|
|
636
|
+
* ```tsx
|
|
637
|
+
* import { usePaymentFlow } from "@simpleapps-com/augur-hooks";
|
|
638
|
+
* import { transactionSetup, cardInfo, validatePayment, accountQuery, billingUpdate } from "@/lib/actions/payments";
|
|
639
|
+
*
|
|
640
|
+
* const payment = usePaymentFlow({
|
|
641
|
+
* callbacks: { transactionSetup, cardInfo, validatePayment, accountQuery, billingUpdate },
|
|
642
|
+
* customerId,
|
|
643
|
+
* billingAddress,
|
|
644
|
+
* paymentMethod: "credit-card",
|
|
645
|
+
* shippingAccepted: true,
|
|
646
|
+
* });
|
|
647
|
+
* ```
|
|
648
|
+
*/
|
|
649
|
+
declare function usePaymentFlow({ callbacks, customerId, billingAddress, paymentMethod, shippingAccepted, }: UsePaymentFlowParams): {
|
|
650
|
+
isOpen: boolean;
|
|
651
|
+
setIsOpen: react.Dispatch<react.SetStateAction<boolean>>;
|
|
652
|
+
editCc: boolean;
|
|
653
|
+
setEditCc: react.Dispatch<react.SetStateAction<boolean>>;
|
|
654
|
+
unified: TTransactionSetup | null;
|
|
655
|
+
unifiedCc: TCardInfo | null;
|
|
656
|
+
unifiedResponse: boolean;
|
|
657
|
+
unifiedBilling: boolean;
|
|
658
|
+
unifiedPayment: TAccountQuery | null;
|
|
659
|
+
capturedBin: string | null;
|
|
660
|
+
handleBinCapture: (bin: string) => void;
|
|
661
|
+
};
|
|
662
|
+
|
|
578
663
|
/** Session info passed from the consumer's auth system. */
|
|
579
664
|
interface CartSessionInfo {
|
|
580
665
|
/** Auth status: "loading" | "authenticated" | "unauthenticated" */
|
|
@@ -997,4 +1082,4 @@ declare function useAugurPersistence(config: PersistenceConfig): {
|
|
|
997
1082
|
};
|
|
998
1083
|
};
|
|
999
1084
|
|
|
1000
|
-
export { AugurApiClient, AugurCallbacks, BatchInvMastDocParam, type CartActionCallbacks, type CartInitCallbacks, type CartPriceData, type CartPricingResult, type CartSessionInfo, type CreateSiteHooksConfig, type FormatPriceCallOptions, GetItemCategoryApiOptions, PageData, PersistenceConfig, type UseFormatPriceOptions, type UseStockOptions, createSiteHooks, useAugurPersistence, useBatchInvMastDoc, useCartActions, useCartHdrUid, useCartInitialization, useCartLineCount, useCartLines, useCartPricing, useCartQuantityTotal, useCartStore, useCategoryItemsInfinite, useClearCart, useCustomerInvoices, useCustomerOrders, useCustomerQuotes, useDebounce, useFormatPrice, useInvMast, useInvMastDoc, useInvMastStock, useInvoiceDetail, useItemAttributes, useItemCategory, useItemDetails, useItemFiltersStore, useItemPrice, useItemSearchInfinite, useJoomlaContent, useJoomlaContentList, useJoomlaMenu, useJoomlaMenuDoc, useOrderDetail, usePaginationPrefetch, useProductCategory, useProductSearch, useQuoteDetail, useSearchSuggestions, useSetCartHdrUid, useSetCartLines, useStock };
|
|
1085
|
+
export { AugurApiClient, AugurCallbacks, BatchInvMastDocParam, type CartActionCallbacks, type CartInitCallbacks, type CartPriceData, type CartPricingResult, type CartSessionInfo, type CreateSiteHooksConfig, type FormatPriceCallOptions, GetItemCategoryApiOptions, PageData, type PaymentBillingAddress, type PaymentFlowCallbacks, PersistenceConfig, type UseFormatPriceOptions, type UseStockOptions, createSiteHooks, useAugurPersistence, useBatchInvMastDoc, useCartActions, useCartHdrUid, useCartInitialization, useCartLineCount, useCartLines, useCartPricing, useCartQuantityTotal, useCartStore, useCategoryItemsInfinite, useClearCart, useCustomerInvoices, useCustomerOrders, useCustomerQuotes, useDebounce, useFormatPrice, useInvMast, useInvMastDoc, useInvMastStock, useInvoiceDetail, useItemAttributes, useItemCategory, useItemDetails, useItemFiltersStore, useItemPrice, useItemSearchInfinite, useJoomlaContent, useJoomlaContentList, useJoomlaMenu, useJoomlaMenuDoc, useOrderDetail, usePaginationPrefetch, usePaymentFlow, useProductCategory, useProductSearch, useQuoteDetail, useSearchSuggestions, useSetCartHdrUid, useSetCartLines, useStock };
|
package/dist/index.d.ts
CHANGED
|
@@ -4,10 +4,11 @@ import { InfiniteScrollPage, ListResult, CacheConfig, AugurAuthContext } from '@
|
|
|
4
4
|
export { AugurAuthContext, AugurSiteConfig, AugurSiteDefaults, AugurSiteFormatting, CacheConfig, CacheProvider, CacheTierConfig, DeepQueryOptions, EdgeCacheValue, InfiniteScrollPage, ProxyMutationOptions, ProxyQueryOptions } from '@simpleapps-com/augur-core';
|
|
5
5
|
import * as zustand from 'zustand';
|
|
6
6
|
import * as _simpleapps_com_augur_utils from '@simpleapps-com/augur-utils';
|
|
7
|
-
import { TCartLine, TItemsFilters, TPriceData, TInvMastDoc, TCategory, TItemDetails, TStock, TAttribute, TSearchSuggestionsResponse, TJoomlaContent, TJoomlaContentFilters, MenuItem, TMenuFilters, ImageConfig, ImageUrlOptions } from '@simpleapps-com/augur-utils';
|
|
7
|
+
import { TCartLine, TItemsFilters, TPriceData, TInvMastDoc, TCategory, TItemDetails, TStock, TAttribute, TSearchSuggestionsResponse, TTransactionSetup, TCardInfo, TPaymentValidation, TAccountQuery, TBillingUpdate, TJoomlaContent, TJoomlaContentFilters, MenuItem, TMenuFilters, ImageConfig, ImageUrlOptions } from '@simpleapps-com/augur-utils';
|
|
8
8
|
export { DerivePriceInput, DerivedPrice, ResolveStockInput, ResolvedStock, TSearchSuggestion as SearchSuggestion, TSearchSuggestionsResponse as SearchSuggestionsResponse } from '@simpleapps-com/augur-utils';
|
|
9
9
|
import * as _tanstack_react_query from '@tanstack/react-query';
|
|
10
10
|
import { QueryKey } from '@tanstack/react-query';
|
|
11
|
+
import * as react from 'react';
|
|
11
12
|
import { ReactNode, createElement } from 'react';
|
|
12
13
|
import { u as useImageWithFallback } from './use-image-with-fallback-DgmtrGZU.js';
|
|
13
14
|
import * as _tanstack_react_query_persist_client from '@tanstack/react-query-persist-client';
|
|
@@ -575,6 +576,90 @@ declare function useCartActions(callbacks: CartActionCallbacks): {
|
|
|
575
576
|
invalidateCartCache: () => void;
|
|
576
577
|
};
|
|
577
578
|
|
|
579
|
+
/** Site-specific payment action callbacks injected into usePaymentFlow. */
|
|
580
|
+
interface PaymentFlowCallbacks {
|
|
581
|
+
/** Initialize a payment session. Returns transaction setup or undefined on failure. */
|
|
582
|
+
transactionSetup: (params: {
|
|
583
|
+
customerId: string;
|
|
584
|
+
}) => Promise<TTransactionSetup | undefined>;
|
|
585
|
+
/** Retrieve card details after iframe entry. */
|
|
586
|
+
cardInfo: (params: {
|
|
587
|
+
transactionSetupId: string;
|
|
588
|
+
}) => Promise<TCardInfo | undefined>;
|
|
589
|
+
/** Verify card is valid. */
|
|
590
|
+
validatePayment: (params: {
|
|
591
|
+
transactionSetupId: string;
|
|
592
|
+
customerId: string;
|
|
593
|
+
}) => Promise<TPaymentValidation | undefined>;
|
|
594
|
+
/** Get payment account ID. */
|
|
595
|
+
accountQuery: (params: {
|
|
596
|
+
transactionSetupId: string;
|
|
597
|
+
customerId: string;
|
|
598
|
+
}) => Promise<TAccountQuery | undefined>;
|
|
599
|
+
/** Send billing address to payment processor. */
|
|
600
|
+
billingUpdate: (params: {
|
|
601
|
+
transactionSetupId: string;
|
|
602
|
+
address1: string;
|
|
603
|
+
address2?: string;
|
|
604
|
+
city: string;
|
|
605
|
+
state: string;
|
|
606
|
+
zip: string;
|
|
607
|
+
}) => Promise<TBillingUpdate | undefined>;
|
|
608
|
+
/** Optional toast notification callback. */
|
|
609
|
+
toast?: {
|
|
610
|
+
error?: (message: string) => void;
|
|
611
|
+
};
|
|
612
|
+
}
|
|
613
|
+
/** Billing address shape accepted by the payment flow. */
|
|
614
|
+
interface PaymentBillingAddress {
|
|
615
|
+
address1: string;
|
|
616
|
+
address2?: string;
|
|
617
|
+
city: string;
|
|
618
|
+
state: string;
|
|
619
|
+
postalCode: string;
|
|
620
|
+
}
|
|
621
|
+
interface UsePaymentFlowParams {
|
|
622
|
+
callbacks: PaymentFlowCallbacks;
|
|
623
|
+
customerId: string | number | undefined;
|
|
624
|
+
billingAddress: PaymentBillingAddress | undefined;
|
|
625
|
+
paymentMethod: string;
|
|
626
|
+
shippingAccepted: boolean;
|
|
627
|
+
}
|
|
628
|
+
/**
|
|
629
|
+
* Manages the full Element/Unified payment lifecycle:
|
|
630
|
+
* transactionSetup -> cardInfo -> validatePayment -> accountQuery -> billingUpdate
|
|
631
|
+
*
|
|
632
|
+
* Accepts site-specific server action callbacks so the hook has no dependency
|
|
633
|
+
* on any particular server action implementation.
|
|
634
|
+
*
|
|
635
|
+
* @example
|
|
636
|
+
* ```tsx
|
|
637
|
+
* import { usePaymentFlow } from "@simpleapps-com/augur-hooks";
|
|
638
|
+
* import { transactionSetup, cardInfo, validatePayment, accountQuery, billingUpdate } from "@/lib/actions/payments";
|
|
639
|
+
*
|
|
640
|
+
* const payment = usePaymentFlow({
|
|
641
|
+
* callbacks: { transactionSetup, cardInfo, validatePayment, accountQuery, billingUpdate },
|
|
642
|
+
* customerId,
|
|
643
|
+
* billingAddress,
|
|
644
|
+
* paymentMethod: "credit-card",
|
|
645
|
+
* shippingAccepted: true,
|
|
646
|
+
* });
|
|
647
|
+
* ```
|
|
648
|
+
*/
|
|
649
|
+
declare function usePaymentFlow({ callbacks, customerId, billingAddress, paymentMethod, shippingAccepted, }: UsePaymentFlowParams): {
|
|
650
|
+
isOpen: boolean;
|
|
651
|
+
setIsOpen: react.Dispatch<react.SetStateAction<boolean>>;
|
|
652
|
+
editCc: boolean;
|
|
653
|
+
setEditCc: react.Dispatch<react.SetStateAction<boolean>>;
|
|
654
|
+
unified: TTransactionSetup | null;
|
|
655
|
+
unifiedCc: TCardInfo | null;
|
|
656
|
+
unifiedResponse: boolean;
|
|
657
|
+
unifiedBilling: boolean;
|
|
658
|
+
unifiedPayment: TAccountQuery | null;
|
|
659
|
+
capturedBin: string | null;
|
|
660
|
+
handleBinCapture: (bin: string) => void;
|
|
661
|
+
};
|
|
662
|
+
|
|
578
663
|
/** Session info passed from the consumer's auth system. */
|
|
579
664
|
interface CartSessionInfo {
|
|
580
665
|
/** Auth status: "loading" | "authenticated" | "unauthenticated" */
|
|
@@ -997,4 +1082,4 @@ declare function useAugurPersistence(config: PersistenceConfig): {
|
|
|
997
1082
|
};
|
|
998
1083
|
};
|
|
999
1084
|
|
|
1000
|
-
export { AugurApiClient, AugurCallbacks, BatchInvMastDocParam, type CartActionCallbacks, type CartInitCallbacks, type CartPriceData, type CartPricingResult, type CartSessionInfo, type CreateSiteHooksConfig, type FormatPriceCallOptions, GetItemCategoryApiOptions, PageData, PersistenceConfig, type UseFormatPriceOptions, type UseStockOptions, createSiteHooks, useAugurPersistence, useBatchInvMastDoc, useCartActions, useCartHdrUid, useCartInitialization, useCartLineCount, useCartLines, useCartPricing, useCartQuantityTotal, useCartStore, useCategoryItemsInfinite, useClearCart, useCustomerInvoices, useCustomerOrders, useCustomerQuotes, useDebounce, useFormatPrice, useInvMast, useInvMastDoc, useInvMastStock, useInvoiceDetail, useItemAttributes, useItemCategory, useItemDetails, useItemFiltersStore, useItemPrice, useItemSearchInfinite, useJoomlaContent, useJoomlaContentList, useJoomlaMenu, useJoomlaMenuDoc, useOrderDetail, usePaginationPrefetch, useProductCategory, useProductSearch, useQuoteDetail, useSearchSuggestions, useSetCartHdrUid, useSetCartLines, useStock };
|
|
1085
|
+
export { AugurApiClient, AugurCallbacks, BatchInvMastDocParam, type CartActionCallbacks, type CartInitCallbacks, type CartPriceData, type CartPricingResult, type CartSessionInfo, type CreateSiteHooksConfig, type FormatPriceCallOptions, GetItemCategoryApiOptions, PageData, type PaymentBillingAddress, type PaymentFlowCallbacks, PersistenceConfig, type UseFormatPriceOptions, type UseStockOptions, createSiteHooks, useAugurPersistence, useBatchInvMastDoc, useCartActions, useCartHdrUid, useCartInitialization, useCartLineCount, useCartLines, useCartPricing, useCartQuantityTotal, useCartStore, useCategoryItemsInfinite, useClearCart, useCustomerInvoices, useCustomerOrders, useCustomerQuotes, useDebounce, useFormatPrice, useInvMast, useInvMastDoc, useInvMastStock, useInvoiceDetail, useItemAttributes, useItemCategory, useItemDetails, useItemFiltersStore, useItemPrice, useItemSearchInfinite, useJoomlaContent, useJoomlaContentList, useJoomlaMenu, useJoomlaMenuDoc, useOrderDetail, usePaginationPrefetch, usePaymentFlow, useProductCategory, useProductSearch, useQuoteDetail, useSearchSuggestions, useSetCartHdrUid, useSetCartLines, useStock };
|
package/dist/index.js
CHANGED
|
@@ -735,8 +735,168 @@ function useCartActions(callbacks) {
|
|
|
735
735
|
};
|
|
736
736
|
}
|
|
737
737
|
|
|
738
|
+
// src/hooks/use-payment-flow.ts
|
|
739
|
+
import { useCallback as useCallback2, useEffect as useEffect2, useState as useState2 } from "react";
|
|
740
|
+
function usePaymentFlow({
|
|
741
|
+
callbacks,
|
|
742
|
+
customerId,
|
|
743
|
+
billingAddress,
|
|
744
|
+
paymentMethod,
|
|
745
|
+
shippingAccepted
|
|
746
|
+
}) {
|
|
747
|
+
const [isOpen, setIsOpen] = useState2(false);
|
|
748
|
+
const [unified, setUnified] = useState2(null);
|
|
749
|
+
const [unifiedCc, setUnifiedCc] = useState2(null);
|
|
750
|
+
const [unifiedResponse, setUnifiedResponse] = useState2(false);
|
|
751
|
+
const [unifiedBilling, setUnifiedBilling] = useState2(false);
|
|
752
|
+
const [unifiedPayment, setUnifiedPayment] = useState2(null);
|
|
753
|
+
const [capturedBin, setCapturedBin] = useState2(null);
|
|
754
|
+
const [editCc, setEditCc] = useState2(false);
|
|
755
|
+
const handleBinCapture = useCallback2((bin) => {
|
|
756
|
+
setCapturedBin(bin);
|
|
757
|
+
}, []);
|
|
758
|
+
const postUnified = useCallback2(async () => {
|
|
759
|
+
if (!customerId) return;
|
|
760
|
+
try {
|
|
761
|
+
const result = await callbacks.transactionSetup({ customerId: String(customerId) });
|
|
762
|
+
if (!result) {
|
|
763
|
+
callbacks.toast?.error?.("Unable to initialize payment. Please try again.");
|
|
764
|
+
return;
|
|
765
|
+
}
|
|
766
|
+
setUnified(result);
|
|
767
|
+
} catch (error) {
|
|
768
|
+
console.error("transactionSetup failed:", error);
|
|
769
|
+
callbacks.toast?.error?.("Unable to initialize payment. Please try again.");
|
|
770
|
+
}
|
|
771
|
+
}, [customerId, callbacks]);
|
|
772
|
+
const getCardInfo = useCallback2(async () => {
|
|
773
|
+
if (!unified?.transactionSetupId) return;
|
|
774
|
+
try {
|
|
775
|
+
const result = await callbacks.cardInfo({ transactionSetupId: unified.transactionSetupId });
|
|
776
|
+
if (!result) {
|
|
777
|
+
callbacks.toast?.error?.("Unable to verify card details. Please try again.");
|
|
778
|
+
return;
|
|
779
|
+
}
|
|
780
|
+
setUnifiedCc(result);
|
|
781
|
+
} catch (error) {
|
|
782
|
+
console.error("cardInfo failed:", error);
|
|
783
|
+
callbacks.toast?.error?.("Unable to verify card details. Please try again.");
|
|
784
|
+
}
|
|
785
|
+
}, [unified, callbacks]);
|
|
786
|
+
const verifyUnified = useCallback2(async () => {
|
|
787
|
+
if (!unified?.transactionSetupId || !customerId) return;
|
|
788
|
+
try {
|
|
789
|
+
const result = await callbacks.validatePayment({
|
|
790
|
+
transactionSetupId: unified.transactionSetupId,
|
|
791
|
+
customerId: String(customerId)
|
|
792
|
+
});
|
|
793
|
+
if (!result) {
|
|
794
|
+
callbacks.toast?.error?.("Payment verification failed. Please try again.");
|
|
795
|
+
return;
|
|
796
|
+
}
|
|
797
|
+
setUnifiedResponse(result.valid);
|
|
798
|
+
if (result.valid) {
|
|
799
|
+
await getCardInfo();
|
|
800
|
+
}
|
|
801
|
+
} catch (error) {
|
|
802
|
+
console.error("validatePayment failed:", error);
|
|
803
|
+
callbacks.toast?.error?.("Payment verification failed. Please try again.");
|
|
804
|
+
}
|
|
805
|
+
}, [unified, customerId, getCardInfo, callbacks]);
|
|
806
|
+
const getUnifiedPayment = useCallback2(async () => {
|
|
807
|
+
if (!unified?.transactionSetupId || !customerId) return;
|
|
808
|
+
try {
|
|
809
|
+
const result = await callbacks.accountQuery({
|
|
810
|
+
transactionSetupId: unified.transactionSetupId,
|
|
811
|
+
customerId: String(customerId)
|
|
812
|
+
});
|
|
813
|
+
if (!result) {
|
|
814
|
+
callbacks.toast?.error?.("Unable to retrieve payment account. Please try again.");
|
|
815
|
+
return;
|
|
816
|
+
}
|
|
817
|
+
const payment = capturedBin && !result.Bin ? { ...result, Bin: capturedBin } : result;
|
|
818
|
+
setUnifiedPayment(payment);
|
|
819
|
+
} catch (error) {
|
|
820
|
+
console.error("accountQuery failed:", error);
|
|
821
|
+
callbacks.toast?.error?.("Unable to retrieve payment account. Please try again.");
|
|
822
|
+
}
|
|
823
|
+
}, [unified, customerId, capturedBin, callbacks]);
|
|
824
|
+
const updateUnifiedBilling = useCallback2(async () => {
|
|
825
|
+
if (!unified?.transactionSetupId || !billingAddress) return;
|
|
826
|
+
try {
|
|
827
|
+
const result = await callbacks.billingUpdate({
|
|
828
|
+
transactionSetupId: unified.transactionSetupId,
|
|
829
|
+
address1: billingAddress.address1,
|
|
830
|
+
address2: billingAddress.address2,
|
|
831
|
+
city: billingAddress.city,
|
|
832
|
+
state: billingAddress.state,
|
|
833
|
+
zip: billingAddress.postalCode
|
|
834
|
+
});
|
|
835
|
+
if (!result) {
|
|
836
|
+
callbacks.toast?.error?.("Billing update failed. Please try again.");
|
|
837
|
+
return;
|
|
838
|
+
}
|
|
839
|
+
setUnifiedBilling(true);
|
|
840
|
+
void getUnifiedPayment();
|
|
841
|
+
} catch (error) {
|
|
842
|
+
console.error("billingUpdate failed:", error);
|
|
843
|
+
callbacks.toast?.error?.("Billing update failed. Please try again.");
|
|
844
|
+
}
|
|
845
|
+
}, [unified, billingAddress, getUnifiedPayment, callbacks]);
|
|
846
|
+
useEffect2(() => {
|
|
847
|
+
if (isOpen && (!shippingAccepted || paymentMethod !== "credit-card")) {
|
|
848
|
+
setIsOpen(false);
|
|
849
|
+
}
|
|
850
|
+
}, [isOpen, shippingAccepted, paymentMethod]);
|
|
851
|
+
useEffect2(() => {
|
|
852
|
+
if (isOpen && shippingAccepted && paymentMethod === "credit-card" && unified === null) {
|
|
853
|
+
void postUnified();
|
|
854
|
+
}
|
|
855
|
+
}, [isOpen, shippingAccepted, paymentMethod, unified, postUnified]);
|
|
856
|
+
useEffect2(() => {
|
|
857
|
+
if (!isOpen && unified !== null && shippingAccepted && paymentMethod === "credit-card") {
|
|
858
|
+
void verifyUnified();
|
|
859
|
+
}
|
|
860
|
+
}, [isOpen, unified, shippingAccepted, paymentMethod, verifyUnified]);
|
|
861
|
+
useEffect2(() => {
|
|
862
|
+
if (unifiedResponse && billingAddress !== void 0 && unifiedCc?.transactionSetupId && paymentMethod === "credit-card") {
|
|
863
|
+
void updateUnifiedBilling();
|
|
864
|
+
}
|
|
865
|
+
}, [
|
|
866
|
+
unifiedResponse,
|
|
867
|
+
billingAddress,
|
|
868
|
+
unifiedCc?.transactionSetupId,
|
|
869
|
+
updateUnifiedBilling,
|
|
870
|
+
paymentMethod
|
|
871
|
+
]);
|
|
872
|
+
useEffect2(() => {
|
|
873
|
+
if (editCc) {
|
|
874
|
+
setIsOpen(true);
|
|
875
|
+
setUnified(null);
|
|
876
|
+
setUnifiedCc(null);
|
|
877
|
+
setUnifiedPayment(null);
|
|
878
|
+
setUnifiedBilling(false);
|
|
879
|
+
setUnifiedResponse(false);
|
|
880
|
+
setCapturedBin(null);
|
|
881
|
+
}
|
|
882
|
+
}, [editCc]);
|
|
883
|
+
return {
|
|
884
|
+
isOpen,
|
|
885
|
+
setIsOpen,
|
|
886
|
+
editCc,
|
|
887
|
+
setEditCc,
|
|
888
|
+
unified,
|
|
889
|
+
unifiedCc,
|
|
890
|
+
unifiedResponse,
|
|
891
|
+
unifiedBilling,
|
|
892
|
+
unifiedPayment,
|
|
893
|
+
capturedBin,
|
|
894
|
+
handleBinCapture
|
|
895
|
+
};
|
|
896
|
+
}
|
|
897
|
+
|
|
738
898
|
// src/hooks/use-cart-initialization.ts
|
|
739
|
-
import { useEffect as
|
|
899
|
+
import { useEffect as useEffect3, useMemo as useMemo4, useRef } from "react";
|
|
740
900
|
import { useQuery as useQuery13, useQueryClient as useQueryClient3 } from "@tanstack/react-query";
|
|
741
901
|
var MAX_RETRY_ATTEMPTS = 7;
|
|
742
902
|
var RETRY_DELAY_MS = 1e3;
|
|
@@ -763,7 +923,7 @@ function useCartInitialization(session, callbacks) {
|
|
|
763
923
|
const retryCountRef = useRef(0);
|
|
764
924
|
const isInitializingRef = useRef(false);
|
|
765
925
|
const prevStatusRef = useRef(effectiveSession.status);
|
|
766
|
-
|
|
926
|
+
useEffect3(() => {
|
|
767
927
|
const prevStatus = prevStatusRef.current;
|
|
768
928
|
prevStatusRef.current = effectiveSession.status;
|
|
769
929
|
if (prevStatus === "authenticated" && effectiveSession.status === "unauthenticated") {
|
|
@@ -772,7 +932,7 @@ function useCartInitialization(session, callbacks) {
|
|
|
772
932
|
queryClient.removeQueries({ queryKey: ["cart-also-bought"] });
|
|
773
933
|
}
|
|
774
934
|
}, [effectiveSession.status, clearCart, queryClient]);
|
|
775
|
-
|
|
935
|
+
useEffect3(() => {
|
|
776
936
|
if (cartHdrUid || effectiveSession.status === "loading") return;
|
|
777
937
|
if (effectiveSession.cartHdrUid && effectiveSession.status === "authenticated") {
|
|
778
938
|
setCartHdrUid(effectiveSession.cartHdrUid);
|
|
@@ -829,7 +989,7 @@ function useCartInitialization(session, callbacks) {
|
|
|
829
989
|
queryFn: async () => await callbacks.getCartLines(Number(cartHdrUid)) ?? [],
|
|
830
990
|
enabled: !!cartHdrUid
|
|
831
991
|
});
|
|
832
|
-
|
|
992
|
+
useEffect3(() => {
|
|
833
993
|
if (cartLinesData) {
|
|
834
994
|
setCartLines(cartLinesData);
|
|
835
995
|
}
|
|
@@ -915,7 +1075,7 @@ function useCartPricing(options = {}) {
|
|
|
915
1075
|
|
|
916
1076
|
// src/hooks/use-pagination-prefetch.ts
|
|
917
1077
|
import { useQueryClient as useQueryClient4 } from "@tanstack/react-query";
|
|
918
|
-
import { useCallback as
|
|
1078
|
+
import { useCallback as useCallback3 } from "react";
|
|
919
1079
|
var usePaginationPrefetch = ({
|
|
920
1080
|
queryKey,
|
|
921
1081
|
queryFn,
|
|
@@ -926,7 +1086,7 @@ var usePaginationPrefetch = ({
|
|
|
926
1086
|
enabled = true
|
|
927
1087
|
}) => {
|
|
928
1088
|
const queryClient = useQueryClient4();
|
|
929
|
-
const prefetchPage =
|
|
1089
|
+
const prefetchPage = useCallback3(
|
|
930
1090
|
async (page) => {
|
|
931
1091
|
if (!enabled) return;
|
|
932
1092
|
const offset = (page - 1) * pageSize;
|
|
@@ -943,7 +1103,7 @@ var usePaginationPrefetch = ({
|
|
|
943
1103
|
},
|
|
944
1104
|
[queryKey, queryFn, pageSize, queryKeyFn, staleTime, gcTime, queryClient, enabled]
|
|
945
1105
|
);
|
|
946
|
-
const handlePaginationHover =
|
|
1106
|
+
const handlePaginationHover = useCallback3(
|
|
947
1107
|
(page) => {
|
|
948
1108
|
const timeoutId = setTimeout(() => prefetchPage(page), 150);
|
|
949
1109
|
return () => clearTimeout(timeoutId);
|
|
@@ -1319,7 +1479,7 @@ function createSiteHooks(config = {}) {
|
|
|
1319
1479
|
}
|
|
1320
1480
|
|
|
1321
1481
|
// src/persistence/use-persistence.ts
|
|
1322
|
-
import { useState as
|
|
1482
|
+
import { useState as useState3, useEffect as useEffect5, useMemo as useMemo6 } from "react";
|
|
1323
1483
|
|
|
1324
1484
|
// src/persistence/serializer.ts
|
|
1325
1485
|
function serialize(data) {
|
|
@@ -1415,12 +1575,12 @@ function createPersister(config) {
|
|
|
1415
1575
|
}
|
|
1416
1576
|
|
|
1417
1577
|
// src/persistence/use-storage-monitor.ts
|
|
1418
|
-
import { useEffect as
|
|
1578
|
+
import { useEffect as useEffect4 } from "react";
|
|
1419
1579
|
var CHECK_INTERVAL_MS = 5 * 60 * 1e3;
|
|
1420
1580
|
function useStorageMonitor(config) {
|
|
1421
1581
|
const { key, limits = {}, maxStorageMB = 3 } = config;
|
|
1422
1582
|
const limitKeys = Object.keys(limits);
|
|
1423
|
-
|
|
1583
|
+
useEffect4(() => {
|
|
1424
1584
|
if (typeof window === "undefined" || limitKeys.length === 0) return;
|
|
1425
1585
|
function evict() {
|
|
1426
1586
|
const storage = window.localStorage;
|
|
@@ -1456,9 +1616,9 @@ function useStorageMonitor(config) {
|
|
|
1456
1616
|
|
|
1457
1617
|
// src/persistence/use-persistence.ts
|
|
1458
1618
|
function useAugurPersistence(config) {
|
|
1459
|
-
const [persister] =
|
|
1460
|
-
const [isMounted, setIsMounted] =
|
|
1461
|
-
|
|
1619
|
+
const [persister] = useState3(() => createPersister(config));
|
|
1620
|
+
const [isMounted, setIsMounted] = useState3(false);
|
|
1621
|
+
useEffect5(() => {
|
|
1462
1622
|
setIsMounted(true);
|
|
1463
1623
|
}, []);
|
|
1464
1624
|
useStorageMonitor(config);
|
|
@@ -1568,6 +1728,7 @@ export {
|
|
|
1568
1728
|
useJoomlaMenuDoc,
|
|
1569
1729
|
useOrderDetail,
|
|
1570
1730
|
usePaginationPrefetch,
|
|
1731
|
+
usePaymentFlow,
|
|
1571
1732
|
useProductCategory,
|
|
1572
1733
|
useProductSearch,
|
|
1573
1734
|
useQuoteDetail,
|