@tagadapay/plugin-sdk 2.7.31 → 2.7.32

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.
@@ -9,14 +9,10 @@ export function useOrderBumpQuery(options) {
9
9
  const { checkoutToken, offerId } = options;
10
10
  const { invalidateCheckout, invalidatePromotions } = useInvalidateQuery();
11
11
  const client = getGlobalApiClient();
12
- // Use checkout query only if no checkout is provided
13
- const { checkout } = useCheckoutQuery({
12
+ const { checkout, isLoading: isCheckoutLoading, isSuccess: isCheckoutSuccess } = useCheckoutQuery({
14
13
  checkoutToken: checkoutToken || undefined,
15
14
  });
16
- // Use provided checkout or loaded checkout
17
- // Get the actual checkout token from the checkout session
18
15
  const actualCheckoutToken = checkoutToken || checkout?.checkoutSession?.checkoutToken || null;
19
- // Function to check if order bump is selected
20
16
  const checkOrderBumpSelection = useCallback(() => {
21
17
  if (!checkout?.checkoutSession?.sessionLineItems) {
22
18
  return false;
@@ -69,6 +65,15 @@ export function useOrderBumpQuery(options) {
69
65
  },
70
66
  });
71
67
  const toggle = useCallback(async (selected) => {
68
+ // Wait for checkout to finish loading if it's still loading
69
+ if (isCheckoutLoading) {
70
+ return { success: false, error: 'Checkout session is still loading. Please wait...' };
71
+ }
72
+ // Check if checkout failed to load
73
+ if (checkoutToken && !isCheckoutSuccess && !checkout) {
74
+ return { success: false, error: 'Failed to load checkout session. Please refresh and try again.' };
75
+ }
76
+ // Check if checkout session is available
72
77
  if (!checkout?.checkoutSession?.id) {
73
78
  return { success: false, error: 'Checkout session not ready' };
74
79
  }
@@ -81,7 +86,7 @@ export function useOrderBumpQuery(options) {
81
86
  const error = err instanceof Error ? err : new Error('Failed to toggle order bump');
82
87
  return { success: false, error: error.message };
83
88
  }
84
- }, [checkout?.checkoutSession?.id, isSelected, toggleMutation, offerId, checkoutToken, actualCheckoutToken]);
89
+ }, [checkout?.checkoutSession?.id, isSelected, toggleMutation, offerId, checkoutToken, actualCheckoutToken, isCheckoutLoading, isCheckoutSuccess, checkout]);
85
90
  return {
86
91
  isSelected,
87
92
  isToggling: toggleMutation.isPending,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tagadapay/plugin-sdk",
3
- "version": "2.7.31",
3
+ "version": "2.7.32",
4
4
  "description": "Modern React SDK for building Tagada Pay plugins",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",