@tagadapay/plugin-sdk 2.4.39 → 2.5.0
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/index.d.ts +1 -0
- package/dist/index.js +2 -0
- package/dist/react/hooks/useCheckout.js +19 -2
- package/dist/react/hooks/useCheckoutSession.d.ts +19 -0
- package/dist/react/hooks/useCheckoutSession.js +108 -0
- package/dist/react/hooks/useCheckoutToken.d.ts +17 -0
- package/dist/react/hooks/useCheckoutToken.js +80 -0
- package/dist/react/hooks/useOrderBump.js +92 -13
- package/dist/react/hooks/useOrderBumpV2.d.ts +17 -0
- package/dist/react/hooks/useOrderBumpV2.js +95 -0
- package/dist/react/hooks/useOrderBumpV3.d.ts +23 -0
- package/dist/react/hooks/useOrderBumpV3.js +109 -0
- package/dist/react/hooks/usePostPurchases.js +11 -5
- package/dist/react/index.d.ts +8 -0
- package/dist/react/index.js +4 -0
- package/dist/react/services/apiService.d.ts +1 -0
- package/dist/react/services/apiService.js +3 -0
- package/dist/v2/core/googleAutocomplete.d.ts +65 -0
- package/dist/v2/core/googleAutocomplete.js +94 -0
- package/dist/v2/core/index.d.ts +8 -0
- package/dist/v2/core/index.js +11 -0
- package/dist/v2/core/isoData.d.ts +50 -0
- package/dist/v2/core/isoData.js +103 -0
- package/dist/v2/core/resources/apiClient.d.ts +25 -0
- package/dist/v2/core/resources/apiClient.js +95 -0
- package/dist/v2/core/resources/checkout.d.ts +189 -0
- package/dist/v2/core/resources/checkout.js +119 -0
- package/dist/v2/core/resources/index.d.ts +13 -0
- package/dist/v2/core/resources/index.js +13 -0
- package/dist/v2/core/resources/offers.d.ts +98 -0
- package/dist/v2/core/resources/offers.js +115 -0
- package/dist/v2/core/resources/orders.d.ts +40 -0
- package/dist/v2/core/resources/orders.js +59 -0
- package/dist/v2/core/resources/payments.d.ts +140 -0
- package/dist/v2/core/resources/payments.js +126 -0
- package/dist/v2/core/resources/postPurchases.d.ts +182 -0
- package/dist/v2/core/resources/postPurchases.js +116 -0
- package/dist/v2/core/resources/products.d.ts +29 -0
- package/dist/v2/core/resources/products.js +49 -0
- package/dist/v2/core/resources/promotions.d.ts +45 -0
- package/dist/v2/core/resources/promotions.js +87 -0
- package/dist/v2/core/resources/threeds.d.ts +23 -0
- package/dist/v2/core/resources/threeds.js +15 -0
- package/dist/v2/core/utils/checkout.d.ts +24 -0
- package/dist/v2/core/utils/checkout.js +30 -0
- package/dist/v2/core/utils/currency.d.ts +28 -0
- package/dist/v2/core/utils/currency.js +272 -0
- package/dist/v2/core/utils/index.d.ts +12 -0
- package/dist/v2/core/utils/index.js +12 -0
- package/dist/v2/core/utils/order.d.ts +159 -0
- package/dist/v2/core/utils/order.js +42 -0
- package/dist/v2/core/utils/orderBump.d.ts +40 -0
- package/dist/v2/core/utils/orderBump.js +47 -0
- package/dist/v2/core/utils/pluginConfig.d.ts +43 -0
- package/dist/v2/core/utils/pluginConfig.js +155 -0
- package/dist/v2/core/utils/postPurchases.d.ts +32 -0
- package/dist/v2/core/utils/postPurchases.js +42 -0
- package/dist/v2/core/utils/products.d.ts +58 -0
- package/dist/v2/core/utils/products.js +64 -0
- package/dist/v2/core/utils/promotions.d.ts +24 -0
- package/dist/v2/core/utils/promotions.js +30 -0
- package/dist/v2/index.d.ts +19 -0
- package/dist/v2/index.js +15 -0
- package/dist/v2/react/components/DebugDrawer.d.ts +7 -0
- package/dist/v2/react/components/DebugDrawer.js +383 -0
- package/dist/v2/react/hooks/useApiQuery.d.ts +28 -0
- package/dist/v2/react/hooks/useApiQuery.js +84 -0
- package/dist/v2/react/hooks/useCheckoutQuery.d.ts +39 -0
- package/dist/v2/react/hooks/useCheckoutQuery.js +208 -0
- package/dist/v2/react/hooks/useCheckoutToken.d.ts +17 -0
- package/dist/v2/react/hooks/useCheckoutToken.js +80 -0
- package/dist/v2/react/hooks/useCurrency.d.ts +9 -0
- package/dist/v2/react/hooks/useCurrency.js +21 -0
- package/dist/v2/react/hooks/useGeoLocation.d.ts +138 -0
- package/dist/v2/react/hooks/useGeoLocation.js +126 -0
- package/dist/v2/react/hooks/useGoogleAutocomplete.d.ts +74 -0
- package/dist/v2/react/hooks/useGoogleAutocomplete.js +207 -0
- package/dist/v2/react/hooks/useISOData.d.ts +61 -0
- package/dist/v2/react/hooks/useISOData.js +176 -0
- package/dist/v2/react/hooks/useOffersQuery.d.ts +65 -0
- package/dist/v2/react/hooks/useOffersQuery.js +353 -0
- package/dist/v2/react/hooks/useOrderBumpQuery.d.ts +20 -0
- package/dist/v2/react/hooks/useOrderBumpQuery.js +88 -0
- package/dist/v2/react/hooks/useOrderQuery.d.ts +29 -0
- package/dist/v2/react/hooks/useOrderQuery.js +98 -0
- package/dist/v2/react/hooks/usePaymentPolling.d.ts +45 -0
- package/dist/v2/react/hooks/usePaymentPolling.js +153 -0
- package/dist/v2/react/hooks/usePaymentQuery.d.ts +19 -0
- package/dist/v2/react/hooks/usePaymentQuery.js +283 -0
- package/dist/v2/react/hooks/usePluginConfig.d.ts +16 -0
- package/dist/v2/react/hooks/usePluginConfig.js +36 -0
- package/dist/v2/react/hooks/usePostPurchasesQuery.d.ts +63 -0
- package/dist/v2/react/hooks/usePostPurchasesQuery.js +365 -0
- package/dist/v2/react/hooks/useProductsQuery.d.ts +31 -0
- package/dist/v2/react/hooks/useProductsQuery.js +102 -0
- package/dist/v2/react/hooks/usePromotionsQuery.d.ts +28 -0
- package/dist/v2/react/hooks/usePromotionsQuery.js +97 -0
- package/dist/v2/react/hooks/useThreeds.d.ts +36 -0
- package/dist/v2/react/hooks/useThreeds.js +166 -0
- package/dist/v2/react/hooks/useThreedsModal.d.ts +13 -0
- package/dist/v2/react/hooks/useThreedsModal.js +343 -0
- package/dist/v2/react/index.d.ts +38 -0
- package/dist/v2/react/index.js +27 -0
- package/dist/v2/react/providers/TagadaProvider.d.ts +63 -0
- package/dist/v2/react/providers/TagadaProvider.js +680 -0
- package/package.json +10 -3
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Order Utility Functions
|
|
3
|
+
* Pure functions for order data manipulation
|
|
4
|
+
*/
|
|
5
|
+
export class OrderUtils {
|
|
6
|
+
/**
|
|
7
|
+
* Get order line items
|
|
8
|
+
*/
|
|
9
|
+
static getOrderLineItems(order) {
|
|
10
|
+
return order.items || [];
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Get order total
|
|
14
|
+
*/
|
|
15
|
+
static getOrderTotal(order) {
|
|
16
|
+
return order.paidAmount || 0;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Get order status
|
|
20
|
+
*/
|
|
21
|
+
static getOrderStatus(order) {
|
|
22
|
+
return order.status || 'unknown';
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Check if order is completed
|
|
26
|
+
*/
|
|
27
|
+
static isOrderCompleted(order) {
|
|
28
|
+
return order.status === 'completed' || order.status === 'fulfilled';
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Check if order is pending
|
|
32
|
+
*/
|
|
33
|
+
static isOrderPending(order) {
|
|
34
|
+
return order.status === 'pending' || order.status === 'processing';
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Check if order is cancelled
|
|
38
|
+
*/
|
|
39
|
+
static isOrderCancelled(order) {
|
|
40
|
+
return order.status === 'cancelled' || order.status === 'refunded';
|
|
41
|
+
}
|
|
42
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Order Bump Utility Functions
|
|
3
|
+
* Pure functions for order bump data manipulation
|
|
4
|
+
*/
|
|
5
|
+
export interface OrderBumpOffer {
|
|
6
|
+
id: string;
|
|
7
|
+
name: string;
|
|
8
|
+
description: string;
|
|
9
|
+
price: number;
|
|
10
|
+
currency: string;
|
|
11
|
+
imageUrl?: string;
|
|
12
|
+
isSelected?: boolean;
|
|
13
|
+
}
|
|
14
|
+
export interface OrderBumpPreview {
|
|
15
|
+
offer: OrderBumpOffer;
|
|
16
|
+
totalAmount: number;
|
|
17
|
+
adjustedAmount: number;
|
|
18
|
+
}
|
|
19
|
+
export declare class OrderBumpUtils {
|
|
20
|
+
/**
|
|
21
|
+
* Check if order bump offer is valid
|
|
22
|
+
*/
|
|
23
|
+
static isValidOffer(offer: OrderBumpOffer): boolean;
|
|
24
|
+
/**
|
|
25
|
+
* Toggle order bump selection
|
|
26
|
+
*/
|
|
27
|
+
static toggleSelection(offer: OrderBumpOffer): OrderBumpOffer;
|
|
28
|
+
/**
|
|
29
|
+
* Calculate order bump preview
|
|
30
|
+
*/
|
|
31
|
+
static calculatePreview(offer: OrderBumpOffer, baseAmount?: number): OrderBumpPreview;
|
|
32
|
+
/**
|
|
33
|
+
* Get selected order bumps
|
|
34
|
+
*/
|
|
35
|
+
static getSelectedOffers(offers: OrderBumpOffer[]): OrderBumpOffer[];
|
|
36
|
+
/**
|
|
37
|
+
* Get total for selected order bumps
|
|
38
|
+
*/
|
|
39
|
+
static getSelectedTotal(offers: OrderBumpOffer[]): number;
|
|
40
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Order Bump Utility Functions
|
|
3
|
+
* Pure functions for order bump data manipulation
|
|
4
|
+
*/
|
|
5
|
+
export class OrderBumpUtils {
|
|
6
|
+
/**
|
|
7
|
+
* Check if order bump offer is valid
|
|
8
|
+
*/
|
|
9
|
+
static isValidOffer(offer) {
|
|
10
|
+
return !!(offer.id && offer.name && offer.price > 0);
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Toggle order bump selection
|
|
14
|
+
*/
|
|
15
|
+
static toggleSelection(offer) {
|
|
16
|
+
return {
|
|
17
|
+
...offer,
|
|
18
|
+
isSelected: !offer.isSelected,
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Calculate order bump preview
|
|
23
|
+
*/
|
|
24
|
+
static calculatePreview(offer, baseAmount = 0) {
|
|
25
|
+
const totalAmount = baseAmount + offer.price;
|
|
26
|
+
const adjustedAmount = offer.isSelected ? totalAmount : baseAmount;
|
|
27
|
+
return {
|
|
28
|
+
offer,
|
|
29
|
+
totalAmount,
|
|
30
|
+
adjustedAmount,
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Get selected order bumps
|
|
35
|
+
*/
|
|
36
|
+
static getSelectedOffers(offers) {
|
|
37
|
+
return offers.filter(offer => offer.isSelected);
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Get total for selected order bumps
|
|
41
|
+
*/
|
|
42
|
+
static getSelectedTotal(offers) {
|
|
43
|
+
return offers
|
|
44
|
+
.filter(offer => offer.isSelected)
|
|
45
|
+
.reduce((total, offer) => total + offer.price, 0);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Plugin Configuration Utility Functions
|
|
3
|
+
* Pure functions for plugin configuration management
|
|
4
|
+
*/
|
|
5
|
+
export interface PluginConfig<TConfig = Record<string, any>> {
|
|
6
|
+
storeId?: string;
|
|
7
|
+
accountId?: string;
|
|
8
|
+
basePath?: string;
|
|
9
|
+
config?: TConfig;
|
|
10
|
+
productId?: string;
|
|
11
|
+
variants?: Record<string, string>;
|
|
12
|
+
prices?: Record<string, any>;
|
|
13
|
+
defaultCurrency?: string;
|
|
14
|
+
hidePriceId?: string;
|
|
15
|
+
upsellId?: string;
|
|
16
|
+
googleApiKey?: string;
|
|
17
|
+
branding?: any;
|
|
18
|
+
}
|
|
19
|
+
export interface RawPluginConfig<TConfig = Record<string, any>> {
|
|
20
|
+
storeId?: string;
|
|
21
|
+
accountId?: string;
|
|
22
|
+
basePath?: string;
|
|
23
|
+
config?: TConfig;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Core plugin config loading function
|
|
27
|
+
* Handles local dev, production, and raw config
|
|
28
|
+
*/
|
|
29
|
+
export declare const loadPluginConfig: (configVariant?: string, rawConfig?: RawPluginConfig) => Promise<PluginConfig>;
|
|
30
|
+
export declare class PluginConfigUtils {
|
|
31
|
+
/**
|
|
32
|
+
* Get plugin configuration from various sources
|
|
33
|
+
*/
|
|
34
|
+
static getPluginConfig<TConfig = Record<string, any>>(rawConfig?: RawPluginConfig<TConfig>, context?: {
|
|
35
|
+
storeId?: string;
|
|
36
|
+
accountId?: string;
|
|
37
|
+
basePath?: string;
|
|
38
|
+
}): PluginConfig<TConfig>;
|
|
39
|
+
/**
|
|
40
|
+
* Validate plugin configuration
|
|
41
|
+
*/
|
|
42
|
+
static validateConfig(config: PluginConfig): boolean;
|
|
43
|
+
}
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Plugin Configuration Utility Functions
|
|
3
|
+
* Pure functions for plugin configuration management
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Load local development configuration
|
|
7
|
+
*/
|
|
8
|
+
const loadLocalDevConfig = async (configVariant = 'default') => {
|
|
9
|
+
try {
|
|
10
|
+
// Only try to load local config in development
|
|
11
|
+
// Use hostname-based detection for better Vite compatibility
|
|
12
|
+
const isLocalDev = typeof window !== 'undefined' &&
|
|
13
|
+
(window.location.hostname === 'localhost' ||
|
|
14
|
+
window.location.hostname.includes('ngrok-free.app') ||
|
|
15
|
+
window.location.hostname.includes('.localhost') ||
|
|
16
|
+
window.location.hostname.includes('127.0.0.1'));
|
|
17
|
+
if (!isLocalDev) {
|
|
18
|
+
return null;
|
|
19
|
+
}
|
|
20
|
+
// Load local store/account config
|
|
21
|
+
const localResponse = await fetch('/.local.json');
|
|
22
|
+
if (!localResponse.ok) {
|
|
23
|
+
return null;
|
|
24
|
+
}
|
|
25
|
+
const localConfig = await localResponse.json();
|
|
26
|
+
// Load deployment config (specified variant or fallback to default)
|
|
27
|
+
let config = {};
|
|
28
|
+
let configLoaded = false;
|
|
29
|
+
try {
|
|
30
|
+
// Try .tgd.json first (new format), then fallback to .json
|
|
31
|
+
let deploymentResponse = await fetch(`/config/${configVariant}.tgd.json`);
|
|
32
|
+
if (!deploymentResponse.ok) {
|
|
33
|
+
deploymentResponse = await fetch(`/config/${configVariant}.json`);
|
|
34
|
+
}
|
|
35
|
+
if (deploymentResponse.ok) {
|
|
36
|
+
config = await deploymentResponse.json();
|
|
37
|
+
configLoaded = true;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
catch {
|
|
41
|
+
// Config fetch failed, will try fallback
|
|
42
|
+
}
|
|
43
|
+
// If config didn't load and it's not 'default', try fallback to default
|
|
44
|
+
if (!configLoaded && configVariant !== 'default') {
|
|
45
|
+
console.warn(`⚠️ Config variant '${configVariant}' not found, falling back to 'default'`);
|
|
46
|
+
try {
|
|
47
|
+
let defaultResponse = await fetch('/config/default.tgd.json');
|
|
48
|
+
if (!defaultResponse.ok) {
|
|
49
|
+
defaultResponse = await fetch('/config/default.json');
|
|
50
|
+
}
|
|
51
|
+
if (defaultResponse.ok) {
|
|
52
|
+
config = await defaultResponse.json();
|
|
53
|
+
configLoaded = true;
|
|
54
|
+
console.log(`✅ Fallback to 'default' config successful`);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
catch {
|
|
58
|
+
// Default config also failed
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
// Final warning if no config was loaded
|
|
62
|
+
if (!configLoaded) {
|
|
63
|
+
if (configVariant === 'default') {
|
|
64
|
+
console.warn(`⚠️ No 'default' config found. Create /config/default.tgd.json`);
|
|
65
|
+
}
|
|
66
|
+
else {
|
|
67
|
+
console.warn(`⚠️ Neither '${configVariant}' nor 'default' config found. Create /config/default.tgd.json`);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
const result = {
|
|
71
|
+
storeId: localConfig.storeId,
|
|
72
|
+
accountId: localConfig.accountId,
|
|
73
|
+
basePath: localConfig.basePath,
|
|
74
|
+
config,
|
|
75
|
+
};
|
|
76
|
+
console.log('🛠️ Using local development plugin config:', result);
|
|
77
|
+
return result;
|
|
78
|
+
}
|
|
79
|
+
catch {
|
|
80
|
+
return null;
|
|
81
|
+
}
|
|
82
|
+
};
|
|
83
|
+
/**
|
|
84
|
+
* Load production config from headers and meta tags
|
|
85
|
+
*/
|
|
86
|
+
const loadProductionConfig = async () => {
|
|
87
|
+
try {
|
|
88
|
+
// Get headers
|
|
89
|
+
const response = await fetch(window.location.href, { method: 'HEAD' });
|
|
90
|
+
const storeId = response.headers.get('X-Plugin-Store-Id') || undefined;
|
|
91
|
+
const accountId = response.headers.get('X-Plugin-Account-Id') || undefined;
|
|
92
|
+
const basePath = response.headers.get('X-Plugin-Base-Path') || '/';
|
|
93
|
+
// Get deployment config from meta tags
|
|
94
|
+
let config = {};
|
|
95
|
+
try {
|
|
96
|
+
const configMeta = document.querySelector('meta[name="x-plugin-config"]');
|
|
97
|
+
const encodedConfig = configMeta?.getAttribute('content');
|
|
98
|
+
if (encodedConfig) {
|
|
99
|
+
const decodedConfig = decodeURIComponent(encodedConfig);
|
|
100
|
+
config = JSON.parse(decodedConfig);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
catch {
|
|
104
|
+
// Deployment config is optional
|
|
105
|
+
}
|
|
106
|
+
console.log('🏭 Using production plugin config 2:', { storeId, accountId, basePath, config });
|
|
107
|
+
return { storeId, accountId, basePath, config };
|
|
108
|
+
}
|
|
109
|
+
catch {
|
|
110
|
+
return { basePath: '/', config: {} };
|
|
111
|
+
}
|
|
112
|
+
};
|
|
113
|
+
/**
|
|
114
|
+
* Core plugin config loading function
|
|
115
|
+
* Handles local dev, production, and raw config
|
|
116
|
+
*/
|
|
117
|
+
export const loadPluginConfig = async (configVariant = 'default', rawConfig) => {
|
|
118
|
+
// If raw config is provided, use it directly
|
|
119
|
+
if (rawConfig) {
|
|
120
|
+
console.log('🛠️ Using raw plugin config:', rawConfig);
|
|
121
|
+
return {
|
|
122
|
+
storeId: rawConfig.storeId,
|
|
123
|
+
accountId: rawConfig.accountId,
|
|
124
|
+
basePath: rawConfig.basePath ?? '/',
|
|
125
|
+
config: rawConfig.config ?? {},
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
// Try local development config
|
|
129
|
+
const localConfig = await loadLocalDevConfig(configVariant);
|
|
130
|
+
if (localConfig) {
|
|
131
|
+
return localConfig;
|
|
132
|
+
}
|
|
133
|
+
// Fall back to production config
|
|
134
|
+
return loadProductionConfig();
|
|
135
|
+
};
|
|
136
|
+
export class PluginConfigUtils {
|
|
137
|
+
/**
|
|
138
|
+
* Get plugin configuration from various sources
|
|
139
|
+
*/
|
|
140
|
+
static getPluginConfig(rawConfig, context) {
|
|
141
|
+
// Priority: rawConfig > context > defaults
|
|
142
|
+
return {
|
|
143
|
+
storeId: rawConfig?.storeId || context?.storeId,
|
|
144
|
+
accountId: rawConfig?.accountId || context?.accountId,
|
|
145
|
+
basePath: rawConfig?.basePath || context?.basePath || '/',
|
|
146
|
+
config: rawConfig?.config || {},
|
|
147
|
+
};
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* Validate plugin configuration
|
|
151
|
+
*/
|
|
152
|
+
static validateConfig(config) {
|
|
153
|
+
return !!(config.storeId && config.accountId);
|
|
154
|
+
}
|
|
155
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Post Purchases Utility Functions
|
|
3
|
+
* Pure functions for post-purchase offer data manipulation
|
|
4
|
+
*/
|
|
5
|
+
import type { PostPurchaseOffer, PostPurchaseOfferItem, PostPurchaseOfferSummary } from '../resources/postPurchases';
|
|
6
|
+
export type { PostPurchaseOffer, PostPurchaseOfferItem, PostPurchaseOfferSummary, };
|
|
7
|
+
export declare class PostPurchasesUtils {
|
|
8
|
+
/**
|
|
9
|
+
* Check if post-purchase offer is valid
|
|
10
|
+
*/
|
|
11
|
+
static isValidOffer(offer: PostPurchaseOffer): boolean;
|
|
12
|
+
/**
|
|
13
|
+
* Get offer total amount
|
|
14
|
+
*/
|
|
15
|
+
static getOfferTotal(offer: PostPurchaseOffer): number;
|
|
16
|
+
/**
|
|
17
|
+
* Get offer adjusted total
|
|
18
|
+
*/
|
|
19
|
+
static getOfferAdjustedTotal(offer: PostPurchaseOffer): number;
|
|
20
|
+
/**
|
|
21
|
+
* Check if offer has items
|
|
22
|
+
*/
|
|
23
|
+
static hasItems(offer: PostPurchaseOffer): boolean;
|
|
24
|
+
/**
|
|
25
|
+
* Get offer currency
|
|
26
|
+
*/
|
|
27
|
+
static getOfferCurrency(offer: PostPurchaseOffer): string;
|
|
28
|
+
/**
|
|
29
|
+
* Get offer title
|
|
30
|
+
*/
|
|
31
|
+
static getOfferTitle(offer: PostPurchaseOffer, locale?: string): string;
|
|
32
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Post Purchases Utility Functions
|
|
3
|
+
* Pure functions for post-purchase offer data manipulation
|
|
4
|
+
*/
|
|
5
|
+
export class PostPurchasesUtils {
|
|
6
|
+
/**
|
|
7
|
+
* Check if post-purchase offer is valid
|
|
8
|
+
*/
|
|
9
|
+
static isValidOffer(offer) {
|
|
10
|
+
return !!(offer.id && offer.summaries && offer.summaries.length > 0);
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Get offer total amount
|
|
14
|
+
*/
|
|
15
|
+
static getOfferTotal(offer) {
|
|
16
|
+
return offer.summaries?.[0]?.totalAmount || 0;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Get offer adjusted total
|
|
20
|
+
*/
|
|
21
|
+
static getOfferAdjustedTotal(offer) {
|
|
22
|
+
return offer.summaries?.[0]?.totalAdjustedAmount || 0;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Check if offer has items
|
|
26
|
+
*/
|
|
27
|
+
static hasItems(offer) {
|
|
28
|
+
return !!(offer.offerLineItems && offer.offerLineItems.length > 0);
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Get offer currency
|
|
32
|
+
*/
|
|
33
|
+
static getOfferCurrency(offer) {
|
|
34
|
+
return offer.summaries?.[0]?.currency || 'USD';
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Get offer title
|
|
38
|
+
*/
|
|
39
|
+
static getOfferTitle(offer, locale = 'en') {
|
|
40
|
+
return offer.titleTrans?.[locale] || offer.titleTrans?.en || `Offer ${offer.id}`;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Products Utility Functions
|
|
3
|
+
* Pure functions for product data manipulation
|
|
4
|
+
*/
|
|
5
|
+
export interface ProductPrice {
|
|
6
|
+
id: string;
|
|
7
|
+
amount: number;
|
|
8
|
+
currency: string;
|
|
9
|
+
recurring: boolean;
|
|
10
|
+
interval?: string;
|
|
11
|
+
intervalCount?: number;
|
|
12
|
+
default?: boolean;
|
|
13
|
+
currencyOptions: Record<string, {
|
|
14
|
+
amount: number;
|
|
15
|
+
currency: string;
|
|
16
|
+
}>;
|
|
17
|
+
}
|
|
18
|
+
export interface ProductVariant {
|
|
19
|
+
id: string;
|
|
20
|
+
name: string;
|
|
21
|
+
description: string;
|
|
22
|
+
sku?: string;
|
|
23
|
+
weight?: number;
|
|
24
|
+
imageUrl?: string;
|
|
25
|
+
default?: boolean;
|
|
26
|
+
prices: ProductPrice[];
|
|
27
|
+
}
|
|
28
|
+
export interface Product {
|
|
29
|
+
id: string;
|
|
30
|
+
name: string;
|
|
31
|
+
description: string;
|
|
32
|
+
imageUrl?: string;
|
|
33
|
+
variants: ProductVariant[];
|
|
34
|
+
}
|
|
35
|
+
export declare class ProductsUtils {
|
|
36
|
+
/**
|
|
37
|
+
* Find a variant by ID within products
|
|
38
|
+
*/
|
|
39
|
+
static findVariant(products: Product[], variantId: string): ProductVariant | null;
|
|
40
|
+
/**
|
|
41
|
+
* Get price for a variant in a specific currency
|
|
42
|
+
*/
|
|
43
|
+
static getVariantPrice(variant: ProductVariant, currency?: string): ProductPrice | null;
|
|
44
|
+
/**
|
|
45
|
+
* Get all variants from products
|
|
46
|
+
*/
|
|
47
|
+
static getAllVariants(products: Product[]): {
|
|
48
|
+
product: Product;
|
|
49
|
+
variant: ProductVariant;
|
|
50
|
+
}[];
|
|
51
|
+
/**
|
|
52
|
+
* Filter variants by predicate
|
|
53
|
+
*/
|
|
54
|
+
static filterVariants(products: Product[], predicate: (variant: ProductVariant, product: Product) => boolean): {
|
|
55
|
+
product: Product;
|
|
56
|
+
variant: ProductVariant;
|
|
57
|
+
}[];
|
|
58
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Products Utility Functions
|
|
3
|
+
* Pure functions for product data manipulation
|
|
4
|
+
*/
|
|
5
|
+
export class ProductsUtils {
|
|
6
|
+
/**
|
|
7
|
+
* Find a variant by ID within products
|
|
8
|
+
*/
|
|
9
|
+
static findVariant(products, variantId) {
|
|
10
|
+
for (const product of products) {
|
|
11
|
+
const variant = product.variants.find(v => v.id === variantId);
|
|
12
|
+
if (variant) {
|
|
13
|
+
return variant;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
return null;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Get price for a variant in a specific currency
|
|
20
|
+
*/
|
|
21
|
+
static getVariantPrice(variant, currency = 'USD') {
|
|
22
|
+
const price = variant.prices.find(p => p.currency === currency);
|
|
23
|
+
if (price) {
|
|
24
|
+
return price;
|
|
25
|
+
}
|
|
26
|
+
// Fallback to default price
|
|
27
|
+
const defaultPrice = variant.prices.find(p => p.default);
|
|
28
|
+
if (defaultPrice) {
|
|
29
|
+
return defaultPrice;
|
|
30
|
+
}
|
|
31
|
+
// Return first available price
|
|
32
|
+
return variant.prices[0] || null;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Get all variants from products
|
|
36
|
+
*/
|
|
37
|
+
static getAllVariants(products) {
|
|
38
|
+
const allVariants = [];
|
|
39
|
+
for (const product of products) {
|
|
40
|
+
if (product.variants) {
|
|
41
|
+
for (const variant of product.variants) {
|
|
42
|
+
allVariants.push({ product, variant });
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
return allVariants;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Filter variants by predicate
|
|
50
|
+
*/
|
|
51
|
+
static filterVariants(products, predicate) {
|
|
52
|
+
const filtered = [];
|
|
53
|
+
for (const product of products) {
|
|
54
|
+
if (product.variants) {
|
|
55
|
+
for (const variant of product.variants) {
|
|
56
|
+
if (predicate(variant, product)) {
|
|
57
|
+
filtered.push({ product, variant });
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
return filtered;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Promotions Utility Functions
|
|
3
|
+
* Pure functions for promotion data manipulation
|
|
4
|
+
*/
|
|
5
|
+
import type { Promotion } from '../resources/checkout';
|
|
6
|
+
export type { Promotion };
|
|
7
|
+
export declare class PromotionsUtils {
|
|
8
|
+
/**
|
|
9
|
+
* Check if promotion is valid
|
|
10
|
+
*/
|
|
11
|
+
static isValidPromotion(promotion: Promotion): boolean;
|
|
12
|
+
/**
|
|
13
|
+
* Get promotion type
|
|
14
|
+
*/
|
|
15
|
+
static getPromotionType(promotion: Promotion): string;
|
|
16
|
+
/**
|
|
17
|
+
* Check if promotion has rules
|
|
18
|
+
*/
|
|
19
|
+
static hasRules(promotion: Promotion): boolean;
|
|
20
|
+
/**
|
|
21
|
+
* Check if promotion has actions
|
|
22
|
+
*/
|
|
23
|
+
static hasActions(promotion: Promotion): boolean;
|
|
24
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Promotions Utility Functions
|
|
3
|
+
* Pure functions for promotion data manipulation
|
|
4
|
+
*/
|
|
5
|
+
export class PromotionsUtils {
|
|
6
|
+
/**
|
|
7
|
+
* Check if promotion is valid
|
|
8
|
+
*/
|
|
9
|
+
static isValidPromotion(promotion) {
|
|
10
|
+
return !!(promotion.id && promotion.name);
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Get promotion type
|
|
14
|
+
*/
|
|
15
|
+
static getPromotionType(promotion) {
|
|
16
|
+
return promotion.type || 'unknown';
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Check if promotion has rules
|
|
20
|
+
*/
|
|
21
|
+
static hasRules(promotion) {
|
|
22
|
+
return !!(promotion.rules && promotion.rules.length > 0);
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Check if promotion has actions
|
|
26
|
+
*/
|
|
27
|
+
static hasActions(promotion) {
|
|
28
|
+
return !!(promotion.actions && promotion.actions.length > 0);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* TagadaPay Plugin SDK v2
|
|
3
|
+
*
|
|
4
|
+
* Clean architecture with separated core and react layers:
|
|
5
|
+
* - core: Pure functions without React dependencies
|
|
6
|
+
* - react: React hooks and components using core functions
|
|
7
|
+
*/
|
|
8
|
+
export * from './core/utils/pluginConfig';
|
|
9
|
+
export * from './core/utils/products';
|
|
10
|
+
export * from './core/googleAutocomplete';
|
|
11
|
+
export * from './core/isoData';
|
|
12
|
+
export * from './core/utils/currency';
|
|
13
|
+
export type { CheckoutData, CheckoutSession, CheckoutLineItem, CheckoutInitParams, Promotion, } from './core/resources/checkout';
|
|
14
|
+
export type { Order, OrderLineItem, } from './core/utils/order';
|
|
15
|
+
export type { PostPurchaseOffer, PostPurchaseOfferItem, PostPurchaseOfferSummary, } from './core/resources/postPurchases';
|
|
16
|
+
export type { Offer, OfferItem, OfferSummary, } from './core/resources/offers';
|
|
17
|
+
export type { OrderBumpOffer, OrderBumpPreview, } from './core/utils/orderBump';
|
|
18
|
+
export type { Payment, PaymentResponse, PaymentOptions, CardPaymentMethod, ApplePayToken, PaymentInstrumentResponse, PaymentInstrumentCustomerResponse, PaymentInstrumentCustomer } from './core/resources/payments';
|
|
19
|
+
export { TagadaProvider, useTagadaContext, useCheckoutToken, usePluginConfig, useGoogleAutocomplete, useGeoLocation, useISOData, getAvailableLanguages, useLanguageImport, useCountryOptions, useRegionOptions, useCheckout, useOrderBump, usePromotions, useProducts, useOrder, usePostPurchases, useOffers, usePayment, useThreeds, useThreedsModal, useCurrency, useApiQuery, useApiMutation, useInvalidateQuery, usePreloadQuery, queryKeys, formatMoney } from './react';
|
package/dist/v2/index.js
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* TagadaPay Plugin SDK v2
|
|
3
|
+
*
|
|
4
|
+
* Clean architecture with separated core and react layers:
|
|
5
|
+
* - core: Pure functions without React dependencies
|
|
6
|
+
* - react: React hooks and components using core functions
|
|
7
|
+
*/
|
|
8
|
+
// Core exports (selective to avoid conflicts)
|
|
9
|
+
export * from './core/utils/pluginConfig';
|
|
10
|
+
export * from './core/utils/products';
|
|
11
|
+
export * from './core/googleAutocomplete';
|
|
12
|
+
export * from './core/isoData';
|
|
13
|
+
export * from './core/utils/currency';
|
|
14
|
+
// React exports (hooks and components only, types are exported above)
|
|
15
|
+
export { TagadaProvider, useTagadaContext, useCheckoutToken, usePluginConfig, useGoogleAutocomplete, useGeoLocation, useISOData, getAvailableLanguages, useLanguageImport, useCountryOptions, useRegionOptions, useCheckout, useOrderBump, usePromotions, useProducts, useOrder, usePostPurchases, useOffers, usePayment, useThreeds, useThreedsModal, useCurrency, useApiQuery, useApiMutation, useInvalidateQuery, usePreloadQuery, queryKeys, formatMoney } from './react';
|