@tagadapay/plugin-sdk 1.0.7 → 1.0.9

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.
@@ -25,14 +25,20 @@ export function usePayment() {
25
25
  const challengeInProgressRef = useRef(false);
26
26
  // Initialize BasisTheory dynamically
27
27
  const [basisTheory, setBasisTheory] = useState(null);
28
+ const [isBasisTheoryLoading, setIsBasisTheoryLoading] = useState(true);
28
29
  useEffect(() => {
29
30
  let isMounted = true;
30
31
  const loadBasisTheory = async () => {
31
32
  try {
33
+ setIsBasisTheoryLoading(true);
32
34
  // Get API key from embedded configuration (with env override support)
33
35
  const apiKey = getBasisTheoryApiKey(environment?.environment || 'local');
34
36
  if (!apiKey) {
35
37
  console.warn('BasisTheory API key not configured');
38
+ if (isMounted) {
39
+ setError('BasisTheory API key not configured');
40
+ setIsBasisTheoryLoading(false);
41
+ }
36
42
  return;
37
43
  }
38
44
  const { BasisTheory } = await import('@basis-theory/basis-theory-js');
@@ -41,6 +47,7 @@ export function usePayment() {
41
47
  elements: false,
42
48
  });
43
49
  setBasisTheory(bt);
50
+ setIsBasisTheoryLoading(false);
44
51
  console.log('✅ BasisTheory initialized successfully');
45
52
  }
46
53
  }
@@ -48,6 +55,7 @@ export function usePayment() {
48
55
  console.error('Failed to load BasisTheory:', err);
49
56
  if (isMounted) {
50
57
  setError('Failed to initialize payment processor');
58
+ setIsBasisTheoryLoading(false);
51
59
  }
52
60
  }
53
61
  };
@@ -146,6 +154,9 @@ export function usePayment() {
146
154
  }, [apiService, startChallenge, startPolling]);
147
155
  // Create card payment instrument
148
156
  const createCardPaymentInstrument = useCallback(async (cardData) => {
157
+ if (isBasisTheoryLoading) {
158
+ throw new Error('Payment processor is still initializing. Please wait...');
159
+ }
149
160
  if (!basisTheory) {
150
161
  throw new Error('Payment processor not initialized');
151
162
  }
@@ -184,9 +195,12 @@ export function usePayment() {
184
195
  console.error('Error creating card payment instrument:', error);
185
196
  throw error;
186
197
  }
187
- }, [basisTheory, apiService]);
198
+ }, [basisTheory, apiService, isBasisTheoryLoading]);
188
199
  // Create Apple Pay payment instrument
189
200
  const createApplePayPaymentInstrument = useCallback(async (applePayToken) => {
201
+ if (isBasisTheoryLoading) {
202
+ throw new Error('Payment processor is still initializing. Please wait...');
203
+ }
190
204
  if (!applePayToken.id) {
191
205
  throw new Error('Apple Pay token is missing');
192
206
  }
@@ -213,7 +227,7 @@ export function usePayment() {
213
227
  console.error('Error creating Apple Pay payment instrument:', error);
214
228
  throw error;
215
229
  }
216
- }, [apiService]);
230
+ }, [apiService, isBasisTheoryLoading]);
217
231
  // Process payment directly with checkout session
218
232
  const processPaymentDirect = useCallback(async (checkoutSessionId, paymentInstrumentId, threedsSessionId, options = {}) => {
219
233
  try {
@@ -335,7 +349,7 @@ export function usePayment() {
335
349
  processPaymentWithInstrument,
336
350
  createCardPaymentInstrument,
337
351
  createApplePayPaymentInstrument,
338
- isLoading,
352
+ isLoading: isLoading || isBasisTheoryLoading,
339
353
  error,
340
354
  clearError,
341
355
  currentPaymentId,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tagadapay/plugin-sdk",
3
- "version": "1.0.7",
3
+ "version": "1.0.9",
4
4
  "description": "Modern React SDK for building Tagada Pay plugins",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",