@tagadapay/plugin-sdk 2.8.7 → 2.8.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.
Files changed (43) hide show
  1. package/dist/react/config/environment.d.ts +1 -22
  2. package/dist/react/config/environment.js +1 -132
  3. package/dist/react/utils/deviceInfo.d.ts +1 -39
  4. package/dist/react/utils/deviceInfo.js +1 -163
  5. package/dist/react/utils/jwtDecoder.d.ts +1 -14
  6. package/dist/react/utils/jwtDecoder.js +1 -86
  7. package/dist/react/utils/tokenStorage.d.ts +1 -16
  8. package/dist/react/utils/tokenStorage.js +1 -53
  9. package/dist/v2/core/client.d.ts +92 -0
  10. package/dist/v2/core/client.js +386 -0
  11. package/dist/v2/core/config/environment.d.ts +22 -0
  12. package/dist/v2/core/config/environment.js +140 -0
  13. package/dist/v2/core/pathRemapping.js +61 -3
  14. package/dist/v2/core/resources/apiClient.d.ts +8 -0
  15. package/dist/v2/core/resources/apiClient.js +30 -9
  16. package/dist/v2/core/resources/funnel.d.ts +253 -16
  17. package/dist/v2/core/resources/payments.d.ts +23 -0
  18. package/dist/v2/core/types.d.ts +271 -0
  19. package/dist/v2/core/types.js +4 -0
  20. package/dist/v2/core/utils/deviceInfo.d.ts +39 -0
  21. package/dist/v2/core/utils/deviceInfo.js +162 -0
  22. package/dist/v2/core/utils/eventDispatcher.d.ts +10 -0
  23. package/dist/v2/core/utils/eventDispatcher.js +24 -0
  24. package/dist/v2/core/utils/jwtDecoder.d.ts +14 -0
  25. package/dist/v2/core/utils/jwtDecoder.js +85 -0
  26. package/dist/v2/core/utils/pluginConfig.js +6 -0
  27. package/dist/v2/core/utils/tokenStorage.d.ts +19 -0
  28. package/dist/v2/core/utils/tokenStorage.js +52 -0
  29. package/dist/v2/index.d.ts +2 -1
  30. package/dist/v2/index.js +1 -1
  31. package/dist/v2/react/components/DebugDrawer.js +90 -1
  32. package/dist/v2/react/hooks/__examples__/FunnelContextExample.d.ts +12 -0
  33. package/dist/v2/react/hooks/__examples__/FunnelContextExample.js +54 -0
  34. package/dist/v2/react/hooks/useFunnel.d.ts +2 -2
  35. package/dist/v2/react/hooks/useFunnel.js +209 -32
  36. package/dist/v2/react/hooks/useGoogleAutocomplete.js +26 -18
  37. package/dist/v2/react/hooks/useISOData.js +4 -2
  38. package/dist/v2/react/hooks/useOffersQuery.d.ts +24 -29
  39. package/dist/v2/react/hooks/useOffersQuery.js +164 -204
  40. package/dist/v2/react/hooks/usePaymentQuery.js +99 -6
  41. package/dist/v2/react/providers/TagadaProvider.d.ts +8 -21
  42. package/dist/v2/react/providers/TagadaProvider.js +79 -673
  43. package/package.json +1 -1
@@ -87,15 +87,28 @@ export function usePaymentQuery() {
87
87
  },
88
88
  onSuccess: (successPayment) => {
89
89
  setIsLoading(false);
90
- options.onSuccess?.({
90
+ const response = {
91
91
  paymentId: successPayment.id,
92
92
  payment: successPayment,
93
- });
93
+ // Extract order from payment if available (for funnel path resolution)
94
+ order: successPayment.order,
95
+ };
96
+ // Legacy callback (backwards compatibility)
97
+ options.onSuccess?.(response);
98
+ // Funnel-aligned callback (recommended)
99
+ options.onPaymentSuccess?.(response);
94
100
  },
95
101
  onFailure: (errorMsg) => {
96
102
  setError(errorMsg);
97
103
  setIsLoading(false);
104
+ // Legacy callback (backwards compatibility)
98
105
  options.onFailure?.(errorMsg);
106
+ // Funnel-aligned callback (recommended)
107
+ options.onPaymentFailed?.({
108
+ code: 'PAYMENT_FAILED',
109
+ message: errorMsg,
110
+ payment,
111
+ });
99
112
  },
100
113
  });
101
114
  }
@@ -105,22 +118,57 @@ export function usePaymentQuery() {
105
118
  const errorMsg = _error instanceof Error ? _error.message : 'Failed to start 3DS challenge';
106
119
  setError(errorMsg);
107
120
  setIsLoading(false);
121
+ // Legacy callback (backwards compatibility)
108
122
  options.onFailure?.(errorMsg);
123
+ // Funnel-aligned callback (recommended)
124
+ options.onPaymentFailed?.({
125
+ code: '3DS_CHALLENGE_FAILED',
126
+ message: errorMsg,
127
+ payment,
128
+ });
109
129
  }
