@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.
- 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 +194 -0
- package/dist/v2/react/hooks/useCheckoutToken.d.ts +17 -0
- package/dist/v2/react/hooks/useCheckoutToken.js +65 -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 +123 -0
- package/dist/v2/react/hooks/useGoogleAutocomplete.d.ts +74 -0
- package/dist/v2/react/hooks/useGoogleAutocomplete.js +196 -0
- package/dist/v2/react/hooks/useISOData.d.ts +61 -0
- package/dist/v2/react/hooks/useISOData.js +175 -0
- package/dist/v2/react/hooks/useOffersQuery.d.ts +65 -0
- package/dist/v2/react/hooks/useOffersQuery.js +342 -0
- package/dist/v2/react/hooks/useOrderBumpQuery.d.ts +20 -0
- package/dist/v2/react/hooks/useOrderBumpQuery.js +92 -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 +140 -0
- package/dist/v2/react/hooks/usePaymentQuery.d.ts +19 -0
- package/dist/v2/react/hooks/usePaymentQuery.js +272 -0
- package/dist/v2/react/hooks/usePluginConfig.d.ts +16 -0
- package/dist/v2/react/hooks/usePluginConfig.js +35 -0
- package/dist/v2/react/hooks/usePostPurchasesQuery.d.ts +63 -0
- package/dist/v2/react/hooks/usePostPurchasesQuery.js +343 -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 +150 -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,87 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Promotions Resource Client
|
|
3
|
+
* Axios-based API client for promotion endpoints
|
|
4
|
+
*/
|
|
5
|
+
export class PromotionsResource {
|
|
6
|
+
constructor(apiClient) {
|
|
7
|
+
this.apiClient = apiClient;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Get applied promotions for a checkout session
|
|
11
|
+
*/
|
|
12
|
+
async getAppliedPromotions(checkoutSessionId) {
|
|
13
|
+
return this.apiClient.get(`/api/v1/checkout-sessions/${checkoutSessionId}/promotions`);
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Apply a promotion code to a checkout session
|
|
17
|
+
*/
|
|
18
|
+
async applyPromotionCode(checkoutSessionId, code) {
|
|
19
|
+
try {
|
|
20
|
+
const response = await this.apiClient.post(`/api/v1/checkout-sessions/${checkoutSessionId}/promotions/apply`, { code: code.trim() });
|
|
21
|
+
if (response.success) {
|
|
22
|
+
return { success: true, promotion: response.promotion };
|
|
23
|
+
}
|
|
24
|
+
else {
|
|
25
|
+
return { success: false, error: response.error?.message || 'Failed to apply promotion code' };
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
catch (err) {
|
|
29
|
+
// Try to extract error message from API response
|
|
30
|
+
let errorMessage = 'Failed to apply promotion code';
|
|
31
|
+
if (err && typeof err === 'object' && 'response' in err) {
|
|
32
|
+
const apiError = err;
|
|
33
|
+
if (apiError.response?.data?.error?.message) {
|
|
34
|
+
errorMessage = apiError.response.data.error.message;
|
|
35
|
+
}
|
|
36
|
+
else if (apiError.response?.data?.message) {
|
|
37
|
+
errorMessage = apiError.response.data.message;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
return { success: false, error: errorMessage };
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Remove a promotion from a checkout session
|
|
45
|
+
*/
|
|
46
|
+
async removePromotionCode(checkoutSessionId, promotionId) {
|
|
47
|
+
try {
|
|
48
|
+
const response = await this.apiClient.delete(`/api/v1/checkout-sessions/${checkoutSessionId}/promotions/${promotionId}`);
|
|
49
|
+
if (response.success) {
|
|
50
|
+
return { success: true };
|
|
51
|
+
}
|
|
52
|
+
else {
|
|
53
|
+
return { success: false, error: response.error?.message || 'Failed to remove promotion' };
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
catch (err) {
|
|
57
|
+
// Try to extract error message from API response
|
|
58
|
+
let errorMessage = 'Failed to remove promotion';
|
|
59
|
+
if (err && typeof err === 'object' && 'response' in err) {
|
|
60
|
+
const apiError = err;
|
|
61
|
+
if (apiError.response?.data?.error?.message) {
|
|
62
|
+
errorMessage = apiError.response.data.error.message;
|
|
63
|
+
}
|
|
64
|
+
else if (apiError.response?.data?.message) {
|
|
65
|
+
errorMessage = apiError.response.data.message;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
return { success: false, error: errorMessage };
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Validate a promotion code without applying it
|
|
73
|
+
*/
|
|
74
|
+
async validatePromotionCode(checkoutSessionId, code) {
|
|
75
|
+
try {
|
|
76
|
+
const response = await this.apiClient.post(`/api/v1/checkout-sessions/${checkoutSessionId}/promotions/validate`, { code: code.trim() });
|
|
77
|
+
return response;
|
|
78
|
+
}
|
|
79
|
+
catch {
|
|
80
|
+
return {
|
|
81
|
+
isValid: false,
|
|
82
|
+
code: code.trim(),
|
|
83
|
+
error: 'Failed to validate promotion code',
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Threeds Resource Client
|
|
3
|
+
* Axios-based API client for 3DS endpoints
|
|
4
|
+
*/
|
|
5
|
+
import { ApiClient } from './apiClient';
|
|
6
|
+
export interface ThreedsSession {
|
|
7
|
+
id: string;
|
|
8
|
+
sessionId: string;
|
|
9
|
+
provider: string;
|
|
10
|
+
}
|
|
11
|
+
export interface CreateSessionRequest {
|
|
12
|
+
provider: string;
|
|
13
|
+
sessionData: any;
|
|
14
|
+
paymentInstrumentId: string;
|
|
15
|
+
}
|
|
16
|
+
export declare class ThreedsResource {
|
|
17
|
+
private apiClient;
|
|
18
|
+
constructor(apiClient: ApiClient);
|
|
19
|
+
/**
|
|
20
|
+
* Create a 3DS session
|
|
21
|
+
*/
|
|
22
|
+
createSession(request: CreateSessionRequest): Promise<ThreedsSession>;
|
|
23
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Threeds Resource Client
|
|
3
|
+
* Axios-based API client for 3DS endpoints
|
|
4
|
+
*/
|
|
5
|
+
export class ThreedsResource {
|
|
6
|
+
constructor(apiClient) {
|
|
7
|
+
this.apiClient = apiClient;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Create a 3DS session
|
|
11
|
+
*/
|
|
12
|
+
async createSession(request) {
|
|
13
|
+
return this.apiClient.post('/api/v1/threeds/create-session', request);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Checkout Utility Functions
|
|
3
|
+
* Pure functions for checkout data manipulation
|
|
4
|
+
*/
|
|
5
|
+
import type { CheckoutData, CheckoutSession, CheckoutLineItem, CheckoutInitParams, Promotion } from '../resources/checkout';
|
|
6
|
+
export type { CheckoutData, CheckoutSession, CheckoutLineItem, CheckoutInitParams, Promotion, };
|
|
7
|
+
export declare class CheckoutUtils {
|
|
8
|
+
/**
|
|
9
|
+
* Get checkout session ID
|
|
10
|
+
*/
|
|
11
|
+
static getCheckoutSessionId(checkoutData: CheckoutData): string;
|
|
12
|
+
/**
|
|
13
|
+
* Get checkout line items
|
|
14
|
+
*/
|
|
15
|
+
static getLineItems(checkoutData: CheckoutData): CheckoutLineItem[];
|
|
16
|
+
/**
|
|
17
|
+
* Get checkout total
|
|
18
|
+
*/
|
|
19
|
+
static getTotal(checkoutData: CheckoutData): number;
|
|
20
|
+
/**
|
|
21
|
+
* Check if customer is club member
|
|
22
|
+
*/
|
|
23
|
+
static isClubMember(checkoutData: CheckoutData): boolean;
|
|
24
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Checkout Utility Functions
|
|
3
|
+
* Pure functions for checkout data manipulation
|
|
4
|
+
*/
|
|
5
|
+
export class CheckoutUtils {
|
|
6
|
+
/**
|
|
7
|
+
* Get checkout session ID
|
|
8
|
+
*/
|
|
9
|
+
static getCheckoutSessionId(checkoutData) {
|
|
10
|
+
return checkoutData.checkoutSession?.id || '';
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Get checkout line items
|
|
14
|
+
*/
|
|
15
|
+
static getLineItems(checkoutData) {
|
|
16
|
+
return checkoutData.checkoutSession?.lineItems || [];
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Get checkout total
|
|
20
|
+
*/
|
|
21
|
+
static getTotal(checkoutData) {
|
|
22
|
+
return checkoutData.checkoutSession?.totalPrice || 0;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Check if customer is club member
|
|
26
|
+
*/
|
|
27
|
+
static isClubMember(checkoutData) {
|
|
28
|
+
return checkoutData.customerIsClubMember || false;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Currency Utility Functions
|
|
3
|
+
* Pure functions for currency management
|
|
4
|
+
*/
|
|
5
|
+
export interface Currency {
|
|
6
|
+
code: string;
|
|
7
|
+
symbol: string;
|
|
8
|
+
name: string;
|
|
9
|
+
decimalPlaces: number;
|
|
10
|
+
}
|
|
11
|
+
export declare class CurrencyUtils {
|
|
12
|
+
/**
|
|
13
|
+
* Get currency from context or fallback to default
|
|
14
|
+
*/
|
|
15
|
+
static getCurrency(context: any, defaultCurrency?: string): Currency;
|
|
16
|
+
/**
|
|
17
|
+
* Get currency symbol
|
|
18
|
+
*/
|
|
19
|
+
static getCurrencySymbol(code: string): string;
|
|
20
|
+
/**
|
|
21
|
+
* Get currency name
|
|
22
|
+
*/
|
|
23
|
+
static getCurrencyName(code: string): string;
|
|
24
|
+
/**
|
|
25
|
+
* Get decimal places for currency
|
|
26
|
+
*/
|
|
27
|
+
static getDecimalPlaces(code: string): number;
|
|
28
|
+
}
|
|
@@ -0,0 +1,272 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Currency Utility Functions
|
|
3
|
+
* Pure functions for currency management
|
|
4
|
+
*/
|
|
5
|
+
export class CurrencyUtils {
|
|
6
|
+
/**
|
|
7
|
+
* Get currency from context or fallback to default
|
|
8
|
+
*/
|
|
9
|
+
static getCurrency(context, defaultCurrency = 'USD') {
|
|
10
|
+
// Handle case where context.currency might be a Currency object or string
|
|
11
|
+
let currencyCode;
|
|
12
|
+
if (typeof context?.currency === 'string') {
|
|
13
|
+
currencyCode = context.currency;
|
|
14
|
+
}
|
|
15
|
+
else if (context?.currency?.code) {
|
|
16
|
+
currencyCode = context.currency.code;
|
|
17
|
+
}
|
|
18
|
+
else if (context?.store?.presentmentCurrencies?.[0]) {
|
|
19
|
+
currencyCode = context.store.presentmentCurrencies[0];
|
|
20
|
+
}
|
|
21
|
+
else {
|
|
22
|
+
currencyCode = defaultCurrency;
|
|
23
|
+
}
|
|
24
|
+
return {
|
|
25
|
+
code: currencyCode,
|
|
26
|
+
symbol: this.getCurrencySymbol(currencyCode),
|
|
27
|
+
name: this.getCurrencyName(currencyCode),
|
|
28
|
+
decimalPlaces: this.getDecimalPlaces(currencyCode),
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Get currency symbol
|
|
33
|
+
*/
|
|
34
|
+
static getCurrencySymbol(code) {
|
|
35
|
+
const symbols = {
|
|
36
|
+
USD: '$',
|
|
37
|
+
EUR: '€',
|
|
38
|
+
GBP: '£',
|
|
39
|
+
JPY: '¥',
|
|
40
|
+
CAD: 'C$',
|
|
41
|
+
AUD: 'A$',
|
|
42
|
+
CHF: 'CHF',
|
|
43
|
+
CNY: '¥',
|
|
44
|
+
SEK: 'kr',
|
|
45
|
+
NOK: 'kr',
|
|
46
|
+
DKK: 'kr',
|
|
47
|
+
PLN: 'zł',
|
|
48
|
+
CZK: 'Kč',
|
|
49
|
+
HUF: 'Ft',
|
|
50
|
+
RON: 'lei',
|
|
51
|
+
BGN: 'лв',
|
|
52
|
+
HRK: 'kn',
|
|
53
|
+
RUB: '₽',
|
|
54
|
+
UAH: '₴',
|
|
55
|
+
TRY: '₺',
|
|
56
|
+
BRL: 'R$',
|
|
57
|
+
ARS: '$',
|
|
58
|
+
CLP: '$',
|
|
59
|
+
COP: '$',
|
|
60
|
+
MXN: '$',
|
|
61
|
+
PEN: 'S/',
|
|
62
|
+
UYU: '$U',
|
|
63
|
+
VEF: 'Bs',
|
|
64
|
+
ZAR: 'R',
|
|
65
|
+
EGP: '£',
|
|
66
|
+
MAD: 'د.م.',
|
|
67
|
+
TND: 'د.ت',
|
|
68
|
+
DZD: 'د.ج',
|
|
69
|
+
LYD: 'ل.د',
|
|
70
|
+
NGN: '₦',
|
|
71
|
+
GHS: '₵',
|
|
72
|
+
KES: 'KSh',
|
|
73
|
+
UGX: 'USh',
|
|
74
|
+
TZS: 'TSh',
|
|
75
|
+
ETB: 'Br',
|
|
76
|
+
ZMW: 'ZK',
|
|
77
|
+
BWP: 'P',
|
|
78
|
+
SZL: 'L',
|
|
79
|
+
LSL: 'L',
|
|
80
|
+
NAD: 'N$',
|
|
81
|
+
MUR: '₨',
|
|
82
|
+
SCR: '₨',
|
|
83
|
+
KWD: 'د.ك',
|
|
84
|
+
BHD: 'د.ب',
|
|
85
|
+
QAR: 'ر.ق',
|
|
86
|
+
AED: 'د.إ',
|
|
87
|
+
OMR: 'ر.ع.',
|
|
88
|
+
YER: '﷼',
|
|
89
|
+
SAR: 'ر.س',
|
|
90
|
+
JOD: 'د.ا',
|
|
91
|
+
LBP: 'ل.ل',
|
|
92
|
+
ILS: '₪',
|
|
93
|
+
INR: '₹',
|
|
94
|
+
PKR: '₨',
|
|
95
|
+
BDT: '৳',
|
|
96
|
+
LKR: '₨',
|
|
97
|
+
NPR: '₨',
|
|
98
|
+
AFN: '؋',
|
|
99
|
+
KZT: '₸',
|
|
100
|
+
UZS: 'лв',
|
|
101
|
+
KGS: 'лв',
|
|
102
|
+
TJS: 'SM',
|
|
103
|
+
TMT: 'T',
|
|
104
|
+
AZN: '₼',
|
|
105
|
+
GEL: '₾',
|
|
106
|
+
AMD: '֏',
|
|
107
|
+
KRW: '₩',
|
|
108
|
+
THB: '฿',
|
|
109
|
+
VND: '₫',
|
|
110
|
+
IDR: 'Rp',
|
|
111
|
+
MYR: 'RM',
|
|
112
|
+
SGD: 'S$',
|
|
113
|
+
PHP: '₱',
|
|
114
|
+
TWD: 'NT$',
|
|
115
|
+
HKD: 'HK$',
|
|
116
|
+
MOP: 'MOP$',
|
|
117
|
+
BND: 'B$',
|
|
118
|
+
LAK: '₭',
|
|
119
|
+
KHR: '៛',
|
|
120
|
+
MMK: 'K',
|
|
121
|
+
BOB: 'Bs',
|
|
122
|
+
PYG: '₲',
|
|
123
|
+
GTQ: 'Q',
|
|
124
|
+
HNL: 'L',
|
|
125
|
+
NIO: 'C$',
|
|
126
|
+
CRC: '₡',
|
|
127
|
+
PAB: 'B/.',
|
|
128
|
+
DOP: 'RD$',
|
|
129
|
+
JMD: 'J$',
|
|
130
|
+
TTD: 'TT$',
|
|
131
|
+
BBD: 'Bds$',
|
|
132
|
+
XCD: 'EC$',
|
|
133
|
+
AWG: 'ƒ',
|
|
134
|
+
ANG: 'ƒ',
|
|
135
|
+
SRD: '$',
|
|
136
|
+
GYD: 'G$',
|
|
137
|
+
VES: 'Bs.S',
|
|
138
|
+
VED: 'Bs.D',
|
|
139
|
+
};
|
|
140
|
+
return symbols[code] || code;
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* Get currency name
|
|
144
|
+
*/
|
|
145
|
+
static getCurrencyName(code) {
|
|
146
|
+
const names = {
|
|
147
|
+
USD: 'US Dollar',
|
|
148
|
+
EUR: 'Euro',
|
|
149
|
+
GBP: 'British Pound',
|
|
150
|
+
JPY: 'Japanese Yen',
|
|
151
|
+
CAD: 'Canadian Dollar',
|
|
152
|
+
AUD: 'Australian Dollar',
|
|
153
|
+
CHF: 'Swiss Franc',
|
|
154
|
+
CNY: 'Chinese Yuan',
|
|
155
|
+
SEK: 'Swedish Krona',
|
|
156
|
+
NOK: 'Norwegian Krone',
|
|
157
|
+
DKK: 'Danish Krone',
|
|
158
|
+
PLN: 'Polish Zloty',
|
|
159
|
+
CZK: 'Czech Koruna',
|
|
160
|
+
HUF: 'Hungarian Forint',
|
|
161
|
+
RON: 'Romanian Leu',
|
|
162
|
+
BGN: 'Bulgarian Lev',
|
|
163
|
+
HRK: 'Croatian Kuna',
|
|
164
|
+
RUB: 'Russian Ruble',
|
|
165
|
+
UAH: 'Ukrainian Hryvnia',
|
|
166
|
+
TRY: 'Turkish Lira',
|
|
167
|
+
BRL: 'Brazilian Real',
|
|
168
|
+
ARS: 'Argentine Peso',
|
|
169
|
+
CLP: 'Chilean Peso',
|
|
170
|
+
COP: 'Colombian Peso',
|
|
171
|
+
MXN: 'Mexican Peso',
|
|
172
|
+
PEN: 'Peruvian Sol',
|
|
173
|
+
UYU: 'Uruguayan Peso',
|
|
174
|
+
VEF: 'Venezuelan Bolivar',
|
|
175
|
+
ZAR: 'South African Rand',
|
|
176
|
+
EGP: 'Egyptian Pound',
|
|
177
|
+
MAD: 'Moroccan Dirham',
|
|
178
|
+
TND: 'Tunisian Dinar',
|
|
179
|
+
DZD: 'Algerian Dinar',
|
|
180
|
+
LYD: 'Libyan Dinar',
|
|
181
|
+
NGN: 'Nigerian Naira',
|
|
182
|
+
GHS: 'Ghanaian Cedi',
|
|
183
|
+
KES: 'Kenyan Shilling',
|
|
184
|
+
UGX: 'Ugandan Shilling',
|
|
185
|
+
TZS: 'Tanzanian Shilling',
|
|
186
|
+
ETB: 'Ethiopian Birr',
|
|
187
|
+
ZMW: 'Zambian Kwacha',
|
|
188
|
+
BWP: 'Botswana Pula',
|
|
189
|
+
SZL: 'Swazi Lilangeni',
|
|
190
|
+
LSL: 'Lesotho Loti',
|
|
191
|
+
NAD: 'Namibian Dollar',
|
|
192
|
+
MUR: 'Mauritian Rupee',
|
|
193
|
+
SCR: 'Seychellois Rupee',
|
|
194
|
+
KWD: 'Kuwaiti Dinar',
|
|
195
|
+
BHD: 'Bahraini Dinar',
|
|
196
|
+
QAR: 'Qatari Riyal',
|
|
197
|
+
AED: 'UAE Dirham',
|
|
198
|
+
OMR: 'Omani Rial',
|
|
199
|
+
YER: 'Yemeni Rial',
|
|
200
|
+
SAR: 'Saudi Riyal',
|
|
201
|
+
JOD: 'Jordanian Dinar',
|
|
202
|
+
LBP: 'Lebanese Pound',
|
|
203
|
+
ILS: 'Israeli Shekel',
|
|
204
|
+
INR: 'Indian Rupee',
|
|
205
|
+
PKR: 'Pakistani Rupee',
|
|
206
|
+
BDT: 'Bangladeshi Taka',
|
|
207
|
+
LKR: 'Sri Lankan Rupee',
|
|
208
|
+
NPR: 'Nepalese Rupee',
|
|
209
|
+
AFN: 'Afghan Afghani',
|
|
210
|
+
KZT: 'Kazakhstani Tenge',
|
|
211
|
+
UZS: 'Uzbekistani Som',
|
|
212
|
+
KGS: 'Kyrgyzstani Som',
|
|
213
|
+
TJS: 'Tajikistani Somoni',
|
|
214
|
+
TMT: 'Turkmenistani Manat',
|
|
215
|
+
AZN: 'Azerbaijani Manat',
|
|
216
|
+
GEL: 'Georgian Lari',
|
|
217
|
+
AMD: 'Armenian Dram',
|
|
218
|
+
KRW: 'South Korean Won',
|
|
219
|
+
THB: 'Thai Baht',
|
|
220
|
+
VND: 'Vietnamese Dong',
|
|
221
|
+
IDR: 'Indonesian Rupiah',
|
|
222
|
+
MYR: 'Malaysian Ringgit',
|
|
223
|
+
SGD: 'Singapore Dollar',
|
|
224
|
+
PHP: 'Philippine Peso',
|
|
225
|
+
TWD: 'Taiwan Dollar',
|
|
226
|
+
HKD: 'Hong Kong Dollar',
|
|
227
|
+
MOP: 'Macanese Pataca',
|
|
228
|
+
BND: 'Brunei Dollar',
|
|
229
|
+
LAK: 'Lao Kip',
|
|
230
|
+
KHR: 'Cambodian Riel',
|
|
231
|
+
MMK: 'Myanmar Kyat',
|
|
232
|
+
BOB: 'Bolivian Boliviano',
|
|
233
|
+
PYG: 'Paraguayan Guarani',
|
|
234
|
+
GTQ: 'Guatemalan Quetzal',
|
|
235
|
+
HNL: 'Honduran Lempira',
|
|
236
|
+
NIO: 'Nicaraguan Cordoba',
|
|
237
|
+
CRC: 'Costa Rican Colon',
|
|
238
|
+
PAB: 'Panamanian Balboa',
|
|
239
|
+
DOP: 'Dominican Peso',
|
|
240
|
+
JMD: 'Jamaican Dollar',
|
|
241
|
+
TTD: 'Trinidad and Tobago Dollar',
|
|
242
|
+
BBD: 'Barbadian Dollar',
|
|
243
|
+
XCD: 'East Caribbean Dollar',
|
|
244
|
+
AWG: 'Aruban Florin',
|
|
245
|
+
ANG: 'Netherlands Antillean Guilder',
|
|
246
|
+
SRD: 'Surinamese Dollar',
|
|
247
|
+
GYD: 'Guyanese Dollar',
|
|
248
|
+
VES: 'Venezuelan Bolivar Soberano',
|
|
249
|
+
VED: 'Venezuelan Bolivar Digital',
|
|
250
|
+
};
|
|
251
|
+
return names[code] || code;
|
|
252
|
+
}
|
|
253
|
+
/**
|
|
254
|
+
* Get decimal places for currency
|
|
255
|
+
*/
|
|
256
|
+
static getDecimalPlaces(code) {
|
|
257
|
+
const decimalPlaces = {
|
|
258
|
+
JPY: 0,
|
|
259
|
+
KRW: 0,
|
|
260
|
+
VND: 0,
|
|
261
|
+
IDR: 0,
|
|
262
|
+
LAK: 0,
|
|
263
|
+
KHR: 0,
|
|
264
|
+
MMK: 0,
|
|
265
|
+
PYG: 0,
|
|
266
|
+
VEF: 0,
|
|
267
|
+
VES: 0,
|
|
268
|
+
VED: 0,
|
|
269
|
+
};
|
|
270
|
+
return decimalPlaces[code] ?? 2;
|
|
271
|
+
}
|
|
272
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Core Utility Functions
|
|
3
|
+
* Pure functions without React dependencies
|
|
4
|
+
*/
|
|
5
|
+
export * from './products';
|
|
6
|
+
export * from './order';
|
|
7
|
+
export * from './currency';
|
|
8
|
+
export * from './pluginConfig';
|
|
9
|
+
export * from './checkout';
|
|
10
|
+
export * from './promotions';
|
|
11
|
+
export * from './postPurchases';
|
|
12
|
+
export * from './orderBump';
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Core Utility Functions
|
|
3
|
+
* Pure functions without React dependencies
|
|
4
|
+
*/
|
|
5
|
+
export * from './products';
|
|
6
|
+
export * from './order';
|
|
7
|
+
export * from './currency';
|
|
8
|
+
export * from './pluginConfig';
|
|
9
|
+
export * from './checkout';
|
|
10
|
+
export * from './promotions';
|
|
11
|
+
export * from './postPurchases';
|
|
12
|
+
export * from './orderBump';
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Order Utility Functions
|
|
3
|
+
* Pure functions for order data manipulation
|
|
4
|
+
*/
|
|
5
|
+
export interface OrderLineItem {
|
|
6
|
+
id: string;
|
|
7
|
+
orderId: string;
|
|
8
|
+
productId: string;
|
|
9
|
+
variantId: string;
|
|
10
|
+
priceId: string;
|
|
11
|
+
sku: string;
|
|
12
|
+
unitAmount: number;
|
|
13
|
+
quantity: number;
|
|
14
|
+
amount: number;
|
|
15
|
+
adjustedAmount: number;
|
|
16
|
+
currency: string;
|
|
17
|
+
adjustments?: Record<string, unknown>[];
|
|
18
|
+
recurring: boolean;
|
|
19
|
+
rebillMode?: string | null;
|
|
20
|
+
rebillStepIntervalMs?: number | null;
|
|
21
|
+
interval: string;
|
|
22
|
+
intervalCount: number;
|
|
23
|
+
totalBillingCycles: number;
|
|
24
|
+
unitAmountAfterFirstCycle: number;
|
|
25
|
+
subscriptionSettings?: Record<string, unknown> | null;
|
|
26
|
+
orderLineItemProduct: {
|
|
27
|
+
id: string;
|
|
28
|
+
name: string;
|
|
29
|
+
description: string;
|
|
30
|
+
storefrontProductId: string;
|
|
31
|
+
originalProductId: string;
|
|
32
|
+
orderLineItemId: string;
|
|
33
|
+
};
|
|
34
|
+
orderLineItemVariant: {
|
|
35
|
+
id: string;
|
|
36
|
+
name: string;
|
|
37
|
+
price: number | null;
|
|
38
|
+
currency: string | null;
|
|
39
|
+
imageUrl: string;
|
|
40
|
+
description: string | null;
|
|
41
|
+
storefrontVariantId: string | null;
|
|
42
|
+
originalVariantId: string;
|
|
43
|
+
orderLineItemId: string;
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
export interface Order {
|
|
47
|
+
id: string;
|
|
48
|
+
storeId: string;
|
|
49
|
+
accountId: string;
|
|
50
|
+
createdAt: string;
|
|
51
|
+
updatedAt: string;
|
|
52
|
+
status: string;
|
|
53
|
+
cancelledAt?: string | null;
|
|
54
|
+
cancelledReason?: string | null;
|
|
55
|
+
paidAt?: string | null;
|
|
56
|
+
paidAmount: number;
|
|
57
|
+
openAt: string;
|
|
58
|
+
abandonedAt?: string | null;
|
|
59
|
+
currency: string;
|
|
60
|
+
externalCustomerType?: string | null;
|
|
61
|
+
externalCustomerId?: string | null;
|
|
62
|
+
externalOrderId?: string | null;
|
|
63
|
+
billingAddress?: {
|
|
64
|
+
company: string;
|
|
65
|
+
firstName: string;
|
|
66
|
+
lastName: string;
|
|
67
|
+
address1: string;
|
|
68
|
+
city: string;
|
|
69
|
+
country: string;
|
|
70
|
+
state: string;
|
|
71
|
+
postal: string;
|
|
72
|
+
phone: string;
|
|
73
|
+
email?: string;
|
|
74
|
+
};
|
|
75
|
+
shippingAddress?: {
|
|
76
|
+
company: string;
|
|
77
|
+
firstName: string;
|
|
78
|
+
lastName: string;
|
|
79
|
+
address1: string;
|
|
80
|
+
city: string;
|
|
81
|
+
country: string;
|
|
82
|
+
state: string;
|
|
83
|
+
postal: string;
|
|
84
|
+
phone: string;
|
|
85
|
+
};
|
|
86
|
+
pickupAddress?: Record<string, unknown> | null;
|
|
87
|
+
taxesIncluded: boolean;
|
|
88
|
+
draft: boolean;
|
|
89
|
+
checkoutSessionId: string;
|
|
90
|
+
sessionHash: string;
|
|
91
|
+
customerId: string;
|
|
92
|
+
createdFrom: string;
|
|
93
|
+
paymentInstrumentId: string;
|
|
94
|
+
refundedAt?: string | null;
|
|
95
|
+
refundedAmount?: number | null;
|
|
96
|
+
metadata?: any;
|
|
97
|
+
customer?: {
|
|
98
|
+
id: string;
|
|
99
|
+
email: string;
|
|
100
|
+
firstName: string;
|
|
101
|
+
lastName: string;
|
|
102
|
+
externalCustomerId?: string | null;
|
|
103
|
+
lastOrderId: string;
|
|
104
|
+
accountId: string;
|
|
105
|
+
storeId: string;
|
|
106
|
+
billingAddress?: any;
|
|
107
|
+
shippingAddress?: any;
|
|
108
|
+
currency: string;
|
|
109
|
+
locale: string;
|
|
110
|
+
draft: boolean;
|
|
111
|
+
acceptsMarketing: boolean;
|
|
112
|
+
createdAt: string;
|
|
113
|
+
updatedAt: string;
|
|
114
|
+
metadata?: any;
|
|
115
|
+
device?: Record<string, unknown> | null;
|
|
116
|
+
};
|
|
117
|
+
items: OrderLineItem[];
|
|
118
|
+
summaries?: any[];
|
|
119
|
+
promotions?: any[];
|
|
120
|
+
checkoutSession?: {
|
|
121
|
+
id: string;
|
|
122
|
+
selectedPresentmentCurrency?: string;
|
|
123
|
+
[key: string]: any;
|
|
124
|
+
};
|
|
125
|
+
payments?: any[];
|
|
126
|
+
subscriptions?: any[];
|
|
127
|
+
store?: {
|
|
128
|
+
name: string;
|
|
129
|
+
chargeCurrencies: string[];
|
|
130
|
+
presentmentCurrencies: string[];
|
|
131
|
+
};
|
|
132
|
+
relatedOrders?: Order[];
|
|
133
|
+
}
|
|
134
|
+
export declare class OrderUtils {
|
|
135
|
+
/**
|
|
136
|
+
* Get order line items
|
|
137
|
+
*/
|
|
138
|
+
static getOrderLineItems(order: Order): OrderLineItem[];
|
|
139
|
+
/**
|
|
140
|
+
* Get order total
|
|
141
|
+
*/
|
|
142
|
+
static getOrderTotal(order: Order): number;
|
|
143
|
+
/**
|
|
144
|
+
* Get order status
|
|
145
|
+
*/
|
|
146
|
+
static getOrderStatus(order: Order): string;
|
|
147
|
+
/**
|
|
148
|
+
* Check if order is completed
|
|
149
|
+
*/
|
|
150
|
+
static isOrderCompleted(order: Order): boolean;
|
|
151
|
+
/**
|
|
152
|
+
* Check if order is pending
|
|
153
|
+
*/
|
|
154
|
+
static isOrderPending(order: Order): boolean;
|
|
155
|
+
/**
|
|
156
|
+
* Check if order is cancelled
|
|
157
|
+
*/
|
|
158
|
+
static isOrderCancelled(order: Order): boolean;
|
|
159
|
+
}
|