@tagadapay/plugin-sdk 2.7.32 → 2.7.33

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.
@@ -3,11 +3,13 @@
3
3
  * Replaces coordinator pattern with automatic cache invalidation
4
4
  */
5
5
  import { useCallback, useEffect, useState } from 'react';
6
+ import { useTagadaContext } from '../providers/TagadaProvider';
6
7
  import { getGlobalApiClient, useApiMutation, useInvalidateQuery } from './useApiQuery';
7
8
  import { useCheckoutQuery } from './useCheckoutQuery';
8
9
  export function useOrderBumpQuery(options) {
9
10
  const { checkoutToken, offerId } = options;
10
11
  const { invalidateCheckout, invalidatePromotions } = useInvalidateQuery();
12
+ const { isSessionInitialized } = useTagadaContext();
11
13
  const client = getGlobalApiClient();
12
14
  const { checkout, isLoading: isCheckoutLoading, isSuccess: isCheckoutSuccess } = useCheckoutQuery({
13
15
  checkoutToken: checkoutToken || undefined,
@@ -65,11 +67,15 @@ export function useOrderBumpQuery(options) {
65
67
  },
66
68
  });
67
69
  const toggle = useCallback(async (selected) => {
70
+ // Check if session is initialized (required for checkout query to run)
71
+ if (!isSessionInitialized) {
72
+ return { success: false, error: 'Session is not initialized yet. Please wait...' };
73
+ }
68
74
  // Wait for checkout to finish loading if it's still loading
69
75
  if (isCheckoutLoading) {
70
76
  return { success: false, error: 'Checkout session is still loading. Please wait...' };
71
77
  }
72
- // Check if checkout failed to load
78
+ // Check if checkout failed to load (only if we have a token)
73
79
  if (checkoutToken && !isCheckoutSuccess && !checkout) {
74
80
  return { success: false, error: 'Failed to load checkout session. Please refresh and try again.' };
75
81
  }
@@ -86,7 +92,7 @@ export function useOrderBumpQuery(options) {
86
92
  const error = err instanceof Error ? err : new Error('Failed to toggle order bump');
87
93
  return { success: false, error: error.message };
88
94
  }
89
- }, [checkout?.checkoutSession?.id, isSelected, toggleMutation, offerId, checkoutToken, actualCheckoutToken, isCheckoutLoading, isCheckoutSuccess, checkout]);
95
+ }, [checkout?.checkoutSession?.id, isSelected, toggleMutation, offerId, checkoutToken, actualCheckoutToken, isCheckoutLoading, isCheckoutSuccess, checkout, isSessionInitialized]);
90
96
  return {
91
97
  isSelected,
92
98
  isToggling: toggleMutation.isPending,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tagadapay/plugin-sdk",
3
- "version": "2.7.32",
3
+ "version": "2.7.33",
4
4
  "description": "Modern React SDK for building Tagada Pay plugins",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",