@wix/ditto-codegen-public 1.0.43 → 1.0.45
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.
|
@@ -1,24 +1,66 @@
|
|
|
1
|
-
import { additionalFees } from
|
|
1
|
+
import { additionalFees } from '@wix/ecom/service-plugins';
|
|
2
|
+
import { items } from '@wix/data';
|
|
3
|
+
|
|
4
|
+
interface GlobalFeeConfig {
|
|
5
|
+
_id: string;
|
|
6
|
+
feeAmount: number;
|
|
7
|
+
isEnabled: boolean;
|
|
8
|
+
}
|
|
2
9
|
|
|
3
10
|
additionalFees.provideHandlers({
|
|
4
|
-
calculateAdditionalFees: async (
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
11
|
+
calculateAdditionalFees: async ({ request, metadata }) => {
|
|
12
|
+
try {
|
|
13
|
+
// Query the global additional fee configuration
|
|
14
|
+
const configResult = await items.query('global-additional-fee-config')
|
|
15
|
+
.limit(1)
|
|
16
|
+
.find();
|
|
17
|
+
|
|
18
|
+
// If no configuration found or fee is disabled, return empty fees
|
|
19
|
+
if (!configResult.items.length) {
|
|
20
|
+
return {
|
|
21
|
+
additionalFees: [],
|
|
22
|
+
currency: metadata.currency || 'USD'
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const config = configResult.items[0] as GlobalFeeConfig;
|
|
27
|
+
|
|
28
|
+
// Check if the fee is enabled and has a valid amount
|
|
29
|
+
if (!config.isEnabled || !config.feeAmount || config.feeAmount <= 0) {
|
|
30
|
+
return {
|
|
31
|
+
additionalFees: [],
|
|
32
|
+
currency: metadata.currency || 'USD'
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
// Ensure currency matches site currency
|
|
37
|
+
const responseCurrency = metadata.currency || 'USD';
|
|
38
|
+
|
|
39
|
+
// Convert fee amount to string as required by Wix API
|
|
40
|
+
const feeAmountString = config.feeAmount.toString();
|
|
41
|
+
|
|
42
|
+
// Create the global additional fee
|
|
43
|
+
const globalFee = {
|
|
44
|
+
code: 'global-additional-fee',
|
|
45
|
+
name: 'Global Additional Fee',
|
|
46
|
+
translatedName: 'Global Additional Fee',
|
|
47
|
+
price: feeAmountString,
|
|
48
|
+
taxDetails: {
|
|
49
|
+
taxable: true
|
|
50
|
+
}
|
|
51
|
+
// No lineItemIds specified - applies to entire cart
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
return {
|
|
55
|
+
additionalFees: [globalFee],
|
|
56
|
+
currency: responseCurrency
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
} catch (error) {
|
|
60
|
+
return {
|
|
61
|
+
additionalFees: [],
|
|
62
|
+
currency: metadata.currency || 'USD'
|
|
63
|
+
};
|
|
64
|
+
}
|
|
23
65
|
},
|
|
24
66
|
});
|