@tagadapay/plugin-sdk 3.1.12 → 3.1.22

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 (106) hide show
  1. package/build-cdn.js +129 -11
  2. package/dist/data/iso3166.d.ts +23 -33
  3. package/dist/data/iso3166.js +134 -198
  4. package/dist/data/languages.d.ts +5 -64
  5. package/dist/data/languages.js +23 -143
  6. package/dist/external-tracker.js +968 -101
  7. package/dist/external-tracker.min.js +2 -2
  8. package/dist/external-tracker.min.js.map +4 -4
  9. package/dist/react/hooks/useISOData.js +1 -1
  10. package/dist/react/hooks/usePaymentPolling.d.ts +3 -3
  11. package/dist/tagada-sdk.js +12066 -0
  12. package/dist/tagada-sdk.min.js +50 -0
  13. package/dist/tagada-sdk.min.js.map +7 -0
  14. package/dist/v2/core/client.d.ts +4 -2
  15. package/dist/v2/core/client.js +4 -3
  16. package/dist/v2/core/errors.d.ts +75 -0
  17. package/dist/v2/core/errors.js +104 -0
  18. package/dist/v2/core/funnelClient.d.ts +2 -0
  19. package/dist/v2/core/index.d.ts +1 -0
  20. package/dist/v2/core/index.js +2 -0
  21. package/dist/v2/core/pixelMapping.d.ts +49 -0
  22. package/dist/v2/core/pixelMapping.js +325 -0
  23. package/dist/v2/core/resources/apiClient.d.ts +2 -0
  24. package/dist/v2/core/resources/apiClient.js +52 -9
  25. package/dist/v2/core/resources/checkout.d.ts +89 -30
  26. package/dist/v2/core/resources/checkout.js +8 -0
  27. package/dist/v2/core/resources/customer.d.ts +20 -19
  28. package/dist/v2/core/resources/funnel.d.ts +17 -17
  29. package/dist/v2/core/resources/payments.d.ts +84 -13
  30. package/dist/v2/core/resources/payments.js +26 -9
  31. package/dist/v2/core/types.d.ts +50 -12
  32. package/dist/v2/core/types.js +0 -3
  33. package/dist/v2/core/utils/checkout.d.ts +2 -2
  34. package/dist/v2/core/utils/checkout.js +7 -2
  35. package/dist/v2/core/utils/currency.d.ts +14 -0
  36. package/dist/v2/core/utils/currency.js +40 -0
  37. package/dist/v2/core/utils/index.d.ts +1 -0
  38. package/dist/v2/core/utils/index.js +2 -0
  39. package/dist/v2/core/utils/order.d.ts +11 -9
  40. package/dist/v2/core/utils/pluginConfig.d.ts +8 -0
  41. package/dist/v2/core/utils/pluginConfig.js +28 -0
  42. package/dist/v2/index.d.ts +3 -1
  43. package/dist/v2/index.js +1 -1
  44. package/dist/v2/react/components/FunnelScriptInjector.js +21 -0
  45. package/dist/v2/react/components/WhopCheckout.d.ts +24 -0
  46. package/dist/v2/react/components/WhopCheckout.js +231 -0
  47. package/dist/v2/react/hooks/__examples__/FunnelContextExample.js +1 -1
  48. package/dist/v2/react/hooks/payment-actions/useAirwallexRadarAction.d.ts +14 -0
  49. package/dist/v2/react/hooks/payment-actions/useAirwallexRadarAction.js +181 -0
  50. package/dist/v2/react/hooks/payment-actions/useErrorAction.d.ts +9 -0
  51. package/dist/v2/react/hooks/payment-actions/useErrorAction.js +21 -0
  52. package/dist/v2/react/hooks/payment-actions/useFinixRadarAction.d.ts +14 -0
  53. package/dist/v2/react/hooks/payment-actions/useFinixRadarAction.js +187 -0
  54. package/dist/v2/react/hooks/payment-actions/useKessPayAction.d.ts +11 -0
  55. package/dist/v2/react/hooks/payment-actions/useKessPayAction.js +91 -0
  56. package/dist/v2/react/hooks/payment-actions/useMasterCardAction.d.ts +24 -0
  57. package/dist/v2/react/hooks/payment-actions/useMasterCardAction.js +221 -0
  58. package/dist/v2/react/hooks/payment-actions/usePaymentActionHandler.d.ts +15 -0
  59. package/dist/v2/react/hooks/payment-actions/usePaymentActionHandler.js +142 -0
  60. package/dist/v2/react/hooks/payment-actions/useProcessorAuthAction.d.ts +3 -0
  61. package/dist/v2/react/hooks/payment-actions/useProcessorAuthAction.js +13 -0
  62. package/dist/v2/react/hooks/payment-actions/useRedirectAction.d.ts +10 -0
  63. package/dist/v2/react/hooks/payment-actions/useRedirectAction.js +35 -0
  64. package/dist/v2/react/hooks/payment-actions/useStripeRadarAction.d.ts +14 -0
  65. package/dist/v2/react/hooks/payment-actions/useStripeRadarAction.js +192 -0
  66. package/dist/v2/react/hooks/payment-actions/useThreedsAuthAction.d.ts +14 -0
  67. package/dist/v2/react/hooks/payment-actions/useThreedsAuthAction.js +81 -0
  68. package/dist/v2/react/hooks/payment-actions/useTrustFlowAction.d.ts +11 -0
  69. package/dist/v2/react/hooks/payment-actions/useTrustFlowAction.js +84 -0
  70. package/dist/v2/react/hooks/payment-processing/usePaymentInstruments.d.ts +14 -0
  71. package/dist/v2/react/hooks/payment-processing/usePaymentInstruments.js +36 -0
  72. package/dist/v2/react/hooks/payment-processing/usePaymentProcessors.d.ts +31 -0
  73. package/dist/v2/react/hooks/payment-processing/usePaymentProcessors.js +212 -0
  74. package/dist/v2/react/hooks/payment-redirect/useAirwallex3dsReturn.d.ts +14 -0
  75. package/dist/v2/react/hooks/payment-redirect/useAirwallex3dsReturn.js +207 -0
  76. package/dist/v2/react/hooks/payment-redirect/useGenericPaymentReturn.d.ts +12 -0
  77. package/dist/v2/react/hooks/payment-redirect/useGenericPaymentReturn.js +101 -0
  78. package/dist/v2/react/hooks/useCheckoutQuery.d.ts +6 -0
  79. package/dist/v2/react/hooks/useCheckoutQuery.js +45 -0
  80. package/dist/v2/react/hooks/useGeoLocation.d.ts +2 -1
  81. package/dist/v2/react/hooks/useGeoLocation.js +4 -2
  82. package/dist/v2/react/hooks/useISOData.js +1 -1
  83. package/dist/v2/react/hooks/usePaymentPolling.d.ts +3 -3
  84. package/dist/v2/react/hooks/usePaymentQuery.d.ts +18 -5
  85. package/dist/v2/react/hooks/usePaymentQuery.js +63 -1015
  86. package/dist/v2/react/hooks/usePaymentRetrieve.d.ts +3 -2
  87. package/dist/v2/react/hooks/usePaymentRetrieve.js +3 -1
  88. package/dist/v2/react/hooks/usePixelTracking.d.ts +5 -48
  89. package/dist/v2/react/hooks/usePixelTracking.js +212 -514
  90. package/dist/v2/react/hooks/useShippingRatesQuery.js +13 -5
  91. package/dist/v2/react/hooks/useWhopPaymentPolling.d.ts +30 -0
  92. package/dist/v2/react/hooks/useWhopPaymentPolling.js +61 -0
  93. package/dist/v2/react/index.d.ts +7 -0
  94. package/dist/v2/react/index.js +4 -0
  95. package/dist/v2/react/providers/ExpressPaymentMethodsProvider.d.ts +2 -1
  96. package/dist/v2/react/providers/ExpressPaymentMethodsProvider.js +3 -1
  97. package/dist/v2/react/providers/TagadaProvider.js +71 -2
  98. package/dist/v2/standalone/external-tracker.d.ts +52 -46
  99. package/dist/v2/standalone/external-tracker.js +205 -98
  100. package/dist/v2/standalone/index.d.ts +22 -0
  101. package/dist/v2/standalone/index.js +126 -1
  102. package/package.json +3 -3
  103. package/dist/react/utils/__tests__/urlUtils.test.d.ts +0 -1
  104. package/dist/react/utils/__tests__/urlUtils.test.js +0 -189
  105. package/dist/v2/core/__tests__/pathRemapping.test.d.ts +0 -11
  106. package/dist/v2/core/__tests__/pathRemapping.test.js +0 -776
