@tagadapay/plugin-sdk 1.0.11 โ 1.0.13
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.
- package/dist/data/countries.d.ts +50 -0
- package/dist/data/countries.js +38181 -0
- package/dist/react/components/AddressForm.example.d.ts +1 -0
- package/dist/react/components/AddressForm.example.js +32 -0
- package/dist/react/hooks/useAddress.d.ts +58 -0
- package/dist/react/hooks/useAddress.js +537 -0
- package/dist/react/hooks/useCheckout.js +11 -2
- package/dist/react/hooks/useOrderBump.js +11 -2
- package/dist/react/hooks/usePayment.d.ts +2 -0
- package/dist/react/hooks/usePayment.js +7 -4
- package/dist/react/index.d.ts +2 -0
- package/dist/react/index.js +1 -0
- package/dist/react/providers/TagadaProvider.d.ts +8 -0
- package/dist/react/providers/TagadaProvider.js +46 -0
- package/package.json +2 -1
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { useState, useCallback, useEffect } from 'react';
|
|
2
2
|
import { useTagadaContext } from '../providers/TagadaProvider';
|
|
3
3
|
export function useOrderBump(options) {
|
|
4
|
-
const { apiService } = useTagadaContext();
|
|
4
|
+
const { apiService, refreshCoordinator } = useTagadaContext();
|
|
5
5
|
const { checkoutSessionId, offerId, orderBumpType = 'vip', autoPreview = true } = options;
|
|
6
6
|
const [isSelected, setIsSelected] = useState(false);
|
|
7
7
|
const [preview, setPreview] = useState(null);
|
|
@@ -55,6 +55,8 @@ export function useOrderBump(options) {
|
|
|
55
55
|
if (response.success) {
|
|
56
56
|
// Refresh preview to get updated savings
|
|
57
57
|
await refreshPreview();
|
|
58
|
+
// Notify checkout hook that order bump data changed
|
|
59
|
+
await refreshCoordinator.notifyOrderBumpChanged();
|
|
58
60
|
return { success: true };
|
|
59
61
|
}
|
|
60
62
|
else {
|
|
@@ -73,7 +75,7 @@ export function useOrderBump(options) {
|
|
|
73
75
|
finally {
|
|
74
76
|
setIsToggling(false);
|
|
75
77
|
}
|
|
76
|
-
}, [checkoutSessionId, offerId, isSelected, apiService, refreshPreview]);
|
|
78
|
+
}, [checkoutSessionId, offerId, isSelected, apiService, refreshPreview, refreshCoordinator]);
|
|
77
79
|
// Auto-fetch preview on mount and when dependencies change
|
|
78
80
|
useEffect(() => {
|
|
79
81
|
if (autoPreview && checkoutSessionId) {
|
|
@@ -82,6 +84,13 @@ export function useOrderBump(options) {
|
|
|
82
84
|
});
|
|
83
85
|
}
|
|
84
86
|
}, [autoPreview, refreshPreview]);
|
|
87
|
+
// Register refresh function with coordinator and cleanup on unmount
|
|
88
|
+
useEffect(() => {
|
|
89
|
+
refreshCoordinator.registerOrderBumpRefresh(refreshPreview);
|
|
90
|
+
return () => {
|
|
91
|
+
refreshCoordinator.unregisterOrderBumpRefresh();
|
|
92
|
+
};
|
|
93
|
+
}, [refreshPreview, refreshCoordinator]);
|
|
85
94
|
// Calculate current savings
|
|
86
95
|
const savings = isSelected && preview?.savings ? preview.savings : preview?.savings || null;
|
|
87
96
|
return {
|
|
@@ -31,6 +31,8 @@ export interface PaymentResponse {
|
|
|
31
31
|
export interface PaymentOptions {
|
|
32
32
|
enableThreeds?: boolean;
|
|
33
33
|
threedsProvider?: ThreedsProvider;
|
|
34
|
+
initiatedBy?: 'customer' | 'merchant';
|
|
35
|
+
source?: 'upsell' | 'checkout' | 'offer' | 'missing_club' | 'forced';
|
|
34
36
|
onSuccess?: (payment: Payment) => void;
|
|
35
37
|
onFailure?: (error: string) => void;
|
|
36
38
|
onRequireAction?: (payment: Payment) => void;
|
|
@@ -204,15 +204,18 @@ export function usePayment() {
|
|
|
204
204
|
throw error;
|
|
205
205
|
}
|
|
206
206
|
}, [basisTheory, apiService]);
|
|
207
|
-
// Process payment directly with checkout session
|
|
207
|
+
// Process payment directly with checkout session (V2)
|
|
208
208
|
const processPaymentDirect = useCallback(async (checkoutSessionId, paymentInstrumentId, threedsSessionId, options = {}) => {
|
|
209
209
|
try {
|
|
210
|
-
// Create order and process payment in one call
|
|
211
|
-
const response = await apiService.fetch(`/api/v1/checkout
|
|
210
|
+
// Create order and process payment in one call using V2 endpoint
|
|
211
|
+
const response = await apiService.fetch(`/api/public/v1/checkout/pay-v2`, {
|
|
212
212
|
method: 'POST',
|
|
213
213
|
body: {
|
|
214
|
+
checkoutSessionId,
|
|
214
215
|
paymentInstrumentId,
|
|
215
|
-
threedsSessionId,
|
|
216
|
+
...(threedsSessionId && { threedsSessionId }),
|
|
217
|
+
...(options.initiatedBy && { initiatedBy: options.initiatedBy }),
|
|
218
|
+
...(options.source && { source: options.source }),
|
|
216
219
|
},
|
|
217
220
|
});
|
|
218
221
|
console.log('Payment response:', response);
|
package/dist/react/index.d.ts
CHANGED
|
@@ -12,6 +12,7 @@ export { useCustomer } from './hooks/useCustomer';
|
|
|
12
12
|
export { useEnvironment } from './hooks/useEnvironment';
|
|
13
13
|
export { useLocale } from './hooks/useLocale';
|
|
14
14
|
export { useAuth } from './hooks/useAuth';
|
|
15
|
+
export { useAddress } from './hooks/useAddress';
|
|
15
16
|
export { useOrder } from './hooks/useOrder';
|
|
16
17
|
export type { UseOrderOptions, UseOrderResult } from './hooks/useOrder';
|
|
17
18
|
export { usePayment } from './hooks/usePayment';
|
|
@@ -21,6 +22,7 @@ export { useThreedsModal } from './hooks/useThreedsModal';
|
|
|
21
22
|
export type { Customer, Session, AuthState, Locale, Currency, Store, Environment, EnvironmentConfig, Order, OrderItem, OrderSummary, OrderAddress, PickupPoint, } from './types';
|
|
22
23
|
export type { UseCheckoutOptions, UseCheckoutResult, CheckoutInitParams, CheckoutLineItem, CheckoutSession, CheckoutData, Promotion, } from './hooks/useCheckout';
|
|
23
24
|
export type { UseOrderBumpOptions, UseOrderBumpResult, OrderBumpPreview } from './hooks/useOrderBump';
|
|
25
|
+
export type { UseAddressOptions, UseAddressResult, AddressData, AddressField, Country, State, } from './hooks/useAddress';
|
|
24
26
|
export type { Payment, PollingOptions, PaymentPollingHook } from './hooks/usePaymentPolling';
|
|
25
27
|
export type { PaymentInstrument, ThreedsSession, ThreedsChallenge, ThreedsOptions, ThreedsHook, ThreedsProvider, } from './hooks/useThreeds';
|
|
26
28
|
export type { ApplePayToken, CardPaymentMethod, PaymentResponse, PaymentOptions, PaymentInstrumentResponse, PaymentHook, } from './hooks/usePayment';
|
package/dist/react/index.js
CHANGED
|
@@ -15,6 +15,7 @@ export { useCustomer } from './hooks/useCustomer';
|
|
|
15
15
|
export { useEnvironment } from './hooks/useEnvironment';
|
|
16
16
|
export { useLocale } from './hooks/useLocale';
|
|
17
17
|
export { useAuth } from './hooks/useAuth';
|
|
18
|
+
export { useAddress } from './hooks/useAddress';
|
|
18
19
|
// Order hook exports
|
|
19
20
|
export { useOrder } from './hooks/useOrder';
|
|
20
21
|
// Payment hooks exports
|
|
@@ -25,6 +25,14 @@ interface TagadaContextValue {
|
|
|
25
25
|
lastUpdated: Date | null;
|
|
26
26
|
};
|
|
27
27
|
updateCheckoutDebugData: (data: any, error?: Error | null, isLoading?: boolean) => void;
|
|
28
|
+
refreshCoordinator: {
|
|
29
|
+
registerCheckoutRefresh: (refreshFn: () => Promise<void>) => void;
|
|
30
|
+
registerOrderBumpRefresh: (refreshFn: () => Promise<void>) => void;
|
|
31
|
+
notifyCheckoutChanged: () => Promise<void>;
|
|
32
|
+
notifyOrderBumpChanged: () => Promise<void>;
|
|
33
|
+
unregisterCheckoutRefresh: () => void;
|
|
34
|
+
unregisterOrderBumpRefresh: () => void;
|
|
35
|
+
};
|
|
28
36
|
money: {
|
|
29
37
|
formatMoney: typeof formatMoney;
|
|
30
38
|
getCurrencyInfo: typeof getCurrencyInfo;
|
|
@@ -341,6 +341,51 @@ storeId, accountId, }) {
|
|
|
341
341
|
session,
|
|
342
342
|
});
|
|
343
343
|
}, [customer, session]);
|
|
344
|
+
// Refresh coordinator for bidirectional hook communication
|
|
345
|
+
const checkoutRefreshRef = useRef(null);
|
|
346
|
+
const orderBumpRefreshRef = useRef(null);
|
|
347
|
+
const refreshCoordinator = {
|
|
348
|
+
registerCheckoutRefresh: (refreshFn) => {
|
|
349
|
+
checkoutRefreshRef.current = refreshFn;
|
|
350
|
+
console.log('๐ [RefreshCoordinator] Checkout refresh function registered');
|
|
351
|
+
},
|
|
352
|
+
registerOrderBumpRefresh: (refreshFn) => {
|
|
353
|
+
orderBumpRefreshRef.current = refreshFn;
|
|
354
|
+
console.log('๐ [RefreshCoordinator] Order bump refresh function registered');
|
|
355
|
+
},
|
|
356
|
+
notifyCheckoutChanged: async () => {
|
|
357
|
+
if (orderBumpRefreshRef.current) {
|
|
358
|
+
console.log('๐ [RefreshCoordinator] Checkout changed, refreshing order bump data...');
|
|
359
|
+
try {
|
|
360
|
+
await orderBumpRefreshRef.current();
|
|
361
|
+
console.log('โ
[RefreshCoordinator] Order bump refresh completed');
|
|
362
|
+
}
|
|
363
|
+
catch (error) {
|
|
364
|
+
console.warn('โ ๏ธ [RefreshCoordinator] Order bump refresh failed:', error);
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
},
|
|
368
|
+
notifyOrderBumpChanged: async () => {
|
|
369
|
+
if (checkoutRefreshRef.current) {
|
|
370
|
+
console.log('๐ [RefreshCoordinator] Order bump changed, refreshing checkout data...');
|
|
371
|
+
try {
|
|
372
|
+
await checkoutRefreshRef.current();
|
|
373
|
+
console.log('โ
[RefreshCoordinator] Checkout refresh completed');
|
|
374
|
+
}
|
|
375
|
+
catch (error) {
|
|
376
|
+
console.warn('โ ๏ธ [RefreshCoordinator] Checkout refresh failed:', error);
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
},
|
|
380
|
+
unregisterCheckoutRefresh: () => {
|
|
381
|
+
checkoutRefreshRef.current = null;
|
|
382
|
+
console.log('๐งน [RefreshCoordinator] Checkout refresh function unregistered');
|
|
383
|
+
},
|
|
384
|
+
unregisterOrderBumpRefresh: () => {
|
|
385
|
+
orderBumpRefreshRef.current = null;
|
|
386
|
+
console.log('๐งน [RefreshCoordinator] Order bump refresh function unregistered');
|
|
387
|
+
},
|
|
388
|
+
};
|
|
344
389
|
const contextValue = {
|
|
345
390
|
auth,
|
|
346
391
|
session,
|
|
@@ -363,6 +408,7 @@ storeId, accountId, }) {
|
|
|
363
408
|
lastUpdated: new Date(),
|
|
364
409
|
});
|
|
365
410
|
},
|
|
411
|
+
refreshCoordinator,
|
|
366
412
|
money: {
|
|
367
413
|
formatMoney,
|
|
368
414
|
getCurrencyInfo,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tagadapay/plugin-sdk",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.13",
|
|
4
4
|
"description": "Modern React SDK for building Tagada Pay plugins",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -38,6 +38,7 @@
|
|
|
38
38
|
"@basis-theory/basis-theory-react": "^1.32.5",
|
|
39
39
|
"@basis-theory/web-threeds": "^1.0.1",
|
|
40
40
|
"axios": "^1.6.0",
|
|
41
|
+
"react-google-autocomplete": "^2.7.3",
|
|
41
42
|
"react-intl": "^7.1.11"
|
|
42
43
|
},
|
|
43
44
|
"devDependencies": {
|