110
130
  }
111
131
  break;
112
132
  case 'processor_auth':
113
133
  case 'redirect': {
114
- if (actionData.metadata?.redirect?.redirectUrl) {
134
+ // Only auto-redirect if explicitly enabled (disableAutoRedirect: false)
135
+ // Default behavior: disable redirects and let funnel orchestrator handle navigation
136
+ const shouldRedirect = options.disableAutoRedirect === false;
137
+ if (shouldRedirect && actionData.metadata?.redirect?.redirectUrl) {
115
138
  window.location.href = actionData.metadata.redirect.redirectUrl;
116
139
  }
140
+ else {
141
+ // If auto-redirect is disabled AND payment succeeded, call success callbacks
142
+ // This allows funnel orchestrator to handle navigation
143
+ if (payment.status === 'succeeded') {
144
+ setIsLoading(false);
145
+ const response = {
146
+ paymentId: payment.id,
147
+ payment,
148
+ // Extract order from payment if available (for funnel path resolution)
149
+ order: payment.order,
150
+ };
151
+ // Legacy callback (backwards compatibility)
152
+ options.onSuccess?.(response);
153
+ // Funnel-aligned callback (recommended)
154
+ options.onPaymentSuccess?.(response);
155
+ }
156
+ }
117
157
  break;
118
158
  }
119
159
  case 'error': {
120
160
  const errorMsg = actionData.message || 'Payment processing failed';
161
+ const errorCode = actionData.errorCode || 'PAYMENT_FAILED';
121
162
  setError(errorMsg);
122
163
  setIsLoading(false);
164
+ // Legacy callback (backwards compatibility)
123
165
  options.onFailure?.(errorMsg);
166
+ // Funnel-aligned callback (recommended)
167
+ options.onPaymentFailed?.({
168
+ code: errorCode,
169
+ message: errorMsg,
170
+ payment,
171
+ });
124
172
  break;
125
173
  }
126
174
  }
@@ -147,7 +195,15 @@ export function usePaymentQuery() {
147
195
  }
148
196
  else if (response.payment.status === 'succeeded') {
149
197
  setIsLoading(false);
150
- options.onSuccess?.(response);
198
+ // Ensure order is at response root (extract from payment if needed)
199
+ const successResponse = {
200
+ ...response,
201
+ order: response.order || response.payment.order,
202
+ };
203
+ // Legacy callback (backwards compatibility)
204
+ options.onSuccess?.(successResponse);
205
+ // Funnel-aligned callback (recommended)
206
+ options.onPaymentSuccess?.(successResponse);
151
207
  }
152
208
  else {
153
209
  // Start polling for payment status
@@ -157,15 +213,28 @@ export function usePaymentQuery() {
157
213
  },
158
214
  onSuccess: (payment) => {
159
215
  setIsLoading(false);
160
- options.onSuccess?.({
216
+ const successResponse = {
161
217
  paymentId: payment.id,
162
218
  payment,
163
- });
219
+ // Extract order from payment if available (for funnel path resolution)
220
+ order: payment.order,
221
+ };
222
+ // Legacy callback (backwards compatibility)
223
+ options.onSuccess?.(successResponse);
224
+ // Funnel-aligned callback (recommended)
225
+ options.onPaymentSuccess?.(successResponse);
164
226
  },
165
227
  onFailure: (errorMsg) => {
166
228
  setError(errorMsg);
167
229
  setIsLoading(false);
230
+ // Legacy callback (backwards compatibility)
168
231
  options.onFailure?.(errorMsg);
232
+ // Funnel-aligned callback (recommended)
233
+ options.onPaymentFailed?.({
234
+ code: 'PAYMENT_FAILED',
235
+ message: errorMsg,
236
+ payment: response.payment,
237
+ });
169
238
  },
170
239
  });
171
240
  }
@@ -175,7 +244,13 @@ export function usePaymentQuery() {
175
244
  const errorMsg = _error instanceof Error ? _error.message : 'Payment failed';
176
245
  setError(errorMsg);
177
246
  setIsLoading(false);
247
+ // Legacy callback (backwards compatibility)
178
248
  options.onFailure?.(errorMsg);
249
+ // Funnel-aligned callback (recommended)
250
+ options.onPaymentFailed?.({
251
+ code: 'PAYMENT_PROCESSING_ERROR',
252
+ message: errorMsg,
253
+ });
179
254
  throw _error;
180
255
  }
181
256
  }, [paymentsResource, handlePaymentAction, startPolling]);
@@ -205,7 +280,13 @@ export function usePaymentQuery() {
205
280
  setIsLoading(false);
206
281
  const errorMsg = _error instanceof Error ? _error.message : 'Payment failed';
207
282
  setError(errorMsg);
283
+ // Legacy callback (backwards compatibility)
208
284
  options.onFailure?.(errorMsg);
285
+ // Funnel-aligned callback (recommended)
286
+ options.onPaymentFailed?.({
287
+ code: 'CARD_PAYMENT_ERROR',
288
+ message: errorMsg,
289
+ });
209
290
  throw _error;
210
291
  }
