@wix/ditto-codegen-public 1.0.42 → 1.0.44

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.
@@ -10,6 +10,7 @@
10
10
  },
11
11
  "devDependencies": {
12
12
  "@types/react": "^16.0.0",
13
+ "@wix/data": "^1.0.290",
13
14
  "@types/react-dom": "^16.0.0",
14
15
  "@wix/cli": "^1.0.0",
15
16
  "@wix/cli-app": "^1.0.0",
@@ -1,24 +1,66 @@
1
- import { additionalFees } from "@wix/ecom/service-plugins";
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 (payload) => {
5
- const { request, metadata } = payload;
6
- // Use the `request` and `metadata` received from Wix and
7
- // apply custom logic.
8
- return {
9
- // Return your response exactly as documented to integrate with Wix.
10
- // Return value example:
11
- additionalFees: [
12
- {
13
- code: "subscription-fee",
14
- name: "Subscription Fee",
15
- price: "5",
16
- taxDetails: {
17
- taxable: true,
18
- },
19
- },
20
- ],
21
- currency: metadata.currency || "ILS",
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
  });