@@ -3,18 +3,19 @@
3
3
  * Axios-based API client for payment endpoints
4
4
  */
5
5
  import { ApiClient } from './apiClient';
6
+ import type { Order } from '../types';
6
7
  export interface Payment {
7
8
  id: string;
8
9
  status: string;
9
10
  subStatus: string;
10
- requireAction: 'none' | 'redirect' | 'error' | 'radar';
11
+ requireAction: 'none' | 'redirect' | 'redirect_to_payment' | 'error' | 'radar';
11
12
  requireActionData?: {
12
- type: 'redirect' | 'threeds_auth' | 'processor_auth' | 'error' | 'stripe_radar' | 'finix_radar' | 'radar';
13
+ type: 'redirect' | 'redirect_to_payment' | 'threeds_auth' | 'processor_auth' | 'error' | 'stripe_radar' | 'finix_radar' | 'radar' | 'kesspay_auth' | 'trustflow_auth' | 'mastercard_auth';
13
14
  url?: string;
14
15
  processed: boolean;
15
16
  processorId?: string;
16
17
  metadata?: {
17
- type: 'redirect' | 'stripe_radar' | 'finix_radar';
18
+ type: 'redirect' | 'redirect_to_payment' | 'stripe_radar' | 'finix_radar';
18
19
  redirect?: {
19
20
  redirectUrl: string;
20
21
  returnUrl: string;
@@ -42,12 +43,15 @@ export interface Payment {
42
43
  order?: {
43
44
  id: string;
44
45
  checkoutSessionId: string;
46
+ amount?: number;
47
+ currency?: string;
48
+ [key: string]: unknown;
45
49
  };
46
50
  }
47
51
  export interface PaymentResponse {
48
52
  paymentId: string;
49
53
  payment: Payment;
50
- order?: any;
54
+ order?: Order | null;
51
55
  }
52
56
  export interface PaymentInstrumentResponse {
53
57
  id: string;
@@ -94,6 +98,16 @@ export interface PaymentOptions {
94
98
  * If neither is set, the store's selectedPaymentFlowId will be used
95
99
  */
96
100
  paymentFlowId?: string;
101
+ /**
102
+ * For alternative payment methods (APM)
103
+ * Processor ID to use for the payment
104
+ */
105
+ processorId?: string;
106
+ /**
107
+ * For alternative payment methods (APM)
108
+ * Payment method type (e.g., 'klarna', 'afterpay', 'paypal')
109
+ */
110
+ paymentMethod?: string;
97
111
  /** @deprecated Use onPaymentSuccess instead - this will be removed in v3 */
98
112
  onSuccess?: (response: PaymentResponse) => void;
99
113
  /** @deprecated Use onPaymentFailed instead - this will be removed in v3 */
@@ -138,28 +152,83 @@ export interface ApplePayToken {
138
152
  brand: string;
139
153
  };
140
154
  }
155
+ /** Token response from BasisTheory SDK */
156
+ export interface BasisTheoryTokenResponse {
157
+ id: string;
158
+ type: string;
159
+ enrichments?: {
160
+ cardDetails?: {
161
+ bin?: string;
162
+ last4?: string;
163
+ };
164
+ };
165
+ }
166
+ /** External BasisTheory SDK instance shape (from @basis-theory/basis-theory-react) */
167
+ export interface BasisTheoryInstance {
168
+ tokens: {
169
+ create(data: Record<string, unknown>): Promise<BasisTheoryTokenResponse>;
170
+ };
171
+ }
172
+ export interface GooglePayToken {
173
+ id: string;
174
+ type: string;
175
+ card: {
176
+ bin: string;
177
+ last4: string;
178
+ expiration_month: number;
179
+ expiration_year: number;
180
+ brand: string;
181
+ };
182
+ details?: {
183
+ auth_method?: string;
184
+ [key: string]: unknown;
185
+ };
186
+ }
187
+ export interface PaymentInstrumentInput {
188
+ type: string;
189
+ token?: string;
190
+ card?: {
191
+ maskedCardNumber?: string;
192
+ expirationMonth?: number;
193
+ expirationYear?: number;
194
+ bin?: string;
195
+ last4?: string;
196
+ brand?: string;
197
+ };
198
+ dpanType?: string;
199
+ authMethod?: string;
200
+ provider?: string;
201
+ paymentMethod?: string;
202
+ processorId?: string;
203
+ [key: string]: unknown;
204
+ }
141
205
  export declare class PaymentsResource {
142
206
  private apiClient;
143
207
  constructor(apiClient: ApiClient);
144
208
  /**
145
209
  * Create payment instrument
146
210
  */
147
- createPaymentInstrument(paymentInstrumentData: any): Promise<PaymentInstrumentResponse>;
211
+ createPaymentInstrument(paymentInstrumentData: PaymentInstrumentInput): Promise<PaymentInstrumentResponse>;
148
212
  /**
149
213
  * Create card payment instrument
150
214
  */
151
- createCardPaymentInstrument(basisTheory: any, // BasisTheory instance from @basis-theory/basis-theory-react
152
- cardData: CardPaymentMethod): Promise<PaymentInstrumentResponse>;
215
+ createCardPaymentInstrument(basisTheory: BasisTheoryInstance | undefined, cardData: CardPaymentMethod): Promise<PaymentInstrumentResponse>;
153
216
  /**
154
217
  * Create Apple Pay payment instrument
155
218
  */
156
- createApplePayPaymentInstrument(basisTheory: any, // BasisTheory instance from @basis-theory/basis-theory-react
157
- applePayToken: ApplePayToken): Promise<PaymentInstrumentResponse>;
219
+ createApplePayPaymentInstrument(basisTheory: BasisTheoryInstance | undefined, applePayToken: ApplePayToken): Promise<PaymentInstrumentResponse>;
158
220
  /**
159
221
  * Create Google Pay payment instrument
160
222
  */
161
- createGooglePayPaymentInstrument(basisTheory: any, // BasisTheory instance from @basis-theory/basis-theory-react
162
- googlePayToken: any): Promise<PaymentInstrumentResponse>;
223
+ createGooglePayPaymentInstrument(basisTheory: BasisTheoryInstance | undefined, googlePayToken: GooglePayToken): Promise<PaymentInstrumentResponse>;
224
+ /**
225
+ * Create APM payment instrument (Klarna, Afterpay, PayPal, etc.)
226
+ */
227
+ createApmPaymentInstrument(apmData: {
228
+ provider: string;
229
+ paymentMethod: string;
230
+ processorId: string;
231
+ }): Promise<PaymentInstrumentResponse>;
163
232
  /**
164
233
  * Helper function to format expiry date
165
234
  */
@@ -171,6 +240,8 @@ export declare class PaymentsResource {
171
240
  initiatedBy?: 'customer' | 'merchant';
172
241
  source?: 'upsell' | 'checkout' | 'offer' | 'missing_club' | 'forced';
173
242
  paymentFlowId?: string;
243
+ processorId?: string;
244
+ paymentMethod?: string;
174
245
  }): Promise<PaymentResponse>;
175
246
  /**
176
247
  * Get card payment instruments for customer
@@ -200,7 +271,7 @@ export declare class PaymentsResource {
200
271
  transactionId?: string;
201
272
  message?: string;
202
273
  success?: boolean;
203
- error?: any;
274
+ error?: string;
204
275
  }>;
205
276
  saveRadarSession(data: {
206
277
  orderId?: string;
@@ -226,5 +297,5 @@ export declare class PaymentsResource {
226
297
  paymentId: string;
227
298
  status: 'succeeded' | 'failed' | 'pending';
228
299
  paymentIntentId: string;
229
- }): Promise<any>;
300
+ }): Promise<Payment>;
230
301
  }
@@ -17,8 +17,7 @@ export class PaymentsResource {
17
17
  /**
18
18
  * Create card payment instrument
19
19
  */
20
- async createCardPaymentInstrument(basisTheory, // BasisTheory instance from @basis-theory/basis-theory-react
21
- cardData) {
20
+ async createCardPaymentInstrument(basisTheory, cardData) {
22
21
  if (!basisTheory) {
23
22
  throw new Error('Payment processor not initialized');
24
23
  }
@@ -55,8 +54,7 @@ export class PaymentsResource {
55
54
  /**
56
55
  * Create Apple Pay payment instrument
57
56
  */
58
- async createApplePayPaymentInstrument(basisTheory, // BasisTheory instance from @basis-theory/basis-theory-react
59
- applePayToken) {
57
+ async createApplePayPaymentInstrument(basisTheory, applePayToken) {
60
58
  if (!basisTheory) {
61
59
  throw new Error('Payment processor not initialized');
62
60
  }
@@ -81,9 +79,7 @@ export class PaymentsResource {
81
79
  /**
82
80
  * Create Google Pay payment instrument
83
81
  */
84
- async createGooglePayPaymentInstrument(basisTheory, // BasisTheory instance from @basis-theory/basis-theory-react
85
- googlePayToken // Token from Basis Theory Google Pay tokenization
86
- ) {
82
+ async createGooglePayPaymentInstrument(basisTheory, googlePayToken) {
87
83
  if (!basisTheory) {
88
84
  throw new Error('Payment processor not initialized');
89
85
  }
@@ -106,6 +102,21 @@ export class PaymentsResource {
106
102
  const response = await this.apiClient.post('/api/v1/payment/create-payment-instrument', { paymentInstrumentData });
107
103
  return response;
108
104
  }
105
+ /**
106
+ * Create APM payment instrument (Klarna, Afterpay, PayPal, etc.)
107
+ */
108
+ async createApmPaymentInstrument(apmData) {
109
+ console.log('Creating APM payment instrument:', apmData);
110
+ const paymentInstrumentData = {
111
+ type: 'apm',
112
+ provider: apmData.provider,
113
+ paymentMethod: apmData.paymentMethod,
114
+ processorId: apmData.processorId,
115
+ };
116
+ const response = await this.apiClient.post('/api/v1/payment/create-payment-instrument', { paymentInstrumentData });
117
+ console.log('APM payment instrument created:', response);
118
+ return response;
119
+ }
109
120
  /**
110
121
  * Helper function to format expiry date
111
122
  */
@@ -124,15 +135,21 @@ export class PaymentsResource {
124
135
  */
125
136
  async processPaymentDirect(checkoutSessionId, paymentInstrumentId, threedsSessionId, options = {}) {
126
137
  console.log('[PaymentsResource] processPaymentDirect START', options.paymentFlowId ? `(flow: ${options.paymentFlowId})` : '');
138
+ console.log('[PaymentsResource] Full options object:', JSON.stringify(options, null, 2));
139
+ console.log('[PaymentsResource] processorId:', options.processorId, 'paymentMethod:', options.paymentMethod);
127
140
  try {
128
- const response = await this.apiClient.post('/api/public/v1/checkout/pay-v2', {
141
+ const requestBody = {
129
142
  checkoutSessionId,
130
143
  paymentInstrumentId,
131
144
  ...(threedsSessionId && { threedsSessionId }),
132
145
  ...(options.initiatedBy && { initiatedBy: options.initiatedBy }),
133
146
  ...(options.source && { source: options.source }),
134
147
  ...(options.paymentFlowId && { paymentFlowId: options.paymentFlowId }),
135
- });
148
+ ...(options.processorId && { processorId: options.processorId }),
149
+ ...(options.paymentMethod && { paymentMethod: options.paymentMethod }),
150
+ };
151
+ console.log('[PaymentsResource] Request body being sent:', JSON.stringify(requestBody, null, 2));
152
+ const response = await this.apiClient.post('/api/public/v1/checkout/pay-v2', requestBody);
136
153
  console.log('[PaymentsResource] processPaymentDirect SUCCESS:', response);
137
154
  return response;
138
155
  }
@@ -1,6 +1,9 @@
1
1
  /**
2
2
  * Types for the Tagada Pay SDK Core
3
3
  */
4
+ export type DeepPartial<T> = {
5
+ [P in keyof T]?: T[P] extends object ? DeepPartial<T[P]> : T[P];
6
+ };
4
7
  export type Environment = 'production' | 'development' | 'local';
5
8
  export interface ApiConfig {
6
9
  baseUrl: string;
@@ -86,6 +89,40 @@ export interface PickupPoint {
86
89
  opening_hours?: string;
87
90
  extra_info?: string;
88
91
  }
92
+ export interface Subscription {
93
+ id: string;
94
+ status: string;
95
+ planName?: string;
96
+ interval?: string;
97
+ intervalCount?: number;
98
+ currentPeriodEnd?: string;
99
+ currentPeriodStart?: string;
100
+ cancelAtPeriodEnd?: boolean;
101
+ trialEnd?: string | null;
102
+ [key: string]: unknown;
103
+ }
104
+ export interface DeviceGeoData {
105
+ city?: string;
106
+ regionName?: string;
107
+ country?: string;
108
+ [key: string]: unknown;
109
+ }
110
+ export interface DeviceInfo {
111
+ userAgent?: string;
112
+ ip?: string;
113
+ country?: string;
114
+ browser?: string;
115
+ browserVersion?: string;
116
+ os?: string;
117
+ osVersion?: string;
118
+ geoData?: DeviceGeoData;
119
+ [key: string]: unknown;
120
+ }
121
+ export interface PromotionCode {
122
+ id: string;
123
+ code: string;
124
+ [key: string]: unknown;
125
+ }
89
126
  export interface OrderItem {
90
127
  id: string;
91
128
  productId: string;
@@ -141,15 +178,16 @@ export interface Order {
141
178
  paidAmount: number;
142
179
  status: string;
143
180
  createdAt: string;
144
- metadata?: Record<string, any>;
181
+ metadata?: Record<string, unknown>;
145
182
  items: OrderItem[];
146
183
  summaries?: OrderSummary[];
147
184
  shippingAddress?: OrderAddress;
148
185
  billingAddress?: OrderAddress;
149
- pickupAddress?: PickupPoint;
186
+ pickupAddress?: PickupPoint | null;
187
+ customer?: Customer;
150
188
  checkoutSession?: {
151
189
  returnUrl?: string;
152
- [key: string]: any;
190
+ [key: string]: unknown;
153
191
  };
154
192
  relatedOrders?: Order[];
155
193
  }
@@ -161,7 +199,7 @@ export interface PaymentSummary {
161
199
  createdAt: string;
162
200
  updatedAt?: string;
163
201
  provider?: string;
164
- metadata?: Record<string, any>;
202
+ metadata?: Record<string, unknown>;
165
203
  }
166
204
  export interface PromotionSummary {
167
205
  id: string;
@@ -188,10 +226,10 @@ export interface OrderWithRelations extends Order {
188
226
  checkoutSession?: {
189
227
  id?: string;
190
228
  returnUrl?: string;
191
- [key: string]: any;
229
+ [key: string]: unknown;
192
230
  };
193
231
  promotions?: PromotionSummary[];
194
- subscriptions?: any[];
232
+ subscriptions?: Subscription[];
195
233
  adjustments: OrderAdjustmentSummary[];
196
234
  }
197
235
  export interface CustomerAddress {
@@ -225,7 +263,7 @@ export interface CustomerOrderSummary {
225
263
  externalOrderId: string | null;
226
264
  billingAddress: CustomerAddress;
227
265
  shippingAddress: Omit<CustomerAddress, 'email'>;
228
- pickupAddress: any | null;
266
+ pickupAddress: PickupPoint | null;
229
267
  taxesIncluded: boolean;
230
268
  draft: boolean;
231
269
  checkoutSessionId: string | null;
@@ -235,7 +273,7 @@ export interface CustomerOrderSummary {
235
273
  paymentInstrumentId: string | null;
236
274
  refundedAt: string | null;
237
275
  refundedAmount: number | null;
238
- metadata?: Record<string, any>;
276
+ metadata?: Record<string, unknown>;
239
277
  }
240
278
  export interface CustomerInfos {
241
279
  customer: {
@@ -255,12 +293,12 @@ export interface CustomerInfos {
255
293
  acceptsMarketing: boolean;
256
294
  createdAt: string;
257
295
  updatedAt: string;
258
- metadata: Record<string, any>;
259
- device: any | null;
296
+ metadata: Record<string, unknown>;
297
+ device: DeviceInfo | null;
260
298
  orders: CustomerOrderSummary[];
261
- subscriptions: any[];
299
+ subscriptions: Subscription[];
262
300
  };
263
- promotionCodes: any[];
301
+ promotionCodes: PromotionCode[];
264
302
  }
265
303
  export interface SessionInitResponse {
266
304
  store: Store;
@@ -1,4 +1 @@
1
- /**
2
- * Types for the Tagada Pay SDK Core
3
- */
4
1
  export {};
@@ -2,8 +2,8 @@
2
2
  * Checkout Utility Functions
3
3
  * Pure functions for checkout data manipulation
4
4
  */
5
- import type { CheckoutData, CheckoutSession, CheckoutLineItem, CheckoutInitParams, Promotion } from '../resources/checkout';
6
- export type { CheckoutData, CheckoutSession, CheckoutLineItem, CheckoutInitParams, Promotion, };
5
+ import type { CheckoutData, CheckoutInitParams, CheckoutLineItem, CheckoutSession, Promotion } from '../resources/checkout';
6
+ export type { CheckoutData, CheckoutInitParams, CheckoutLineItem, CheckoutSession, Promotion };
7
7
  export declare class CheckoutUtils {
8
8
  /**
9
9
  * Get checkout session ID
@@ -13,13 +13,18 @@ export class CheckoutUtils {
13
13
  * Get checkout line items
14
14
  */
15
15
  static getLineItems(checkoutData) {
16
- return checkoutData.checkoutSession?.lineItems || [];
16
+ const lineItems = checkoutData.checkoutSession?.lineItems;
17
+ if (!Array.isArray(lineItems)) {
18
+ return [];
19
+ }
20
+ return lineItems;
17
21
  }
18
22
  /**
19
23
  * Get checkout total
20
24
  */
21
25
  static getTotal(checkoutData) {
22
- return checkoutData.checkoutSession?.totalPrice || 0;
26
+ const totalPrice = checkoutData.checkoutSession?.totalPrice;
27
+ return typeof totalPrice === 'number' ? totalPrice : 0;
23
28
  }
24
29
  /**
25
30
  * Check if customer is club member
@@ -8,6 +8,20 @@ export interface Currency {
8
8
  name: string;
9
9
  decimalPlaces: number;
10
10
  }
11
+ /**
12
+ * Format money amount from minor units (cents) to a formatted string
13
+ *
14
+ * @param amountMinorUnits - Amount in minor units (e.g., 12345 for $123.45)
15
+ * @param currencyCode - ISO 4217 currency code (e.g., "USD", "EUR")
16
+ * @param locale - Locale for formatting (default: "en-US")
17
+ * @returns Formatted money string (e.g., "$123.45")
18
+ *
19
+ * @example
20
+ * formatMoney(12345, 'USD') // "$123.45"
21
+ * formatMoney(10000, 'EUR', 'de-DE') // "100,00 €"
22
+ * formatMoney(1000, 'JPY') // "¥1,000"
23
+ */
24
+ export declare function formatMoney(amountMinorUnits: number, currencyCode?: string, locale?: string): string;
11
25
  export declare class CurrencyUtils {
12
26
  /**
13
27
  * Get currency from context or fallback to default
@@ -2,6 +2,46 @@
2
2
  * Currency Utility Functions
3
3
  * Pure functions for currency management
4
4
  */
5
+ /**
6
+ * Format money amount from minor units (cents) to a formatted string
7
+ *
8
+ * @param amountMinorUnits - Amount in minor units (e.g., 12345 for $123.45)
9
+ * @param currencyCode - ISO 4217 currency code (e.g., "USD", "EUR")
10
+ * @param locale - Locale for formatting (default: "en-US")
11
+ * @returns Formatted money string (e.g., "$123.45")
12
+ *
13
+ * @example
14
+ * formatMoney(12345, 'USD') // "$123.45"
15
+ * formatMoney(10000, 'EUR', 'de-DE') // "100,00 €"
16
+ * formatMoney(1000, 'JPY') // "¥1,000"
17
+ */
18
+ export function formatMoney(amountMinorUnits, currencyCode = 'USD', locale = 'en-US') {
19
+ const decimalPlaces = CurrencyUtils.getDecimalPlaces(currencyCode);
20
+ // Convert minor units to major units
21
+ // Backend stores amounts with 2 decimal places for all currencies
22
+ // For currencies with 0 decimal places (JPY, KRW, etc.), divide by 100
23
+ let value;
24
+ if (decimalPlaces === 0) {
25
+ // For zero-decimal currencies, backend still stores with 2 decimals
26
+ value = amountMinorUnits / 100;
27
+ }
28
+ else {
29
+ value = amountMinorUnits / Math.pow(10, decimalPlaces);
30
+ }
31
+ try {
32
+ return new Intl.NumberFormat(locale, {
33
+ style: 'currency',
34
+ currency: currencyCode,
35
+ minimumFractionDigits: decimalPlaces,
36
+ maximumFractionDigits: decimalPlaces,
37
+ }).format(value);
38
+ }
39
+ catch {
40
+ // Fallback if Intl.NumberFormat fails
41
+ const symbol = CurrencyUtils.getCurrencySymbol(currencyCode);
42
+ return `${symbol}${value.toFixed(decimalPlaces)}`;
43
+ }
44
+ }
5
45
  export class CurrencyUtils {
6
46
  /**
7
47
  * Get currency from context or fallback to default
@@ -12,3 +12,4 @@ export * from './postPurchases';
12
12
  export * from './orderBump';
13
13
  export * from './sessionStorage';
14
14
  export * from './funnelQueryKeys';
15
+ export * from './configHotReload';
@@ -12,3 +12,5 @@ export * from './postPurchases';
12
12
  export * from './orderBump';
13
13
  export * from './sessionStorage';
14
14
  export * from './funnelQueryKeys';
15
+ // Config hot reload for live preview editing
16
+ export * from './configHotReload';
@@ -2,6 +2,7 @@
2
2
  * Order Utility Functions
3
3
  * Pure functions for order data manipulation
4
4
  */
5
+ import type { OrderSummary, PromotionSummary, PaymentSummary, Subscription, OrderAddress } from '../types';
5
6
  export interface OrderLineItem {
6
7
  id: string;
7
8
  orderId: string;
@@ -95,7 +96,7 @@ export interface Order {
95
96
  paymentInstrumentId: string;
96
97
  refundedAt?: string | null;
97
98
  refundedAmount?: number | null;
98
- metadata?: any;
99
+ metadata?: Record<string, unknown>;
99
100
  customer?: {
100
101
  id: string;
101
102
  email: string;
@@ -105,27 +106,28 @@ export interface Order {
105
106
  lastOrderId: string;
106
107
  accountId: string;
107
108
  storeId: string;
108
- billingAddress?: any;
109
- shippingAddress?: any;
109
+ billingAddress?: OrderAddress | null;
110
+ shippingAddress?: OrderAddress | null;
110
111
  currency: string;
111
112
  locale: string;
112
113
  draft: boolean;
113
114
  acceptsMarketing: boolean;
114
115
  createdAt: string;
115
116
  updatedAt: string;
116
- metadata?: any;
117
+ metadata?: Record<string, unknown>;
117
118
  device?: Record<string, unknown> | null;
118
119
  };
119
120
  items: OrderLineItem[];
120
- summaries?: any[];
121
- promotions?: any[];
121
+ summaries?: OrderSummary[];
122
+ promotions?: PromotionSummary[];
122
123
  checkoutSession?: {
123
124
  id: string;
124
125
  selectedPresentmentCurrency?: string;
125
- [key: string]: any;
126
+ returnUrl?: string;
127
+ [key: string]: unknown;
126
128
  };
127
- payments?: any[];
128
- subscriptions?: any[];
129
+ payments?: PaymentSummary[];
130
+ subscriptions?: Subscription[];
129
131
  store?: {
130
132
  name: string;
131
133
  chargeCurrencies: string[];
@@ -22,6 +22,14 @@ export type RawPluginConfig<TConfig = Record<string, any>> = {
22
22
  basePath?: string;
23
23
  config?: any;
24
24
  } & TConfig;
25
+ /**
26
+ * Synchronously get plugin config from meta tags
27
+ * This is a lightweight sync alternative to loadPluginConfig
28
+ * Use this when you need immediate config access (e.g., in CDN bundles)
29
+ *
30
+ * @returns Plugin config from meta tags or defaults
31
+ */
32
+ export declare function getPluginConfig(): PluginConfig;
25
33
  /**
26
34
  * Core plugin config loading function
27
35
  *
@@ -154,9 +154,37 @@ const loadStaticResources = async () => {
154
154
  * Helper to get content from meta tag
155
155
  */
156
156
  const getMetaContent = (name) => {
157
+ if (typeof document === 'undefined')
158
+ return undefined;
157
159
  const metaTag = document.querySelector(`meta[name="${name}"]`);
158
160
  return metaTag?.getAttribute('content') || undefined;
159
161
  };
162
+ /**
163
+ * Synchronously get plugin config from meta tags
164
+ * This is a lightweight sync alternative to loadPluginConfig
165
+ * Use this when you need immediate config access (e.g., in CDN bundles)
166
+ *
167
+ * @returns Plugin config from meta tags or defaults
168
+ */
169
+ export function getPluginConfig() {
170
+ if (typeof document === 'undefined') {
171
+ return { basePath: '/', config: {} };
172
+ }
173
+ const storeId = getMetaContent('x-plugin-store-id');
174
+ const accountId = getMetaContent('x-plugin-account-id');
175
+ const basePath = getMetaContent('x-plugin-base-path') || '/';
176
+ let config = {};
177
+ try {
178
+ const encodedConfig = getMetaContent('x-plugin-config');
179
+ if (encodedConfig) {
180
+ config = JSON.parse(decodeURIComponent(encodedConfig));
181
+ }
182
+ }
183
+ catch (error) {
184
+ console.warn('[TagadaSDK] Failed to parse plugin config from meta tag:', error);
185
+ }
186
+ return { storeId, accountId, basePath, config };
187
+ }
160
188
  /**
161
189
  * Load production config from meta tags (HIGHEST PRIORITY)
162
190
  * Meta tags are injected by the plugin middleware during HTML serving
@@ -28,7 +28,7 @@ export type { ToggleOrderBumpResponse, VipOffer, VipPreviewResponse } from './co
28
28
  export type { StoreConfig } from './core/resources/storeConfig';
29
29
  export { FunnelActionType } from './core/resources/funnel';
30
30
  export type { BackNavigationActionData, CartUpdatedActionData, DirectNavigationActionData, FormSubmitActionData, FunnelContextUpdateRequest, FunnelContextUpdateResponse, FunnelAction as FunnelEvent, FunnelInitializeRequest, FunnelInitializeResponse, FunnelNavigateRequest, FunnelNavigateResponse, FunnelNavigationAction, FunnelNavigationResult, NextAction, OfferAcceptedActionData, OfferDeclinedActionData, PaymentFailedActionData, PaymentSuccessActionData, SimpleFunnelContext } from './core/resources/funnel';
31
- export { ApplePayButton, ExpressPaymentMethodsProvider, formatMoney, getAvailableLanguages, GooglePayButton, PreviewModeIndicator, queryKeys, TagadaProvider, useApiMutation, useApiQuery, useApplePayCheckout, useAuth, useCheckout, useCheckoutToken, useClubOffers, useCountryOptions, useCredits, useCurrency, useCustomer, useCustomerInfos, useCustomerOrders, useCustomerSubscriptions, useDiscounts, useExpressPaymentMethods, useFunnel, useFunnelLegacy, useGeoLocation, useGoogleAutocomplete, useGooglePayCheckout, useInvalidateQuery, useISOData, useLanguageImport, useLogin, useOffer, useOrder, useOrderBump, usePayment, usePaymentRetrieve, usePixelTracking, usePluginConfig, usePostPurchases, usePreloadQuery, usePreviewOffer, useProducts, usePromotions, useRegionOptions, useRemappableParams, useShippingRates, useSimpleFunnel, useStepConfig, useStoreConfig, useTagadaContext, useThreeds, useThreedsModal, useTranslation, useVipOffers } from './react';
31
+ export { ApplePayButton, ExpressPaymentMethodsProvider, formatMoney, getAvailableLanguages, GooglePayButton, PreviewModeIndicator, queryKeys, TagadaProvider, useApiMutation, useApiQuery, useApplePayCheckout, useAuth, useCheckout, useCheckoutToken, useClubOffers, useCountryOptions, useCredits, useCurrency, useCustomer, useCustomerInfos, useCustomerOrders, useCustomerSubscriptions, useDiscounts, useExpressPaymentMethods, useFunnel, useFunnelLegacy, useGeoLocation, useGoogleAutocomplete, useGooglePayCheckout, useInvalidateQuery, useISOData, useLanguageImport, useLogin, useOffer, useOrder, useOrderBump, usePayment, usePaymentRetrieve, usePixelTracking, usePluginConfig, usePostPurchases, usePreloadQuery, usePreviewOffer, useProducts, usePromotions, useRegionOptions, useRemappableParams, useShippingRates, useSimpleFunnel, useStepConfig, useStoreConfig, useTagadaContext, useThreeds, useThreedsModal, useTranslation, useVipOffers, WhopCheckout, useWhopPaymentPolling } from './react';
32
32
  export type { DebugScript } from './react';
33
33
  export type { TranslateFunction, TranslationText, UseTranslationOptions, UseTranslationResult } from './react/hooks/useTranslation';
34
34
  export type { FunnelContextValue } from './react/hooks/useFunnel';
@@ -37,6 +37,8 @@ export type { ClubOffer, ClubOfferItem, ClubOfferLineItem, ClubOfferSummary, Use
37
37
  export type { UseCreditsOptions, UseCreditsResult } from './react/hooks/useCredits';
38
38
  export type { UseGooglePayCheckoutOptions } from './react/hooks/useGooglePayCheckout';
39
39
  export type { UseLoginOptions, UseLoginResult } from './react/hooks/useLogin';
40
+ export type { WhopCheckoutHandle, WhopCheckoutProps } from './react/components/WhopCheckout';
41
+ export type { WhopPayment, UseWhopPaymentPollingOptions, UseWhopPaymentPollingReturn } from './react/hooks/useWhopPaymentPolling';
40
42
  export type { CustomerAddress, CustomerInfos, CustomerOrderSummary, OrderWithRelations, Subscription, SubscriptionsResponse } from './core/resources/customer';
41
43
  export type { UseCustomerResult } from './react/hooks/useCustomer';
42
44
  export type { UseCustomerInfosOptions, UseCustomerInfosResult } from './react/hooks/useCustomerInfos';
package/dist/v2/index.js CHANGED
@@ -22,4 +22,4 @@ loadLocalFunnelConfig } from './core/funnelClient';
22
22
  export * from './core/pathRemapping';
23
23
  export { FunnelActionType } from './core/resources/funnel';
24
24
  // React exports (hooks and components only, types are exported above)
25
- export { ApplePayButton, ExpressPaymentMethodsProvider, formatMoney, getAvailableLanguages, GooglePayButton, PreviewModeIndicator, queryKeys, TagadaProvider, useApiMutation, useApiQuery, useApplePayCheckout, useAuth, useCheckout, useCheckoutToken, useClubOffers, useCountryOptions, useCredits, useCurrency, useCustomer, useCustomerInfos, useCustomerOrders, useCustomerSubscriptions, useDiscounts, useExpressPaymentMethods, useFunnel, useFunnelLegacy, useGeoLocation, useGoogleAutocomplete, useGooglePayCheckout, useInvalidateQuery, useISOData, useLanguageImport, useLogin, useOffer, useOrder, useOrderBump, usePayment, usePaymentRetrieve, usePixelTracking, usePluginConfig, usePostPurchases, usePreloadQuery, usePreviewOffer, useProducts, usePromotions, useRegionOptions, useRemappableParams, useShippingRates, useSimpleFunnel, useStepConfig, useStoreConfig, useTagadaContext, useThreeds, useThreedsModal, useTranslation, useVipOffers } from './react';
25
+ export { ApplePayButton, ExpressPaymentMethodsProvider, formatMoney, getAvailableLanguages, GooglePayButton, PreviewModeIndicator, queryKeys, TagadaProvider, useApiMutation, useApiQuery, useApplePayCheckout, useAuth, useCheckout, useCheckoutToken, useClubOffers, useCountryOptions, useCredits, useCurrency, useCustomer, useCustomerInfos, useCustomerOrders, useCustomerSubscriptions, useDiscounts, useExpressPaymentMethods, useFunnel, useFunnelLegacy, useGeoLocation, useGoogleAutocomplete, useGooglePayCheckout, useInvalidateQuery, useISOData, useLanguageImport, useLogin, useOffer, useOrder, useOrderBump, usePayment, usePaymentRetrieve, usePixelTracking, usePluginConfig, usePostPurchases, usePreloadQuery, usePreviewOffer, useProducts, usePromotions, useRegionOptions, useRemappableParams, useShippingRates, useSimpleFunnel, useStepConfig, useStoreConfig, useTagadaContext, useThreeds, useThreedsModal, useTranslation, useVipOffers, WhopCheckout, useWhopPaymentPolling } from './react';
@@ -143,6 +143,27 @@ export function FunnelScriptInjector({ context, isInitialized }) {
143
143
  observer.disconnect();
144
144
  }, timeout);
145
145
  },
146
+ waitForElements: (selector, callback, timeout = 10000) => {
147
+ const elements = document.querySelectorAll(selector);
148
+ if (elements.length > 0) {
149
+ callback(elements);
150
+ return;
151
+ }
152
+ const observer = new MutationObserver(() => {
153
+ const elements = document.querySelectorAll(selector);
154
+ if (elements.length > 0) {
155
+ observer.disconnect();
156
+ callback(elements);
157
+ }
158
+ });
159
+ observer.observe(document.body, {
160
+ childList: true,
161
+ subtree: true,
162
+ });
163
+ setTimeout(() => {
164
+ observer.disconnect();
165
+ }, timeout);
166
+ },
146
167
  pageType: context?.currentStepId || null,
147
168
  isInitialized: isInitialized,
148
169
  ressources: context?.resources || null,