211
292
  }, [createCardPaymentInstrument, createSession, processPaymentDirect]);
@@ -223,7 +304,13 @@ export function usePaymentQuery() {
223
304
  setIsLoading(false);
224
305
  const errorMsg = _error instanceof Error ? _error.message : 'Apple Pay payment failed';
225
306
  setError(errorMsg);
307
+ // Legacy callback (backwards compatibility)
226
308
  options.onFailure?.(errorMsg);
309
+ // Funnel-aligned callback (recommended)
310
+ options.onPaymentFailed?.({
311
+ code: 'APPLE_PAY_ERROR',
312
+ message: errorMsg,
313
+ });
227
314
  throw _error;
228
315
  }
229
316
  }, [createApplePayPaymentInstrument, processPaymentDirect]);
@@ -238,7 +325,13 @@ export function usePaymentQuery() {
238
325
  setIsLoading(false);
239
326
  const errorMsg = _error instanceof Error ? _error.message : 'Payment failed';
240
327
  setError(errorMsg);
328
+ // Legacy callback (backwards compatibility)
241
329
  options.onFailure?.(errorMsg);
330
+ // Funnel-aligned callback (recommended)
331
+ options.onPaymentFailed?.({
332
+ code: 'PAYMENT_INSTRUMENT_ERROR',
333
+ message: errorMsg,
334
+ });
242
335
  throw _error;
243
336
  }
244
337
  }, [processPaymentDirect]);
@@ -1,23 +1,11 @@
1
1
  import { ReactNode } from 'react';
2
- import { PluginConfig, RawPluginConfig } from '../../../react/hooks/usePluginConfig';
2
+ import { TagadaState } from '../../core/client';
3
+ import { RawPluginConfig } from '../../core/utils/pluginConfig';
4
+ import { Environment, EnvironmentConfig } from '../../core/types';
3
5
  import { ApiService } from '../../../react/services/apiService';
4
- import { AuthState, Currency, Customer, Environment, EnvironmentConfig, Locale, Session, Store } from '../../../react/types';
5
- import { convertCurrency, formatMoney, formatMoneyWithoutSymbol, formatSimpleMoney, getCurrencyInfo, minorUnitsToMajorUnits, moneyStringOrNumberToMinorUnits } from '../../../react/utils/money';
6
- interface TagadaContextValue {
7
- auth: AuthState;
8
- session: Session | null;
9
- customer: Customer | null;
10
- locale: Locale;
11
- currency: Currency;
12
- store: Store | null;
13
- environment: EnvironmentConfig;
6
+ import { formatMoney, formatMoneyWithoutSymbol, formatSimpleMoney, getCurrencyInfo, minorUnitsToMajorUnits, moneyStringOrNumberToMinorUnits, convertCurrency } from '../../../react/utils/money';
7
+ interface TagadaContextValue extends TagadaState {
14
8
  apiService: ApiService;
15
- isLoading: boolean;
16
- isInitialized: boolean;
17
- isSessionInitialized: boolean;
18
- debugMode: boolean;
19
- pluginConfig: PluginConfig;
20
- pluginConfigLoading: boolean;
21
9
  debugCheckout: {
22
10
  isActive: boolean;
23
11
  data: any;
@@ -40,7 +28,7 @@ interface TagadaContextValue {
40
28
  notifyCheckoutChanged: () => Promise<void>;
41
29
  notifyOrderBumpChanged: () => Promise<void>;
42
30
  unregisterCheckoutRefresh: (refreshFn?: () => Promise<void>) => void;
43
- unregisterOrderBumpRefresh: () => void;
31
+ unregisterOrderBumpRefresh: (refreshFn?: () => Promise<void>) => void;
44
32
  };
45
33
  money: {
46
34
  formatMoney: typeof formatMoney;
@@ -61,8 +49,7 @@ interface TagadaProviderProps {
61
49
  blockUntilSessionReady?: boolean;
62
50
  rawPluginConfig?: RawPluginConfig;
63
51
  }
64
- export declare function TagadaProvider({ children, environment, customApiConfig, debugMode, // Remove default, will be set based on environment
65
- localConfig, blockUntilSessionReady, // Default to new non-blocking behavior
66
- rawPluginConfig, }: TagadaProviderProps): import("react/jsx-runtime").JSX.Element;
52
+ export declare function TagadaProvider({ children, environment, customApiConfig, // Ignored for now in TagadaClient, or need to add support
53
+ debugMode, localConfig, blockUntilSessionReady, rawPluginConfig, }: TagadaProviderProps): import("react/jsx-runtime").JSX.Element;
67
54
  export declare function useTagadaContext(): TagadaContextValue;
68
55
  export {};