@tagadapay/plugin-sdk 2.4.39 → 2.5.2

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/dist/index.d.ts +1 -0
  2. package/dist/index.js +2 -0
  3. package/dist/react/hooks/useCheckout.js +19 -2
  4. package/dist/react/hooks/useCheckoutSession.d.ts +19 -0
  5. package/dist/react/hooks/useCheckoutSession.js +108 -0
  6. package/dist/react/hooks/useCheckoutToken.d.ts +17 -0
  7. package/dist/react/hooks/useCheckoutToken.js +80 -0
  8. package/dist/react/hooks/useOrderBump.js +92 -13
  9. package/dist/react/hooks/useOrderBumpV2.d.ts +17 -0
  10. package/dist/react/hooks/useOrderBumpV2.js +95 -0
  11. package/dist/react/hooks/useOrderBumpV3.d.ts +23 -0
  12. package/dist/react/hooks/useOrderBumpV3.js +109 -0
  13. package/dist/react/hooks/usePostPurchases.js +11 -5
  14. package/dist/react/index.d.ts +8 -0
  15. package/dist/react/index.js +4 -0
  16. package/dist/react/services/apiService.d.ts +1 -0
  17. package/dist/react/services/apiService.js +3 -0
  18. package/dist/v2/core/googleAutocomplete.d.ts +65 -0
  19. package/dist/v2/core/googleAutocomplete.js +94 -0
  20. package/dist/v2/core/index.d.ts +8 -0
  21. package/dist/v2/core/index.js +11 -0
  22. package/dist/v2/core/isoData.d.ts +50 -0
  23. package/dist/v2/core/isoData.js +103 -0
  24. package/dist/v2/core/resources/apiClient.d.ts +25 -0
  25. package/dist/v2/core/resources/apiClient.js +95 -0
  26. package/dist/v2/core/resources/checkout.d.ts +189 -0
  27. package/dist/v2/core/resources/checkout.js +119 -0
  28. package/dist/v2/core/resources/index.d.ts +13 -0
  29. package/dist/v2/core/resources/index.js +13 -0
  30. package/dist/v2/core/resources/offers.d.ts +98 -0
  31. package/dist/v2/core/resources/offers.js +115 -0
  32. package/dist/v2/core/resources/orders.d.ts +40 -0
  33. package/dist/v2/core/resources/orders.js +59 -0
  34. package/dist/v2/core/resources/payments.d.ts +140 -0
  35. package/dist/v2/core/resources/payments.js +126 -0
  36. package/dist/v2/core/resources/postPurchases.d.ts +182 -0
  37. package/dist/v2/core/resources/postPurchases.js +116 -0
  38. package/dist/v2/core/resources/products.d.ts +29 -0
  39. package/dist/v2/core/resources/products.js +49 -0
  40. package/dist/v2/core/resources/promotions.d.ts +45 -0
  41. package/dist/v2/core/resources/promotions.js +87 -0
  42. package/dist/v2/core/resources/threeds.d.ts +23 -0
  43. package/dist/v2/core/resources/threeds.js +15 -0
  44. package/dist/v2/core/utils/checkout.d.ts +24 -0
  45. package/dist/v2/core/utils/checkout.js +30 -0
  46. package/dist/v2/core/utils/currency.d.ts +28 -0
  47. package/dist/v2/core/utils/currency.js +272 -0
  48. package/dist/v2/core/utils/index.d.ts +12 -0
  49. package/dist/v2/core/utils/index.js +12 -0
  50. package/dist/v2/core/utils/order.d.ts +159 -0
  51. package/dist/v2/core/utils/order.js +42 -0
  52. package/dist/v2/core/utils/orderBump.d.ts +40 -0
  53. package/dist/v2/core/utils/orderBump.js +47 -0
  54. package/dist/v2/core/utils/pluginConfig.d.ts +43 -0
  55. package/dist/v2/core/utils/pluginConfig.js +155 -0
  56. package/dist/v2/core/utils/postPurchases.d.ts +32 -0
  57. package/dist/v2/core/utils/postPurchases.js +42 -0
  58. package/dist/v2/core/utils/products.d.ts +58 -0
  59. package/dist/v2/core/utils/products.js +64 -0
  60. package/dist/v2/core/utils/promotions.d.ts +24 -0
  61. package/dist/v2/core/utils/promotions.js +30 -0
  62. package/dist/v2/index.d.ts +19 -0
  63. package/dist/v2/index.js +15 -0
  64. package/dist/v2/react/components/DebugDrawer.d.ts +7 -0
  65. package/dist/v2/react/components/DebugDrawer.js +383 -0
  66. package/dist/v2/react/hooks/useApiQuery.d.ts +28 -0
  67. package/dist/v2/react/hooks/useApiQuery.js +84 -0
  68. package/dist/v2/react/hooks/useCheckoutQuery.d.ts +39 -0
  69. package/dist/v2/react/hooks/useCheckoutQuery.js +194 -0
  70. package/dist/v2/react/hooks/useCheckoutToken.d.ts +17 -0
  71. package/dist/v2/react/hooks/useCheckoutToken.js +65 -0
  72. package/dist/v2/react/hooks/useCurrency.d.ts +9 -0
  73. package/dist/v2/react/hooks/useCurrency.js +21 -0
  74. package/dist/v2/react/hooks/useGeoLocation.d.ts +138 -0
  75. package/dist/v2/react/hooks/useGeoLocation.js +123 -0
  76. package/dist/v2/react/hooks/useGoogleAutocomplete.d.ts +74 -0
  77. package/dist/v2/react/hooks/useGoogleAutocomplete.js +196 -0
  78. package/dist/v2/react/hooks/useISOData.d.ts +61 -0
  79. package/dist/v2/react/hooks/useISOData.js +175 -0
  80. package/dist/v2/react/hooks/useOffersQuery.d.ts +65 -0
  81. package/dist/v2/react/hooks/useOffersQuery.js +342 -0
  82. package/dist/v2/react/hooks/useOrderBumpQuery.d.ts +20 -0
  83. package/dist/v2/react/hooks/useOrderBumpQuery.js +92 -0
  84. package/dist/v2/react/hooks/useOrderQuery.d.ts +29 -0
  85. package/dist/v2/react/hooks/useOrderQuery.js +98 -0
  86. package/dist/v2/react/hooks/usePaymentPolling.d.ts +45 -0
  87. package/dist/v2/react/hooks/usePaymentPolling.js +140 -0
  88. package/dist/v2/react/hooks/usePaymentQuery.d.ts +19 -0
  89. package/dist/v2/react/hooks/usePaymentQuery.js +272 -0
  90. package/dist/v2/react/hooks/usePluginConfig.d.ts +16 -0
  91. package/dist/v2/react/hooks/usePluginConfig.js +35 -0
  92. package/dist/v2/react/hooks/usePostPurchasesQuery.d.ts +63 -0
  93. package/dist/v2/react/hooks/usePostPurchasesQuery.js +343 -0
  94. package/dist/v2/react/hooks/useProductsQuery.d.ts +31 -0
  95. package/dist/v2/react/hooks/useProductsQuery.js +102 -0
  96. package/dist/v2/react/hooks/usePromotionsQuery.d.ts +28 -0
  97. package/dist/v2/react/hooks/usePromotionsQuery.js +97 -0
  98. package/dist/v2/react/hooks/useThreeds.d.ts +36 -0
  99. package/dist/v2/react/hooks/useThreeds.js +150 -0
  100. package/dist/v2/react/hooks/useThreedsModal.d.ts +13 -0
  101. package/dist/v2/react/hooks/useThreedsModal.js +343 -0
  102. package/dist/v2/react/index.d.ts +38 -0
  103. package/dist/v2/react/index.js +27 -0
  104. package/dist/v2/react/providers/TagadaProvider.d.ts +63 -0
  105. package/dist/v2/react/providers/TagadaProvider.js +680 -0
  106. package/package.json +10 -3
