@tagadapay/plugin-sdk 2.7.30 → 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.
@@ -5,7 +5,6 @@
5
5
  export interface UseOrderBumpQueryOptions {
6
6
  checkoutToken: string | null;
7
7
  offerId: string;
8
- checkout?: any;
9
8
  }
10
9
  export interface UseOrderBumpQueryResult {
11
10
  isSelected: boolean;
@@ -2,23 +2,17 @@
2
2
  * Order Bump Hook using TanStack Query
3
3
  * Replaces coordinator pattern with automatic cache invalidation
4
4
  */
5
- import { useState, useCallback, useEffect } from 'react';
6
- import { useApiMutation, useInvalidateQuery, getGlobalApiClient } from './useApiQuery';
5
+ import { useCallback, useEffect, useState } from 'react';
6
+ import { getGlobalApiClient, useApiMutation, useInvalidateQuery } from './useApiQuery';
7
7
  import { useCheckoutQuery } from './useCheckoutQuery';
8
8
  export function useOrderBumpQuery(options) {
9
- const { checkoutToken, offerId, checkout: providedCheckout } = options;
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: loadedCheckout } = useCheckoutQuery({
12
+ const { checkout, isLoading: isCheckoutLoading, isSuccess: isCheckoutSuccess } = useCheckoutQuery({
14
13
  checkoutToken: checkoutToken || undefined,
15
- enabled: !providedCheckout, // Enable if no checkout is provided, regardless of token
16
14
  });
17
- // Use provided checkout or loaded checkout
18
- const checkout = providedCheckout || loadedCheckout;
19
- // Get the actual checkout token from the checkout session
20
15
  const actualCheckoutToken = checkoutToken || checkout?.checkoutSession?.checkoutToken || null;
21
- // Function to check if order bump is selected
22
16
  const checkOrderBumpSelection = useCallback(() => {
23
17
  if (!checkout?.checkoutSession?.sessionLineItems) {
24
18
  return false;
@@ -71,6 +65,15 @@ export function useOrderBumpQuery(options) {
71
65
  },
72
66
  });
73
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
74
77
  if (!checkout?.checkoutSession?.id) {
75
78
  return { success: false, error: 'Checkout session not ready' };
76
79
  }
@@ -83,7 +86,7 @@ export function useOrderBumpQuery(options) {
83
86
  const error = err instanceof Error ? err : new Error('Failed to toggle order bump');
84
87
  return { success: false, error: error.message };
85
88
  }
86
- }, [checkout?.checkoutSession?.id, isSelected, toggleMutation, offerId, checkoutToken, actualCheckoutToken]);
89
+ }, [checkout?.checkoutSession?.id, isSelected, toggleMutation, offerId, checkoutToken, actualCheckoutToken, isCheckoutLoading, isCheckoutSuccess, checkout]);
87
90
  return {
88
91
  isSelected,
89
92
  isToggling: toggleMutation.isPending,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tagadapay/plugin-sdk",
3
- "version": "2.7.30",
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",