@tagadapay/plugin-sdk 2.4.38 → 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 +21 -33
- 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 +94 -29
- 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/usePayment.d.ts +1 -1
- package/dist/react/hooks/usePayment.js +2 -18
- package/dist/react/hooks/usePluginConfig.js +2 -13
- package/dist/react/hooks/usePostPurchases.js +11 -5
- package/dist/react/hooks/useProducts.js +2 -16
- package/dist/react/index.d.ts +9 -1
- package/dist/react/index.js +5 -1
- package/dist/react/providers/TagadaProvider.d.ts +0 -1
- package/dist/react/providers/TagadaProvider.js +16 -12
- 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,103 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ISO Data Core
|
|
3
|
+
* Pure functions for country and region data management
|
|
4
|
+
* Uses the existing iso3166 data functions
|
|
5
|
+
*/
|
|
6
|
+
// Import the pre-built ISO data functions
|
|
7
|
+
import { getCountries, getStatesForCountry, importLanguage, isLanguageRegistered, getRegisteredLanguages } from '../../data/iso3166';
|
|
8
|
+
export class ISODataCore {
|
|
9
|
+
/**
|
|
10
|
+
* Get countries data for a specific language
|
|
11
|
+
*/
|
|
12
|
+
static getCountriesData(language = 'en') {
|
|
13
|
+
try {
|
|
14
|
+
// Get countries from pre-built data with language support
|
|
15
|
+
const countriesArray = getCountries(language);
|
|
16
|
+
// Transform to our expected format (Record<string, ISOCountry>)
|
|
17
|
+
const countries = {};
|
|
18
|
+
countriesArray.forEach((country) => {
|
|
19
|
+
countries[country.code] = {
|
|
20
|
+
iso: country.code,
|
|
21
|
+
iso3: country.iso3 || '',
|
|
22
|
+
numeric: country.numeric || 0,
|
|
23
|
+
name: country.name,
|
|
24
|
+
};
|
|
25
|
+
});
|
|
26
|
+
return countries;
|
|
27
|
+
}
|
|
28
|
+
catch (error) {
|
|
29
|
+
console.error(`Failed to load ISO data for language: ${language}`, error);
|
|
30
|
+
return {};
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Get regions for a specific country
|
|
35
|
+
*/
|
|
36
|
+
static getRegions(countryCode, language = 'en') {
|
|
37
|
+
try {
|
|
38
|
+
const states = getStatesForCountry(countryCode, language);
|
|
39
|
+
return states.map((state) => ({
|
|
40
|
+
iso: state.code,
|
|
41
|
+
name: state.name,
|
|
42
|
+
}));
|
|
43
|
+
}
|
|
44
|
+
catch {
|
|
45
|
+
return []; // Return empty array if no regions
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Find a specific region by ISO code
|
|
50
|
+
*/
|
|
51
|
+
static findRegion(countryCode, regionCode, language = 'en') {
|
|
52
|
+
const regions = this.getRegions(countryCode, language);
|
|
53
|
+
return regions.find((region) => region.iso === regionCode) ?? null;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Map Google Places state to ISO region (proven 100% success rate)
|
|
57
|
+
*/
|
|
58
|
+
static mapGoogleToISO(googleState, googleStateLong, countryCode, language = 'en') {
|
|
59
|
+
const regions = this.getRegions(countryCode, language);
|
|
60
|
+
if (regions.length === 0)
|
|
61
|
+
return null;
|
|
62
|
+
// Strategy 1: Exact ISO code match (86% success rate)
|
|
63
|
+
let match = regions.find((r) => r.iso === googleState);
|
|
64
|
+
if (match)
|
|
65
|
+
return match;
|
|
66
|
+
// Strategy 2: Name matching (14% success rate)
|
|
67
|
+
match = regions.find((r) => r.name.toLowerCase() === googleState.toLowerCase());
|
|
68
|
+
if (match)
|
|
69
|
+
return match;
|
|
70
|
+
match = regions.find((r) => r.name.toLowerCase() === googleStateLong.toLowerCase());
|
|
71
|
+
if (match)
|
|
72
|
+
return match;
|
|
73
|
+
// Strategy 3: Partial name matching (fallback)
|
|
74
|
+
match = regions.find((r) => r.name.toLowerCase().includes(googleStateLong.toLowerCase()) ||
|
|
75
|
+
googleStateLong.toLowerCase().includes(r.name.toLowerCase()));
|
|
76
|
+
return match ?? null;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Check if language is registered
|
|
80
|
+
*/
|
|
81
|
+
static isLanguageRegistered(language) {
|
|
82
|
+
return isLanguageRegistered(language);
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Get registered languages
|
|
86
|
+
*/
|
|
87
|
+
static getRegisteredLanguages() {
|
|
88
|
+
return getRegisteredLanguages();
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Import language data
|
|
92
|
+
*/
|
|
93
|
+
static async importLanguage(language) {
|
|
94
|
+
return importLanguage(language);
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Get available languages for ISO data
|
|
98
|
+
*/
|
|
99
|
+
static getAvailableLanguages() {
|
|
100
|
+
// Return all available languages (not just registered ones)
|
|
101
|
+
return ['en', 'ru', 'de', 'fr', 'es', 'zh', 'hi', 'pt', 'ja', 'ar', 'it', 'he'];
|
|
102
|
+
}
|
|
103
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Base API Client using Axios
|
|
3
|
+
* Shared between all resource clients
|
|
4
|
+
*/
|
|
5
|
+
import { AxiosInstance, AxiosRequestConfig } from 'axios';
|
|
6
|
+
export interface ApiClientConfig {
|
|
7
|
+
baseURL: string;
|
|
8
|
+
headers?: Record<string, string>;
|
|
9
|
+
timeout?: number;
|
|
10
|
+
}
|
|
11
|
+
export declare class ApiClient {
|
|
12
|
+
axios: AxiosInstance;
|
|
13
|
+
private currentToken;
|
|
14
|
+
constructor(config: ApiClientConfig);
|
|
15
|
+
get<T = unknown>(url: string, config?: AxiosRequestConfig): Promise<T>;
|
|
16
|
+
post<T = unknown>(url: string, data?: unknown, config?: AxiosRequestConfig): Promise<T>;
|
|
17
|
+
put<T = unknown>(url: string, data?: unknown, config?: AxiosRequestConfig): Promise<T>;
|
|
18
|
+
patch<T = unknown>(url: string, data?: unknown, config?: AxiosRequestConfig): Promise<T>;
|
|
19
|
+
delete<T = unknown>(url: string, config?: AxiosRequestConfig): Promise<T>;
|
|
20
|
+
setHeader(key: string, value: string): void;
|
|
21
|
+
removeHeader(key: string): void;
|
|
22
|
+
updateToken(token: string | null): void;
|
|
23
|
+
getCurrentToken(): string | null;
|
|
24
|
+
updateConfig(config: Partial<ApiClientConfig>): void;
|
|
25
|
+
}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Base API Client using Axios
|
|
3
|
+
* Shared between all resource clients
|
|
4
|
+
*/
|
|
5
|
+
import axios from 'axios';
|
|
6
|
+
export class ApiClient {
|
|
7
|
+
constructor(config) {
|
|
8
|
+
this.currentToken = null;
|
|
9
|
+
this.axios = axios.create({
|
|
10
|
+
baseURL: config.baseURL,
|
|
11
|
+
timeout: config.timeout || 30000,
|
|
12
|
+
headers: {
|
|
13
|
+
'Content-Type': 'application/json',
|
|
14
|
+
...config.headers,
|
|
15
|
+
},
|
|
16
|
+
});
|
|
17
|
+
// Request interceptor for logging and auth
|
|
18
|
+
this.axios.interceptors.request.use((config) => {
|
|
19
|
+
console.log(`[SDK] Making ${config.method?.toUpperCase()} request to: ${config.baseURL}${config.url}`);
|
|
20
|
+
console.log('[SDK] Request headers:', config.headers);
|
|
21
|
+
if (config.data) {
|
|
22
|
+
console.log('[SDK] Request body:', config.data);
|
|
23
|
+
}
|
|
24
|
+
return config;
|
|
25
|
+
}, (error) => {
|
|
26
|
+
console.error('[SDK] Request error:', error);
|
|
27
|
+
return Promise.reject(error instanceof Error ? error : new Error(String(error)));
|
|
28
|
+
});
|
|
29
|
+
// Response interceptor for logging
|
|
30
|
+
this.axios.interceptors.response.use((response) => {
|
|
31
|
+
console.log('[SDK] Response status:', response.status);
|
|
32
|
+
console.log('[SDK] Response data:', response.data);
|
|
33
|
+
return response;
|
|
34
|
+
}, (error) => {
|
|
35
|
+
console.error('[SDK] Response error:', error);
|
|
36
|
+
return Promise.reject(error instanceof Error ? error : new Error(String(error)));
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
// Convenience methods
|
|
40
|
+
async get(url, config) {
|
|
41
|
+
const response = await this.axios.get(url, config);
|
|
42
|
+
return response.data;
|
|
43
|
+
}
|
|
44
|
+
async post(url, data, config) {
|
|
45
|
+
const response = await this.axios.post(url, data, config);
|
|
46
|
+
return response.data;
|
|
47
|
+
}
|
|
48
|
+
async put(url, data, config) {
|
|
49
|
+
const response = await this.axios.put(url, data, config);
|
|
50
|
+
return response.data;
|
|
51
|
+
}
|
|
52
|
+
async patch(url, data, config) {
|
|
53
|
+
const response = await this.axios.patch(url, data, config);
|
|
54
|
+
return response.data;
|
|
55
|
+
}
|
|
56
|
+
async delete(url, config) {
|
|
57
|
+
const response = await this.axios.delete(url, config);
|
|
58
|
+
return response.data;
|
|
59
|
+
}
|
|
60
|
+
// Update headers (useful for auth tokens)
|
|
61
|
+
setHeader(key, value) {
|
|
62
|
+
this.axios.defaults.headers.common[key] = value;
|
|
63
|
+
}
|
|
64
|
+
removeHeader(key) {
|
|
65
|
+
delete this.axios.defaults.headers.common[key];
|
|
66
|
+
}
|
|
67
|
+
// Token management methods (matching old ApiService pattern)
|
|
68
|
+
updateToken(token) {
|
|
69
|
+
this.currentToken = token;
|
|
70
|
+
if (token) {
|
|
71
|
+
this.setHeader('x-cms-token', token);
|
|
72
|
+
console.log('[SDK] Token updated in ApiClient:', token.substring(0, 8) + '...');
|
|
73
|
+
}
|
|
74
|
+
else {
|
|
75
|
+
this.removeHeader('x-cms-token');
|
|
76
|
+
console.log('[SDK] Token removed from ApiClient');
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
getCurrentToken() {
|
|
80
|
+
return this.currentToken;
|
|
81
|
+
}
|
|
82
|
+
// Update configuration (useful for environment changes)
|
|
83
|
+
updateConfig(config) {
|
|
84
|
+
if (config.baseURL) {
|
|
85
|
+
this.axios.defaults.baseURL = config.baseURL;
|
|
86
|
+
}
|
|
87
|
+
if (config.timeout) {
|
|
88
|
+
this.axios.defaults.timeout = config.timeout;
|
|
89
|
+
}
|
|
90
|
+
if (config.headers) {
|
|
91
|
+
Object.assign(this.axios.defaults.headers.common, config.headers);
|
|
92
|
+
}
|
|
93
|
+
console.log('[SDK] ApiClient configuration updated');
|
|
94
|
+
}
|
|
95
|
+
}
|
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Checkout Resource Client
|
|
3
|
+
* Axios-based API client for checkout endpoints
|
|
4
|
+
*/
|
|
5
|
+
import { ApiClient } from './apiClient';
|
|
6
|
+
export interface CheckoutLineItem {
|
|
7
|
+
externalProductId?: string | null;
|
|
8
|
+
externalVariantId?: string | null;
|
|
9
|
+
variantId?: string | null;
|
|
10
|
+
priceId?: string | null;
|
|
11
|
+
quantity: number;
|
|
12
|
+
}
|
|
13
|
+
export interface CheckoutInitParams {
|
|
14
|
+
lineItems: CheckoutLineItem[];
|
|
15
|
+
cartToken?: string;
|
|
16
|
+
promotionIds?: string[];
|
|
17
|
+
returnUrl?: string;
|
|
18
|
+
draft?: boolean;
|
|
19
|
+
useCustomDomain?: boolean;
|
|
20
|
+
customerMetadata?: Record<string, unknown>;
|
|
21
|
+
metadata?: Record<string, unknown>;
|
|
22
|
+
storeId?: string;
|
|
23
|
+
customer?: {
|
|
24
|
+
currency?: string;
|
|
25
|
+
locale?: string;
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
export interface CheckoutSession {
|
|
29
|
+
id: string;
|
|
30
|
+
checkoutToken: string;
|
|
31
|
+
status: string;
|
|
32
|
+
storeId: string;
|
|
33
|
+
accountId: string;
|
|
34
|
+
customerId: string;
|
|
35
|
+
draft: boolean;
|
|
36
|
+
createdAt: string;
|
|
37
|
+
updatedAt: string;
|
|
38
|
+
lastActiveDate: string;
|
|
39
|
+
selectedPresentmentCurrency: string;
|
|
40
|
+
[key: string]: any;
|
|
41
|
+
}
|
|
42
|
+
export interface CheckoutData {
|
|
43
|
+
checkoutSession: CheckoutSession;
|
|
44
|
+
customerIsClubMember: boolean;
|
|
45
|
+
clubProductId?: string;
|
|
46
|
+
summary: any;
|
|
47
|
+
availablePromotions: any[];
|
|
48
|
+
}
|
|
49
|
+
export interface Promotion {
|
|
50
|
+
id: string;
|
|
51
|
+
name: string;
|
|
52
|
+
description: string | null;
|
|
53
|
+
type: string;
|
|
54
|
+
rules: any[];
|
|
55
|
+
actions: any[];
|
|
56
|
+
}
|
|
57
|
+
export declare class CheckoutResource {
|
|
58
|
+
private apiClient;
|
|
59
|
+
constructor(apiClient: ApiClient);
|
|
60
|
+
/**
|
|
61
|
+
* Initialize a new checkout session
|
|
62
|
+
*/
|
|
63
|
+
initCheckout(params: CheckoutInitParams): Promise<{
|
|
64
|
+
checkoutUrl: string;
|
|
65
|
+
checkoutSession: CheckoutSession;
|
|
66
|
+
checkoutToken: string;
|
|
67
|
+
}>;
|
|
68
|
+
/**
|
|
69
|
+
* Get checkout session by token
|
|
70
|
+
*/
|
|
71
|
+
getCheckout(checkoutToken: string, currency?: string): Promise<CheckoutData>;
|
|
72
|
+
/**
|
|
73
|
+
* Update checkout address
|
|
74
|
+
*/
|
|
75
|
+
updateAddress(checkoutSessionId: string, data: {
|
|
76
|
+
shippingAddress: any;
|
|
77
|
+
billingAddress?: any;
|
|
78
|
+
}): Promise<{
|
|
79
|
+
success: boolean;
|
|
80
|
+
errors?: Record<string, {
|
|
81
|
+
message: string;
|
|
82
|
+
type: string;
|
|
83
|
+
}>;
|
|
84
|
+
shippingCountryChanged: boolean;
|
|
85
|
+
billingCountryChanged: boolean;
|
|
86
|
+
}>;
|
|
87
|
+
/**
|
|
88
|
+
* Set checkout info
|
|
89
|
+
*/
|
|
90
|
+
setCheckoutInfo(checkoutSessionId: string, data: {
|
|
91
|
+
shippingAddress: any;
|
|
92
|
+
billingAddress?: any;
|
|
93
|
+
differentBillingAddress?: boolean;
|
|
94
|
+
}): Promise<{
|
|
95
|
+
success: boolean;
|
|
96
|
+
errors?: Record<string, {
|
|
97
|
+
message: string;
|
|
98
|
+
type: string;
|
|
99
|
+
}>;
|
|
100
|
+
shippingCountryChanged?: boolean;
|
|
101
|
+
billingCountryChanged?: boolean;
|
|
102
|
+
}>;
|
|
103
|
+
/**
|
|
104
|
+
* Apply promotion code
|
|
105
|
+
*/
|
|
106
|
+
applyPromotionCode(checkoutSessionId: string, code: string): Promise<{
|
|
107
|
+
success: boolean;
|
|
108
|
+
error?: any;
|
|
109
|
+
}>;
|
|
110
|
+
/**
|
|
111
|
+
* Remove promotion
|
|
112
|
+
*/
|
|
113
|
+
removePromotion(checkoutSessionId: string, promotionId: string): Promise<{
|
|
114
|
+
success: boolean;
|
|
115
|
+
error?: any;
|
|
116
|
+
}>;
|
|
117
|
+
/**
|
|
118
|
+
* Get applied promotions
|
|
119
|
+
*/
|
|
120
|
+
getAppliedPromotions(checkoutSessionId: string): Promise<Promotion[]>;
|
|
121
|
+
/**
|
|
122
|
+
* Update line items
|
|
123
|
+
*/
|
|
124
|
+
updateLineItems(checkoutSessionId: string, lineItems: CheckoutLineItem[]): Promise<{
|
|
125
|
+
success: boolean;
|
|
126
|
+
error?: any;
|
|
127
|
+
}>;
|
|
128
|
+
/**
|
|
129
|
+
* Add line items
|
|
130
|
+
*/
|
|
131
|
+
addLineItems(checkoutSessionId: string, lineItems: CheckoutLineItem[]): Promise<{
|
|
132
|
+
success: boolean;
|
|
133
|
+
error?: any;
|
|
134
|
+
}>;
|
|
135
|
+
/**
|
|
136
|
+
* Remove line items
|
|
137
|
+
*/
|
|
138
|
+
removeLineItems(checkoutSessionId: string, lineItems: {
|
|
139
|
+
variantId: string;
|
|
140
|
+
quantity?: number;
|
|
141
|
+
}[]): Promise<{
|
|
142
|
+
success: boolean;
|
|
143
|
+
error?: any;
|
|
144
|
+
}>;
|
|
145
|
+
/**
|
|
146
|
+
* Set item quantity
|
|
147
|
+
*/
|
|
148
|
+
setItemQuantity(checkoutSessionId: string, variantId: string, quantity: number, priceId?: string): Promise<{
|
|
149
|
+
success: boolean;
|
|
150
|
+
error?: any;
|
|
151
|
+
}>;
|
|
152
|
+
/**
|
|
153
|
+
* Toggle order bump
|
|
154
|
+
*/
|
|
155
|
+
toggleOrderBump(checkoutSessionId: string, orderBumpOfferId: string, selected: boolean): Promise<{
|
|
156
|
+
success: boolean;
|
|
157
|
+
error?: any;
|
|
158
|
+
}>;
|
|
159
|
+
/**
|
|
160
|
+
* Update customer
|
|
161
|
+
*/
|
|
162
|
+
updateCustomer(checkoutSessionId: string, data: {
|
|
163
|
+
email: string;
|
|
164
|
+
acceptsMarketing?: boolean;
|
|
165
|
+
}): Promise<{
|
|
166
|
+
success: boolean;
|
|
167
|
+
error?: any;
|
|
168
|
+
}>;
|
|
169
|
+
/**
|
|
170
|
+
* Update customer and session info
|
|
171
|
+
*/
|
|
172
|
+
updateCustomerAndSessionInfo(checkoutSessionId: string, data: {
|
|
173
|
+
customerData: {
|
|
174
|
+
email: string;
|
|
175
|
+
acceptsMarketing?: boolean;
|
|
176
|
+
};
|
|
177
|
+
shippingAddress: any;
|
|
178
|
+
billingAddress?: any;
|
|
179
|
+
differentBillingAddress?: boolean;
|
|
180
|
+
}): Promise<{
|
|
181
|
+
success: boolean;
|
|
182
|
+
errors?: Record<string, {
|
|
183
|
+
message: string;
|
|
184
|
+
type: string;
|
|
185
|
+
}>;
|
|
186
|
+
shippingCountryChanged?: boolean;
|
|
187
|
+
billingCountryChanged?: boolean;
|
|
188
|
+
}>;
|
|
189
|
+
}
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Checkout Resource Client
|
|
3
|
+
* Axios-based API client for checkout endpoints
|
|
4
|
+
*/
|
|
5
|
+
export class CheckoutResource {
|
|
6
|
+
constructor(apiClient) {
|
|
7
|
+
this.apiClient = apiClient;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Initialize a new checkout session
|
|
11
|
+
*/
|
|
12
|
+
async initCheckout(params) {
|
|
13
|
+
return this.apiClient.post('/api/v1/checkout/session/init', params);
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Get checkout session by token
|
|
17
|
+
*/
|
|
18
|
+
async getCheckout(checkoutToken, currency) {
|
|
19
|
+
const queryParams = new URLSearchParams();
|
|
20
|
+
if (currency) {
|
|
21
|
+
queryParams.set('currency', currency);
|
|
22
|
+
}
|
|
23
|
+
const url = `/api/v1/checkout-sessions/${checkoutToken}/v2${queryParams.toString() ? `?${queryParams.toString()}` : ''}`;
|
|
24
|
+
return this.apiClient.get(url);
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Update checkout address
|
|
28
|
+
*/
|
|
29
|
+
async updateAddress(checkoutSessionId, data) {
|
|
30
|
+
return this.apiClient.post(`/api/v1/checkout-sessions/${checkoutSessionId}/address`, {
|
|
31
|
+
data,
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Set checkout info
|
|
36
|
+
*/
|
|
37
|
+
async setCheckoutInfo(checkoutSessionId, data) {
|
|
38
|
+
return this.apiClient.post(`/api/v1/checkout-sessions/${checkoutSessionId}/checkout-info`, {
|
|
39
|
+
shippingAddress: data.shippingAddress,
|
|
40
|
+
billingAddress: data.differentBillingAddress ? data.billingAddress : data.shippingAddress,
|
|
41
|
+
differentBillingAddress: data.differentBillingAddress || false,
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Apply promotion code
|
|
46
|
+
*/
|
|
47
|
+
async applyPromotionCode(checkoutSessionId, code) {
|
|
48
|
+
return this.apiClient.post(`/api/v1/checkout-sessions/${checkoutSessionId}/promotions/apply`, {
|
|
49
|
+
code,
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Remove promotion
|
|
54
|
+
*/
|
|
55
|
+
async removePromotion(checkoutSessionId, promotionId) {
|
|
56
|
+
return this.apiClient.delete(`/api/v1/checkout-sessions/${checkoutSessionId}/promotions/${promotionId}`);
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Get applied promotions
|
|
60
|
+
*/
|
|
61
|
+
async getAppliedPromotions(checkoutSessionId) {
|
|
62
|
+
return this.apiClient.get(`/api/v1/checkout-sessions/${checkoutSessionId}/promotions`);
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Update line items
|
|
66
|
+
*/
|
|
67
|
+
async updateLineItems(checkoutSessionId, lineItems) {
|
|
68
|
+
return this.apiClient.post(`/api/v1/checkout-sessions/${checkoutSessionId}/line-items`, {
|
|
69
|
+
lineItems,
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Add line items
|
|
74
|
+
*/
|
|
75
|
+
async addLineItems(checkoutSessionId, lineItems) {
|
|
76
|
+
return this.apiClient.post(`/api/v1/checkout-sessions/${checkoutSessionId}/line-items/add`, {
|
|
77
|
+
lineItems,
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Remove line items
|
|
82
|
+
*/
|
|
83
|
+
async removeLineItems(checkoutSessionId, lineItems) {
|
|
84
|
+
return this.apiClient.post(`/api/v1/checkout-sessions/${checkoutSessionId}/line-items/remove`, {
|
|
85
|
+
lineItems,
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Set item quantity
|
|
90
|
+
*/
|
|
91
|
+
async setItemQuantity(checkoutSessionId, variantId, quantity, priceId) {
|
|
92
|
+
return this.apiClient.post(`/api/v1/checkout-sessions/${checkoutSessionId}/line-items/set-quantity`, {
|
|
93
|
+
variantId,
|
|
94
|
+
quantity,
|
|
95
|
+
priceId,
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Toggle order bump
|
|
100
|
+
*/
|
|
101
|
+
async toggleOrderBump(checkoutSessionId, orderBumpOfferId, selected) {
|
|
102
|
+
return this.apiClient.post(`/api/v1/checkout-sessions/${checkoutSessionId}/toggle-order-bump`, {
|
|
103
|
+
orderBumpOfferId,
|
|
104
|
+
selected,
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Update customer
|
|
109
|
+
*/
|
|
110
|
+
async updateCustomer(checkoutSessionId, data) {
|
|
111
|
+
return this.apiClient.post(`/api/v1/checkout-sessions/${checkoutSessionId}/customer`, data);
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Update customer and session info
|
|
115
|
+
*/
|
|
116
|
+
async updateCustomerAndSessionInfo(checkoutSessionId, data) {
|
|
117
|
+
return this.apiClient.post(`/api/v1/checkout-sessions/${checkoutSessionId}/customer-and-session-info`, data);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Resource Clients
|
|
3
|
+
* Axios-based API clients for all endpoints
|
|
4
|
+
*/
|
|
5
|
+
export * from './apiClient';
|
|
6
|
+
export * from './products';
|
|
7
|
+
export * from './orders';
|
|
8
|
+
export * from './payments';
|
|
9
|
+
export * from './checkout';
|
|
10
|
+
export * from './promotions';
|
|
11
|
+
export * from './postPurchases';
|
|
12
|
+
export * from './offers';
|
|
13
|
+
export * from './threeds';
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Resource Clients
|
|
3
|
+
* Axios-based API clients for all endpoints
|
|
4
|
+
*/
|
|
5
|
+
export * from './apiClient';
|
|
6
|
+
export * from './products';
|
|
7
|
+
export * from './orders';
|
|
8
|
+
export * from './payments';
|
|
9
|
+
export * from './checkout';
|
|
10
|
+
export * from './promotions';
|
|
11
|
+
export * from './postPurchases';
|
|
12
|
+
export * from './offers';
|
|
13
|
+
export * from './threeds';
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Offers Resource Client
|
|
3
|
+
* Axios-based API client for offers endpoints
|
|
4
|
+
*/
|
|
5
|
+
import { ApiClient } from './apiClient';
|
|
6
|
+
export interface OfferItem {
|
|
7
|
+
id: string;
|
|
8
|
+
product: {
|
|
9
|
+
name: string;
|
|
10
|
+
description: string;
|
|
11
|
+
};
|
|
12
|
+
variant: {
|
|
13
|
+
name: string;
|
|
14
|
+
imageUrl: string;
|
|
15
|
+
};
|
|
16
|
+
quantity: number;
|
|
17
|
+
unitAmount: number;
|
|
18
|
+
amount: number;
|
|
19
|
+
adjustedAmount: number;
|
|
20
|
+
currency: string;
|
|
21
|
+
}
|
|
22
|
+
export interface OfferSummary {
|
|
23
|
+
items: OfferItem[];
|
|
24
|
+
totalAmount: number;
|
|
25
|
+
totalAdjustedAmount: number;
|
|
26
|
+
totalPromotionAmount: number;
|
|
27
|
+
currency: string;
|
|
28
|
+
adjustments: {
|
|
29
|
+
type: string;
|
|
30
|
+
description: string;
|
|
31
|
+
amount: number;
|
|
32
|
+
}[];
|
|
33
|
+
}
|
|
34
|
+
import type { CurrencyOptions, VariantOption, OrderSummaryItem, OrderSummary, CheckoutSessionState } from './postPurchases';
|
|
35
|
+
export type { CurrencyOptions, VariantOption, OrderSummaryItem, OrderSummary, CheckoutSessionState };
|
|
36
|
+
export interface Offer {
|
|
37
|
+
id: string;
|
|
38
|
+
titleTrans: Record<string, string>;
|
|
39
|
+
summaries: OfferSummary[];
|
|
40
|
+
}
|
|
41
|
+
export declare class OffersResource {
|
|
42
|
+
private apiClient;
|
|
43
|
+
constructor(apiClient: ApiClient);
|
|
44
|
+
/**
|
|
45
|
+
* Get offers for a store
|
|
46
|
+
*/
|
|
47
|
+
getOffers(storeId: string): Promise<Offer[]>;
|
|
48
|
+
/**
|
|
49
|
+
* Get offers by IDs
|
|
50
|
+
*/
|
|
51
|
+
getOffersByIds(storeId: string, offerIds: string[]): Promise<Offer[]>;
|
|
52
|
+
/**
|
|
53
|
+
* Initialize checkout session for an offer
|
|
54
|
+
*/
|
|
55
|
+
initCheckoutSession(offerId: string, orderId: string, customerId?: string): Promise<{
|
|
56
|
+
checkoutSessionId: string;
|
|
57
|
+
}>;
|
|
58
|
+
/**
|
|
59
|
+
* Create checkout session for an offer
|
|
60
|
+
*/
|
|
61
|
+
createCheckoutSession(offerId: string, returnUrl?: string): Promise<{
|
|
62
|
+
checkoutUrl: string;
|
|
63
|
+
}>;
|
|
64
|
+
/**
|
|
65
|
+
* Pay with checkout session
|
|
66
|
+
*/
|
|
67
|
+
payWithCheckoutSession(checkoutSessionId: string, orderId?: string): Promise<void>;
|
|
68
|
+
/**
|
|
69
|
+
* Pay for an offer directly
|
|
70
|
+
*/
|
|
71
|
+
payOffer(offerId: string, orderId?: string): Promise<any>;
|
|
72
|
+
/**
|
|
73
|
+
* Transform offer to checkout session with dynamic variant selection
|
|
74
|
+
*/
|
|
75
|
+
transformToCheckout(offerId: string, returnUrl?: string): Promise<{
|
|
76
|
+
checkoutUrl: string;
|
|
77
|
+
}>;
|
|
78
|
+
/**
|
|
79
|
+
* Initialize checkout session for an offer with variants (similar to postPurchases)
|
|
80
|
+
*/
|
|
81
|
+
initCheckoutSessionWithVariants(offerId: string, lineItems: {
|
|
82
|
+
variantId: string;
|
|
83
|
+
quantity: number;
|
|
84
|
+
}[], returnUrl?: string): Promise<{
|
|
85
|
+
checkoutSessionId: string;
|
|
86
|
+
}>;
|
|
87
|
+
/**
|
|
88
|
+
* Get order summary for a checkout session
|
|
89
|
+
*/
|
|
90
|
+
getOrderSummary(sessionId: string, includeVariantOptions?: boolean): Promise<any>;
|
|
91
|
+
/**
|
|
92
|
+
* Update line items for a checkout session
|
|
93
|
+
*/
|
|
94
|
+
updateLineItems(sessionId: string, lineItems: {
|
|
95
|
+
variantId: string;
|
|
96
|
+
quantity: number;
|
|
97
|
+
}[]): Promise<any>;
|
|
98
|
+
}
|