@tagadapay/plugin-sdk 2.2.8 → 2.2.9
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.
|
@@ -14,6 +14,11 @@ export function useCheckout(options = {}) {
|
|
|
14
14
|
const { checkoutToken: providedToken, autoLoadFromToken = true, } = options;
|
|
15
15
|
const currentCheckoutTokenRef = useRef(null);
|
|
16
16
|
const hasAutoLoadedRef = useRef(false);
|
|
17
|
+
const isSessionInitializedRef = useRef(isSessionInitialized);
|
|
18
|
+
// Keep ref in sync with state
|
|
19
|
+
useEffect(() => {
|
|
20
|
+
isSessionInitializedRef.current = isSessionInitialized;
|
|
21
|
+
}, [isSessionInitialized]);
|
|
17
22
|
// Update debug data whenever checkout state changes with comprehensive information
|
|
18
23
|
useEffect(() => {
|
|
19
24
|
const debugData = checkout
|
|
@@ -52,9 +57,21 @@ export function useCheckout(options = {}) {
|
|
|
52
57
|
console.warn('[Checkout] Cannot init - checkoutToken already provided:', providedToken.substring(0, 8) + '...');
|
|
53
58
|
throw new Error('Cannot initialize new checkout when checkoutToken is already provided. The existing checkout will be auto-loaded.');
|
|
54
59
|
}
|
|
55
|
-
//
|
|
60
|
+
// Wait for CMS session to initialize before making API calls
|
|
56
61
|
if (!isSessionInitialized) {
|
|
57
|
-
|
|
62
|
+
console.log('🔄 [useCheckout] Waiting for session initialization to complete...');
|
|
63
|
+
await new Promise((resolve) => {
|
|
64
|
+
const checkSession = () => {
|
|
65
|
+
if (isSessionInitializedRef.current) {
|
|
66
|
+
console.log('✅ [useCheckout] Session initialized, proceeding with checkout init');
|
|
67
|
+
resolve();
|
|
68
|
+
}
|
|
69
|
+
else {
|
|
70
|
+
setTimeout(checkSession, 100); // Check every 100ms
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
checkSession();
|
|
74
|
+
});
|
|
58
75
|
}
|
|
59
76
|
setIsLoading(true);
|
|
60
77
|
setError(null);
|
|
@@ -110,9 +127,21 @@ export function useCheckout(options = {}) {
|
|
|
110
127
|
}
|
|
111
128
|
}, [apiService, currentCurrency, providedToken, storeId, isSessionInitialized]);
|
|
112
129
|
const getCheckout = useCallback(async (checkoutToken) => {
|
|
113
|
-
//
|
|
130
|
+
// Wait for CMS session to initialize before making API calls
|
|
114
131
|
if (!isSessionInitialized) {
|
|
115
|
-
|
|
132
|
+
console.log('🔄 [useCheckout] Waiting for session initialization to complete...');
|
|
133
|
+
await new Promise((resolve) => {
|
|
134
|
+
const checkSession = () => {
|
|
135
|
+
if (isSessionInitializedRef.current) {
|
|
136
|
+
console.log('✅ [useCheckout] Session initialized, proceeding with getCheckout');
|
|
137
|
+
resolve();
|
|
138
|
+
}
|
|
139
|
+
else {
|
|
140
|
+
setTimeout(checkSession, 100); // Check every 100ms
|
|
141
|
+
}
|
|
142
|
+
};
|
|
143
|
+
checkSession();
|
|
144
|
+
});
|
|
116
145
|
}
|
|
117
146
|
setIsLoading(true);
|
|
118
147
|
setError(null);
|