@tagadapay/plugin-sdk 2.4.36 → 2.4.38

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.
@@ -1,11 +1,40 @@
1
1
  import { useCallback, useEffect, useRef, useState } from 'react';
2
2
  import { useCurrency } from '../hooks/useCurrency';
3
- import { useTagadaContext } from '../providers/TagadaProvider';
3
+ import { useTagadaContextSafe } 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, isSessionInitialized } = useTagadaContext();
7
+ const context = useTagadaContextSafe();
8
8
  const { storeId } = usePluginConfig();
9
+ // If context is not ready yet, return loading state
10
+ if (!context) {
11
+ return {
12
+ checkout: null,
13
+ error: null,
14
+ isLoading: true,
15
+ isInitialized: false,
16
+ initialized: false,
17
+ init: async () => ({ checkoutUrl: '', checkoutSession: {}, checkoutToken: '' }),
18
+ getCheckout: async () => ({}),
19
+ refresh: async () => { },
20
+ updateAddress: async () => ({ success: false, shippingCountryChanged: false, billingCountryChanged: false }),
21
+ setCheckoutInfo: async () => ({ success: false }),
22
+ applyPromotionCode: async () => ({ success: false }),
23
+ removePromotion: async () => ({ success: false }),
24
+ getAppliedPromotions: async () => [],
25
+ updateLineItems: async () => ({ success: false }),
26
+ addLineItems: async () => ({ success: false }),
27
+ removeLineItems: async () => ({ success: false }),
28
+ setItemQuantity: async () => ({ success: false }),
29
+ toggleOrderBump: async () => ({ success: false }),
30
+ updateCustomer: async () => ({ success: false }),
31
+ updateCustomerAndSessionInfo: async () => ({ success: false }),
32
+ previewOrderSummary: async () => ({ savings: 0, savingsPct: 0, currency: 'USD' }),
33
+ previewCheckoutSession: async () => ({ success: false, preview: {} }),
34
+ clear: () => { },
35
+ };
36
+ }
37
+ const { apiService, updateCheckoutDebugData, refreshCoordinator, currency, isSessionInitialized } = context;
9
38
  const { code: currentCurrency } = useCurrency();
10
39
  const [checkout, setCheckout] = useState(null);
11
40
  const [isLoading, setIsLoading] = useState(false);
@@ -1,7 +1,21 @@
1
1
  import { useState, useCallback, useEffect } from 'react';
2
- import { useTagadaContext } from '../providers/TagadaProvider';
2
+ import { useTagadaContextSafe } from '../providers/TagadaProvider';
3
3
  export function useOrderBump(options) {
4
- const { apiService, refreshCoordinator } = useTagadaContext();
4
+ const context = useTagadaContextSafe();
5
+ // If context is not ready yet, return loading state
6
+ if (!context) {
7
+ return {
8
+ isSelected: false,
9
+ preview: null,
10
+ savings: null,
11
+ isLoading: false,
12
+ isToggling: false,
13
+ error: null,
14
+ toggle: async () => ({ success: false }),
15
+ refreshPreview: async () => { },
16
+ };
17
+ }
18
+ const { apiService, refreshCoordinator } = context;
5
19
  const { checkoutSessionId, offerId, orderBumpType = 'vip', autoPreview = true } = options;
6
20
  const [isSelected, setIsSelected] = useState(false);
7
21
  const [preview, setPreview] = useState(null);
@@ -1,7 +1,7 @@
1
1
  import { useBasisTheory } from '@basis-theory/basis-theory-react';
2
2
  import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
3
3
  import { getBasisTheoryApiKey } from '../config/payment';
4
- import { useTagadaContext } from '../providers/TagadaProvider';
4
+ import { useTagadaContextSafe } from '../providers/TagadaProvider';
5
5
  import { usePaymentPolling } from './usePaymentPolling';
6
6
  import { useThreeds } from './useThreeds';
7
7
  // Helper function to format expiry date
@@ -16,7 +16,23 @@ const getCardMonthAndYear = (expiryDate) => {
16
16
  };
17
17
  };
18
18
  export function usePayment() {
19
- const { apiService, environment } = useTagadaContext();
19
+ const context = useTagadaContextSafe();
20
+ // If context is not ready yet, return loading state
21
+ if (!context) {
22
+ return {
23
+ processCardPayment: async () => ({ paymentId: '', payment: {} }),
24
+ processApplePayPayment: async () => ({ paymentId: '', payment: {} }),
25
+ processPaymentWithInstrument: async () => ({ paymentId: '', payment: {} }),
26
+ createCardPaymentInstrument: async () => ({ id: '', token: '', type: 'card' }),
27
+ createApplePayPaymentInstrument: async () => ({ id: '', token: '', type: 'apple_pay' }),
28
+ getCardPaymentInstruments: async () => [],
29
+ isLoading: false,
30
+ error: null,
31
+ clearError: () => { },
32
+ currentPaymentId: null,
33
+ };
34
+ }
35
+ const { apiService, environment } = context;
20
36
  const [isLoading, setIsLoading] = useState(false);
21
37
  const [error, setError] = useState(null);
22
38
  const [currentPaymentId, setCurrentPaymentId] = useState(null);
@@ -162,11 +162,8 @@ export const loadPluginConfig = async (configVariant = 'default', rawConfig) =>
162
162
  */
163
163
  export const usePluginConfig = () => {
164
164
  const context = useTagadaContextSafe();
165
- // Log to confirm we're using the updated SDK
166
- console.log('🔧 [SDK DEBUG] usePluginConfig called - using updated SDK version with safe context handling');
167
165
  // If context is not ready yet, return loading state
168
166
  if (!context) {
169
- console.log('🔧 [SDK DEBUG] Context not ready yet, returning loading state');
170
167
  return {
171
168
  storeId: undefined,
172
169
  accountId: undefined,
@@ -176,11 +173,6 @@ export const usePluginConfig = () => {
176
173
  };
177
174
  }
178
175
  const { pluginConfig, pluginConfigLoading } = context;
179
- console.log('🔧 [SDK DEBUG] Context ready, returning plugin config:', {
180
- storeId: pluginConfig.storeId,
181
- loading: pluginConfigLoading,
182
- hasConfig: !!pluginConfig.config
183
- });
184
176
  return {
185
177
  storeId: pluginConfig.storeId,
186
178
  accountId: pluginConfig.accountId,
@@ -1,9 +1,23 @@
1
1
  import { useCallback, useEffect, useMemo, useState } from 'react';
2
- import { useTagadaContext } from '../providers/TagadaProvider';
2
+ import { useTagadaContextSafe } from '../providers/TagadaProvider';
3
3
  import { usePluginConfig } from './usePluginConfig';
4
4
  export function useProducts(options = {}) {
5
- const { apiService } = useTagadaContext();
5
+ const context = useTagadaContextSafe();
6
6
  const { storeId } = usePluginConfig();
7
+ // If context is not ready yet, return loading state
8
+ if (!context) {
9
+ return {
10
+ products: [],
11
+ isLoading: true,
12
+ error: null,
13
+ getVariant: () => undefined,
14
+ getProduct: () => undefined,
15
+ getAllVariants: () => [],
16
+ filterVariants: () => [],
17
+ refetch: async () => { },
18
+ };
19
+ }
20
+ const { apiService } = context;
7
21
  const [products, setProducts] = useState([]);
8
22
  const [isLoading, setIsLoading] = useState(false);
9
23
  const [error, setError] = useState(null);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tagadapay/plugin-sdk",
3
- "version": "2.4.36",
3
+ "version": "2.4.38",
4
4
  "description": "Modern React SDK for building Tagada Pay plugins",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",