@@ -0,0 +1,196 @@
1
+ /**
2
+ * Google Autocomplete Hook - V2 Implementation
3
+ * Compatible with V1 interface while using V2 core architecture
4
+ */
5
+ import { useCallback, useEffect, useRef, useState } from 'react';
6
+ /**
7
+ * React hook for Google Places Autocomplete with automatic script injection
8
+ * Automatically loads the Google Maps JavaScript API with Places library
9
+ */
10
+ export function useGoogleAutocomplete(options) {
11
+ const { apiKey, libraries = ['places'], version = 'weekly', language, region } = options;
12
+ const [predictions, setPredictions] = useState([]);
13
+ const [isLoading, setIsLoading] = useState(false);
14
+ const [isScriptLoaded, setIsScriptLoaded] = useState(false);
15
+ const autocompleteServiceRef = useRef(null);
16
+ const placesServiceRef = useRef(null);
17
+ const scriptLoadedRef = useRef(false);
18
+ // Inject Google Maps script
19
+ useEffect(() => {
20
+ if (!apiKey) {
21
+ return;
22
+ }
23
+ if (scriptLoadedRef.current || window.google?.maps) {
24
+ setIsScriptLoaded(true);
25
+ return;
26
+ }
27
+ // Check if script is already being loaded
28
+ const existingScript = document.querySelector('script[src*="maps.googleapis.com"]');
29
+ if (existingScript) {
30
+ // Wait for existing script to load
31
+ const checkLoaded = () => {
32
+ if (window.google?.maps?.places?.AutocompleteService) {
33
+ setIsScriptLoaded(true);
34
+ scriptLoadedRef.current = true;
35
+ }
36
+ else {
37
+ setTimeout(checkLoaded, 100);
38
+ }
39
+ };
40
+ checkLoaded();
41
+ return;
42
+ }
43
+ // Create and inject the script
44
+ const script = document.createElement('script');
45
+ const params = new URLSearchParams({
46
+ key: apiKey,
47
+ libraries: libraries.join(','),
48
+ v: version,
49
+ });
50
+ if (language)
51
+ params.append('language', language);
52
+ if (region)
53
+ params.append('region', region);
54
+ script.src = `https://maps.googleapis.com/maps/api/js?${params.toString()}`;
55
+ script.async = true;
56
+ script.defer = true;
57
+ script.onload = () => {
58
+ setIsScriptLoaded(true);
59
+ scriptLoadedRef.current = true;
60
+ };
61
+ script.onerror = () => {
62
+ // Failed to load Google Maps API
63
+ };
64
+ document.head.appendChild(script);
65
+ // Cleanup function
66
+ return () => {
67
+ // Note: We don't remove the script as it might be used by other components
68
+ // The script will remain in the DOM for the session
69
+ };
70
+ }, [apiKey, libraries, version, language, region]);
71
+ // Initialize Google Places services
72
+ const initializeServices = useCallback(() => {
73
+ if (typeof window === 'undefined')
74
+ return false;
75
+ if (!window.google?.maps?.places?.AutocompleteService) {
76
+ return false;
77
+ }
78
+ if (!autocompleteServiceRef.current) {
79
+ autocompleteServiceRef.current = new window.google.maps.places.AutocompleteService();
80
+ }
81
+ if (!placesServiceRef.current) {
82
+ // Create a dummy map for PlacesService (required by Google API)
83
+ const map = new window.google.maps.Map(document.createElement('div'));
84
+ placesServiceRef.current = new window.google.maps.places.PlacesService(map);
85
+ }
86
+ return true;
87
+ }, []);
88
+ // Search for place predictions
89
+ const searchPlaces = useCallback((input, countryRestriction) => {
90
+ if (!isScriptLoaded) {
91
+ return;
92
+ }
93
+ if (!initializeServices()) {
94
+ return;
95
+ }
96
+ if (input.length < 3) {
97
+ setPredictions([]);
98
+ return;
99
+ }
100
+ setIsLoading(true);
101
+ const request = {
102
+ input,
103
+ ...(countryRestriction && {
104
+ componentRestrictions: { country: countryRestriction.toLowerCase() },
105
+ }),
106
+ };
107
+ autocompleteServiceRef.current.getPlacePredictions(request, (results, status) => {
108
+ setIsLoading(false);
109
+ if (status === window.google.maps.places.PlacesServiceStatus.OK && results) {
110
+ setPredictions(results);
111
+ }
112
+ else {
113
+ setPredictions([]);
114
+ if (status !== window.google.maps.places.PlacesServiceStatus.ZERO_RESULTS) {
115
+ // Prediction failed but not zero results
116
+ }
117
+ }
118
+ });
119
+ }, [initializeServices, isScriptLoaded]);
120
+ // Get detailed place information
121
+ const getPlaceDetails = useCallback((placeId) => {
122
+ return new Promise((resolve) => {
123
+ if (!isScriptLoaded) {
124
+ resolve(null);
125
+ return;
126
+ }
127
+ if (!initializeServices()) {
128
+ resolve(null);
129
+ return;
130
+ }
131
+ const request = {
132
+ placeId,
133
+ fields: ['place_id', 'formatted_address', 'address_components', 'geometry'],
134
+ };
135
+ placesServiceRef.current.getDetails(request, (place, status) => {
136
+ if (status === window.google.maps.places.PlacesServiceStatus.OK && place) {
137
+ resolve(place);
138
+ }
139
+ else {
140
+ resolve(null);
141
+ }
142
+ });
143
+ });
144
+ }, [initializeServices, isScriptLoaded]);
145
+ // Extract structured address components from Google place
146
+ const extractAddressComponents = useCallback((place) => {
147
+ const extracted = {
148
+ streetNumber: '',
149
+ route: '',
150
+ locality: '',
151
+ administrativeAreaLevel1: '',
152
+ administrativeAreaLevel1Long: '',
153
+ country: '',
154
+ postalCode: '',
155
+ };
156
+ place.address_components?.forEach((component) => {
157
+ const types = component.types;
158
+ if (types.includes('street_number')) {
159
+ extracted.streetNumber = component.long_name;
160
+ }
161
+ if (types.includes('route')) {
162
+ extracted.route = component.long_name;
163
+ }
164
+ if (types.includes('locality')) {
165
+ extracted.locality = component.long_name;
166
+ }
167
+ if (types.includes('administrative_area_level_2') && !extracted.locality) {
168
+ extracted.locality = component.long_name;
169
+ }
170
+ if (types.includes('administrative_area_level_1')) {
171
+ extracted.administrativeAreaLevel1 = component.short_name;
172
+ extracted.administrativeAreaLevel1Long = component.long_name;
173
+ }
174
+ if (types.includes('country')) {
175
+ extracted.country = component.short_name;
176
+ }
177
+ if (types.includes('postal_code')) {
178
+ extracted.postalCode = component.long_name;
179
+ }
180
+ });
181
+ return extracted;
182
+ }, []);
183
+ // Clear predictions
184
+ const clearPredictions = useCallback(() => {
185
+ setPredictions([]);
186
+ }, []);
187
+ return {
188
+ predictions,
189
+ isLoading,
190
+ isScriptLoaded,
191
+ searchPlaces,
192
+ getPlaceDetails,
193
+ extractAddressComponents,
194
+ clearPredictions,
195
+ };
196
+ }
@@ -0,0 +1,61 @@
1
+ import { type SupportedLanguage } from '../../../data/iso3166';
2
+ export interface ISOCountry {
3
+ iso: string;
4
+ iso3: string;
5
+ numeric: number;
6
+ name: string;
7
+ }
8
+ export interface ISORegion {
9
+ iso: string;
10
+ name: string;
11
+ }
12
+ export interface UseISODataResult {
13
+ countries: Record<string, ISOCountry>;
14
+ getRegions: (countryCode: string) => ISORegion[];
15
+ findRegion: (countryCode: string, regionCode: string) => ISORegion | null;
16
+ mapGoogleToISO: (googleState: string, googleStateLong: string, countryCode: string) => ISORegion | null;
17
+ isLanguageLoaded: boolean;
18
+ registeredLanguages: SupportedLanguage[];
19
+ }
20
+ /**
21
+ * React hook for accessing ISO3166 countries and regions data with dynamic language loading
22
+ * @param language - Language code (supports: en, ru, de, fr, es, zh, hi, pt, ja, ar, it, he)
23
+ * @param autoImport - Whether to automatically import the language if not registered (default: true)
24
+ * @param disputeSetting - Territorial dispute perspective (currently only UN is supported)
25
+ * @returns Object with countries data and helper functions
26
+ */
27
+ export declare function useISOData(language?: SupportedLanguage, autoImport?: boolean, disputeSetting?: string): UseISODataResult;
28
+ /**
29
+ * Get available languages for ISO data
30
+ */
31
+ export declare function getAvailableLanguages(): SupportedLanguage[];
32
+ /**
33
+ * Hook to manually import and register a language
34
+ * @param language - Language code to import
35
+ * @returns Object with loading state and error handling
36
+ */
37
+ export declare function useLanguageImport(language: SupportedLanguage): {
38
+ importLanguage: () => Promise<void>;
39
+ isLoading: boolean;
40
+ error: string | null;
41
+ isRegistered: boolean;
42
+ };
43
+ /**
44
+ * Get list of countries as options for select components
45
+ * @param language - Language code (defaults to 'en')
46
+ * @param autoImport - Whether to automatically import the language if not registered (default: true)
47
+ */
48
+ export declare function useCountryOptions(language?: SupportedLanguage, autoImport?: boolean): {
49
+ value: string;
50
+ label: string;
51
+ }[];
52
+ /**
53
+ * Get list of regions/states for a country as options for select components
54
+ * @param countryCode - ISO country code
55
+ * @param language - Language code (defaults to 'en')
56
+ * @param autoImport - Whether to automatically import the language if not registered (default: true)
57
+ */
58
+ export declare function useRegionOptions(countryCode: string, language?: SupportedLanguage, autoImport?: boolean): {
59
+ value: string;
60
+ label: string;
61
+ }[];
@@ -0,0 +1,175 @@
1
+ import { useMemo, useEffect, useState, useCallback } from 'react';
2
+ // Import the pre-built ISO data functions
3
+ import { getCountries, getStatesForCountry, importLanguage, isLanguageRegistered, getRegisteredLanguages } from '../../../data/iso3166';
4
+ /**
5
+ * React hook for accessing ISO3166 countries and regions data with dynamic language loading
6
+ * @param language - Language code (supports: en, ru, de, fr, es, zh, hi, pt, ja, ar, it, he)
7
+ * @param autoImport - Whether to automatically import the language if not registered (default: true)
8
+ * @param disputeSetting - Territorial dispute perspective (currently only UN is supported)
9
+ * @returns Object with countries data and helper functions
10
+ */
11
+ export function useISOData(language = 'en', autoImport = true, disputeSetting = 'UN') {
12
+ const [isLanguageLoaded, setIsLanguageLoaded] = useState(isLanguageRegistered(language));
13
+ const [registeredLanguages, setRegisteredLanguages] = useState(getRegisteredLanguages);
14
+ // Auto-import language if not registered and autoImport is true
15
+ useEffect(() => {
16
+ if (!isLanguageRegistered(language) && autoImport && language !== 'en') {
17
+ importLanguage(language)
18
+ .then(() => {
19
+ setIsLanguageLoaded(true);
20
+ setRegisteredLanguages(getRegisteredLanguages());
21
+ })
22
+ .catch((error) => {
23
+ });
24
+ }
25
+ }, [language, autoImport]);
26
+ const data = useMemo(() => {
27
+ try {
28
+ // Get countries from pre-built data with language support
29
+ const countriesArray = getCountries(language);
30
+ // Transform to our expected format (Record<string, ISOCountry>)
31
+ const countries = {};
32
+ countriesArray.forEach((country) => {
33
+ countries[country.code] = {
34
+ iso: country.code,
35
+ iso3: country.iso3 || '',
36
+ numeric: country.numeric || 0,
37
+ name: country.name,
38
+ };
39
+ });
40
+ // Helper to load regions for a specific country
41
+ const getRegions = (countryCode) => {
42
+ try {
43
+ const states = getStatesForCountry(countryCode, language);
44
+ return states.map((state) => ({
45
+ iso: state.code,
46
+ name: state.name,
47
+ }));
48
+ }
49
+ catch {
50
+ return []; // Return empty array if no regions
51
+ }
52
+ };
53
+ // Find a specific region by ISO code
54
+ const findRegion = (countryCode, regionCode) => {
55
+ const regions = getRegions(countryCode);
56
+ return regions.find((region) => region.iso === regionCode) ?? null;
57
+ };
58
+ // Map Google Places state to ISO region (proven 100% success rate)
59
+ const mapGoogleToISO = (googleState, googleStateLong, countryCode) => {
60
+ const regions = getRegions(countryCode);
61
+ if (regions.length === 0)
62
+ return null;
63
+ // Strategy 1: Exact ISO code match (86% success rate)
64
+ let match = regions.find((r) => r.iso === googleState);
65
+ if (match)
66
+ return match;
67
+ // Strategy 2: Name matching (14% success rate)
68
+ match = regions.find((r) => r.name.toLowerCase() === googleState.toLowerCase());
69
+ if (match)
70
+ return match;
71
+ match = regions.find((r) => r.name.toLowerCase() === googleStateLong.toLowerCase());
72
+ if (match)
73
+ return match;
74
+ // Strategy 3: Partial name matching (fallback)
75
+ match = regions.find((r) => r.name.toLowerCase().includes(googleStateLong.toLowerCase()) ||
76
+ googleStateLong.toLowerCase().includes(r.name.toLowerCase()));
77
+ return match ?? null;
78
+ };
79
+ return {
80
+ countries,
81
+ getRegions,
82
+ findRegion,
83
+ mapGoogleToISO,
84
+ isLanguageLoaded,
85
+ registeredLanguages,
86
+ };
87
+ }
88
+ catch (_error) {
89
+ // Error handling removed
90
+ return {
91
+ countries: {},
92
+ getRegions: () => [],
93
+ findRegion: () => null,
94
+ mapGoogleToISO: () => null,
95
+ isLanguageLoaded,
96
+ registeredLanguages,
97
+ };
98
+ }
99
+ }, [language, disputeSetting, isLanguageLoaded, registeredLanguages]);
100
+ return data;
101
+ }
102
+ /**
103
+ * Get available languages for ISO data
104
+ */
105
+ export function getAvailableLanguages() {
106
+ // Return all available languages (not just registered ones)
107
+ return ['en', 'ru', 'de', 'fr', 'es', 'zh', 'hi', 'pt', 'ja', 'ar', 'it', 'he'];
108
+ }
109
+ /**
110
+ * Hook to manually import and register a language
111
+ * @param language - Language code to import
112
+ * @returns Object with loading state and error handling
113
+ */
114
+ export function useLanguageImport(language) {
115
+ const [isLoading, setIsLoading] = useState(false);
116
+ const [error, setError] = useState(null);
117
+ const importLanguageData = useCallback(async () => {
118
+ if (isLanguageRegistered(language)) {
119
+ return; // Already registered
120
+ }
121
+ setIsLoading(true);
122
+ setError(null);
123
+ try {
124
+ await importLanguage(language);
125
+ }
126
+ catch (err) {
127
+ setError(err instanceof Error ? err.message : 'Failed to import language');
128
+ }
129
+ finally {
130
+ setIsLoading(false);
131
+ }
132
+ }, [language]);
133
+ return {
134
+ importLanguage: importLanguageData,
135
+ isLoading,
136
+ error,
137
+ isRegistered: isLanguageRegistered(language),
138
+ };
139
+ }
140
+ /**
141
+ * Get list of countries as options for select components
142
+ * @param language - Language code (defaults to 'en')
143
+ * @param autoImport - Whether to automatically import the language if not registered (default: true)
144
+ */
145
+ export function useCountryOptions(language = 'en', autoImport = true) {
146
+ const { countries } = useISOData(language, autoImport);
147
+ return useMemo(() => {
148
+ return Object.entries(countries)
149
+ .map(([code, country]) => ({
150
+ value: code,
151
+ label: country.name,
152
+ }))
153
+ .sort((a, b) => a.label.localeCompare(b.label));
154
+ }, [countries]);
155
+ }
156
+ /**
157
+ * Get list of regions/states for a country as options for select components
158
+ * @param countryCode - ISO country code
159
+ * @param language - Language code (defaults to 'en')
160
+ * @param autoImport - Whether to automatically import the language if not registered (default: true)
161
+ */
162
+ export function useRegionOptions(countryCode, language = 'en', autoImport = true) {
163
+ const { getRegions } = useISOData(language, autoImport);
164
+ return useMemo(() => {
165
+ if (!countryCode)
166
+ return [];
167
+ const regions = getRegions(countryCode);
168
+ return regions
169
+ .map((region) => ({
170
+ value: region.iso,
171
+ label: region.name,
172
+ }))
173
+ .sort((a, b) => a.label.localeCompare(b.label));
174
+ }, [countryCode, getRegions]);
175
+ }
@@ -0,0 +1,65 @@
1
+ /**
2
+ * Offers Hook using TanStack Query
3
+ * Handles offers with automatic caching
4
+ */
5
+ import { Offer } from '../../core/resources/offers';
6
+ import { CheckoutSessionState, OrderSummary, CurrencyOptions } from '../../core/resources/postPurchases';
7
+ export interface UseOffersQueryOptions {
8
+ /**
9
+ * Array of offer IDs to fetch
10
+ */
11
+ offerIds?: string[];
12
+ /**
13
+ * Whether to fetch offers automatically on mount
14
+ * @default true
15
+ */
16
+ enabled?: boolean;
17
+ /**
18
+ * Return URL for checkout sessions
19
+ */
20
+ returnUrl?: string;
21
+ }
22
+ export interface UseOffersQueryResult {
23
+ offers: Offer[];
24
+ isLoading: boolean;
25
+ error: Error | null;
26
+ refetch: () => Promise<void>;
27
+ createCheckoutSession: (offerId: string, options?: {
28
+ returnUrl?: string;
29
+ }) => Promise<{
30
+ checkoutUrl: string;
31
+ }>;
32
+ payOffer: (offerId: string, orderId?: string) => Promise<void>;
33
+ transformToCheckout: (offerId: string, options?: {
34
+ returnUrl?: string;
35
+ }) => Promise<{
36
+ checkoutUrl: string;
37
+ }>;
38
+ getOffer: (offerId: string) => Offer | undefined;
39
+ getTotalValue: () => number;
40
+ getTotalSavings: () => number;
41
+ payWithCheckoutSession: (checkoutSessionId: string, orderId?: string) => Promise<void>;
42
+ initCheckoutSession: (offerId: string, orderId: string, customerId?: string) => Promise<{
43
+ checkoutSessionId: string;
44
+ }>;
45
+ getCheckoutSessionState: (offerId: string) => CheckoutSessionState | null;
46
+ initializeOfferCheckout: (offerId: string) => Promise<void>;
47
+ getAvailableVariants: (offerId: string, productId: string) => {
48
+ variantId: string;
49
+ variantName: string;
50
+ variantSku: string | null;
51
+ variantDefault: boolean | null;
52
+ variantExternalId: string | null;
53
+ priceId: string;
54
+ currencyOptions: CurrencyOptions;
55
+ }[];
56
+ selectVariant: (offerId: string, productId: string, variantId: string) => Promise<void>;
57
+ getOrderSummary: (offerId: string) => OrderSummary | null;
58
+ isLoadingVariants: (offerId: string, productId: string) => boolean;
59
+ isUpdatingOrderSummary: (offerId: string) => boolean;
60
+ confirmPurchase: (offerId: string, options?: {
61
+ draft?: boolean;
62
+ returnUrl?: string;
63
+ }) => Promise<void>;
64
+ }
65
+ export declare function useOffersQuery(options?: UseOffersQueryOptions): UseOffersQueryResult;