@tagadapay/plugin-sdk 2.2.6 → 2.2.8
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.
|
@@ -4,7 +4,7 @@ import { useTagadaContext } from '../providers/TagadaProvider';
|
|
|
4
4
|
import { collectTrackingData } from '../utils/trackingUtils';
|
|
5
5
|
import { usePluginConfig } from './usePluginConfig';
|
|
6
6
|
export function useCheckout(options = {}) {
|
|
7
|
-
const { apiService, updateCheckoutDebugData, refreshCoordinator, currency } = useTagadaContext();
|
|
7
|
+
const { apiService, updateCheckoutDebugData, refreshCoordinator, currency, isSessionInitialized } = useTagadaContext();
|
|
8
8
|
const { storeId } = usePluginConfig();
|
|
9
9
|
const { code: currentCurrency } = useCurrency();
|
|
10
10
|
const [checkout, setCheckout] = useState(null);
|
|
@@ -52,6 +52,10 @@ export function useCheckout(options = {}) {
|
|
|
52
52
|
console.warn('[Checkout] Cannot init - checkoutToken already provided:', providedToken.substring(0, 8) + '...');
|
|
53
53
|
throw new Error('Cannot initialize new checkout when checkoutToken is already provided. The existing checkout will be auto-loaded.');
|
|
54
54
|
}
|
|
55
|
+
// Check if CMS session is initialized before making API calls
|
|
56
|
+
if (!isSessionInitialized) {
|
|
57
|
+
throw new Error('Session not initialized. Please wait for the SDK to complete initialization before calling init().');
|
|
58
|
+
}
|
|
55
59
|
setIsLoading(true);
|
|
56
60
|
setError(null);
|
|
57
61
|
try {
|
|
@@ -104,8 +108,12 @@ export function useCheckout(options = {}) {
|
|
|
104
108
|
finally {
|
|
105
109
|
setIsLoading(false);
|
|
106
110
|
}
|
|
107
|
-
}, [apiService, currentCurrency, providedToken, storeId]);
|
|
111
|
+
}, [apiService, currentCurrency, providedToken, storeId, isSessionInitialized]);
|
|
108
112
|
const getCheckout = useCallback(async (checkoutToken) => {
|
|
113
|
+
// Check if CMS session is initialized before making API calls
|
|
114
|
+
if (!isSessionInitialized) {
|
|
115
|
+
throw new Error('Session not initialized. Please wait for the SDK to complete initialization before calling getCheckout().');
|
|
116
|
+
}
|
|
109
117
|
setIsLoading(true);
|
|
110
118
|
setError(null);
|
|
111
119
|
try {
|
|
@@ -138,7 +146,7 @@ export function useCheckout(options = {}) {
|
|
|
138
146
|
finally {
|
|
139
147
|
setIsLoading(false);
|
|
140
148
|
}
|
|
141
|
-
}, [apiService, currentCurrency]);
|
|
149
|
+
}, [apiService, currentCurrency, isSessionInitialized]);
|
|
142
150
|
const refresh = useCallback(async () => {
|
|
143
151
|
if (!currentCheckoutTokenRef.current) {
|
|
144
152
|
throw new Error('No checkout session to refresh');
|
|
@@ -159,6 +159,7 @@ localConfig, }) {
|
|
|
159
159
|
const [customer, setCustomer] = useState(null);
|
|
160
160
|
const [session, setSession] = useState(null);
|
|
161
161
|
const [store, setStore] = useState(null);
|
|
162
|
+
const [isSessionInitialized, setIsSessionInitialized] = useState(false);
|
|
162
163
|
// Initialize locale and currency with defaults
|
|
163
164
|
const [locale, setLocale] = useState({
|
|
164
165
|
locale: 'en-US',
|
|
@@ -283,6 +284,7 @@ localConfig, }) {
|
|
|
283
284
|
}
|
|
284
285
|
console.debug('[SDK] Session initialized successfully');
|
|
285
286
|
setIsInitialized(true);
|
|
287
|
+
setIsSessionInitialized(true); // Mark CMS session as ready
|
|
286
288
|
setIsLoading(false);
|
|
287
289
|
}
|
|
288
290
|
catch (error) {
|
|
@@ -330,6 +332,7 @@ localConfig, }) {
|
|
|
330
332
|
setIsLoading(false);
|
|
331
333
|
}
|
|
332
334
|
console.log('[SDK] ✅ Phase 3 Complete - Session initialization completed successfully');
|
|
335
|
+
setIsSessionInitialized(true); // Mark CMS session as ready
|
|
333
336
|
}
|
|
334
337
|
catch (error) {
|
|
335
338
|
console.error('[SDK] ❌ Initialization failed:', error);
|
|
@@ -391,6 +394,7 @@ localConfig, }) {
|
|
|
391
394
|
else {
|
|
392
395
|
console.error('[SDK] Failed to decode token');
|
|
393
396
|
setIsInitialized(true);
|
|
397
|
+
setIsSessionInitialized(false); // Session failed to initialize
|
|
394
398
|
setIsLoading(false);
|
|
395
399
|
}
|
|
396
400
|
}
|
|
@@ -469,6 +473,7 @@ localConfig, }) {
|
|
|
469
473
|
apiService,
|
|
470
474
|
isLoading,
|
|
471
475
|
isInitialized,
|
|
476
|
+
isSessionInitialized,
|
|
472
477
|
debugMode: finalDebugMode,
|
|
473
478
|
pluginConfig,
|
|
474
479
|
pluginConfigLoading: configLoading,
|
|
@@ -503,6 +508,7 @@ localConfig, }) {
|
|
|
503
508
|
apiService,
|
|
504
509
|
isLoading,
|
|
505
510
|
isInitialized,
|
|
511
|
+
isSessionInitialized,
|
|
506
512
|
finalDebugMode,
|
|
507
513
|
pluginConfig,
|
|
508
514
|
configLoading,
|