cloudcommerce 0.0.98 → 0.0.99
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/CHANGELOG.md +7 -0
- package/package.json +1 -1
- package/packages/api/package.json +1 -1
- package/packages/apps/correios/package.json +1 -1
- package/packages/apps/custom-shipping/package.json +1 -1
- package/packages/apps/discounts/package.json +1 -1
- package/packages/apps/frenet/package.json +1 -1
- package/packages/apps/tiny-erp/lib/event-to-tiny.js +94 -94
- package/packages/apps/tiny-erp/lib/index.js +1 -1
- package/packages/apps/tiny-erp/lib/integration/after-tiny-queue.js +71 -74
- package/packages/apps/tiny-erp/lib/integration/export-order-to-tiny.js +70 -73
- package/packages/apps/tiny-erp/lib/integration/export-product-to-tiny.js +49 -53
- package/packages/apps/tiny-erp/lib/integration/helpers/format-tiny-date.js +3 -3
- package/packages/apps/tiny-erp/lib/integration/import-order-from-tiny.js +76 -75
- package/packages/apps/tiny-erp/lib/integration/import-product-from-tiny.js +137 -140
- package/packages/apps/tiny-erp/lib/integration/parsers/order-from-tiny.js +40 -39
- package/packages/apps/tiny-erp/lib/integration/parsers/order-to-tiny.js +173 -178
- package/packages/apps/tiny-erp/lib/integration/parsers/product-from-tiny.js +173 -171
- package/packages/apps/tiny-erp/lib/integration/parsers/product-to-tiny.js +123 -127
- package/packages/apps/tiny-erp/lib/integration/parsers/status-from-tiny.js +32 -32
- package/packages/apps/tiny-erp/lib/integration/parsers/status-to-tiny.js +37 -37
- package/packages/apps/tiny-erp/lib/integration/post-tiny-erp.js +42 -43
- package/packages/apps/tiny-erp/lib/tiny-erp.js +8 -6
- package/packages/apps/tiny-erp/lib/tiny-webhook.js +76 -73
- package/packages/apps/tiny-erp/package.json +1 -1
- package/packages/cli/package.json +1 -1
- package/packages/config/package.json +1 -1
- package/packages/events/package.json +1 -1
- package/packages/firebase/package.json +1 -1
- package/packages/modules/lib/firebase/ajv.js +24 -19
- package/packages/modules/lib/firebase/call-app-module.js +110 -116
- package/packages/modules/lib/firebase/checkout.js +152 -151
- package/packages/modules/lib/firebase/functions-checkout/fix-items.js +187 -194
- package/packages/modules/lib/firebase/functions-checkout/get-custumerId.js +26 -25
- package/packages/modules/lib/firebase/functions-checkout/handle-order-transaction.js +109 -110
- package/packages/modules/lib/firebase/functions-checkout/new-order.js +177 -177
- package/packages/modules/lib/firebase/functions-checkout/request-to-module.js +59 -59
- package/packages/modules/lib/firebase/functions-checkout/utils.js +197 -195
- package/packages/modules/lib/firebase/handle-module.js +146 -144
- package/packages/modules/lib/firebase/proxy-apps.js +1 -2
- package/packages/modules/lib/firebase/serve-modules-api.js +53 -52
- package/packages/modules/lib/firebase.js +6 -4
- package/packages/modules/lib/index.js +15 -12
- package/packages/modules/package.json +1 -1
- package/packages/passport/package.json +1 -1
- package/packages/ssr/package.json +1 -1
- package/packages/storefront/astro.config.mjs +1 -1
- package/packages/storefront/dist/client/{LoginOffcanvas.daf3f717.js → LoginOffcanvas.c2faa1dc.js} +1 -1
- package/packages/storefront/dist/client/chunks/{LoginForm.d9251274.js → LoginForm.3bcb85fb.js} +10 -10
- package/packages/storefront/dist/client/chunks/{LoginOffcanvas.07fe6492.js → LoginOffcanvas.e48f274b.js} +1 -1
- package/packages/storefront/dist/client/sw.js +1 -1
- package/packages/storefront/dist/server/entry.mjs +2 -2
- package/packages/storefront/package.json +2 -2
- package/packages/storefront/tsconfig.json +1 -1
- package/packages/types/package.json +1 -1
|
@@ -1,67 +1,67 @@
|
|
|
1
1
|
import { logger } from 'firebase-functions';
|
|
2
2
|
import axios from 'axios';
|
|
3
|
+
|
|
3
4
|
// handle other modules endpoints directly
|
|
4
5
|
export default async (checkoutBody, hostname, label) => {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
}
|
|
54
|
-
if (resp.result.length === countAppErro) {
|
|
55
|
-
return null;
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
return resp.result;
|
|
6
|
+
const locationId = process.env.FIREBASE_CONFIG
|
|
7
|
+
? (JSON.parse(process.env.FIREBASE_CONFIG).locationId || 'southamerica-east1')
|
|
8
|
+
: 'southamerica-east1';
|
|
9
|
+
const baseUrl = hostname !== 'localhost' ? `https://${hostname}`
|
|
10
|
+
: `http://localhost:5001/${process.env.GCLOUD_PROJECT}/${locationId}/modules`; // To LocalTest
|
|
11
|
+
let moduleBody;
|
|
12
|
+
let modName;
|
|
13
|
+
switch (label) {
|
|
14
|
+
case 'shipping':
|
|
15
|
+
modName = 'calculate_shipping';
|
|
16
|
+
moduleBody = checkoutBody.shipping;
|
|
17
|
+
break;
|
|
18
|
+
case 'payment':
|
|
19
|
+
modName = 'list_payments';
|
|
20
|
+
moduleBody = checkoutBody.transaction;
|
|
21
|
+
break;
|
|
22
|
+
case 'discount':
|
|
23
|
+
modName = 'apply_discount';
|
|
24
|
+
moduleBody = checkoutBody.discount;
|
|
25
|
+
break;
|
|
26
|
+
case 'transaction':
|
|
27
|
+
modName = 'create_transaction';
|
|
28
|
+
moduleBody = checkoutBody.transaction;
|
|
29
|
+
break;
|
|
30
|
+
default:
|
|
31
|
+
break;
|
|
32
|
+
}
|
|
33
|
+
if (moduleBody && moduleBody.app_id && modName) {
|
|
34
|
+
// mask request objects
|
|
35
|
+
const url = `${baseUrl}/${modName}?app_id=${moduleBody.app_id}`;
|
|
36
|
+
// mount request body with received checkout body object
|
|
37
|
+
const body = {
|
|
38
|
+
...checkoutBody,
|
|
39
|
+
...moduleBody,
|
|
40
|
+
is_checkout_confirmation: true,
|
|
41
|
+
};
|
|
42
|
+
try {
|
|
43
|
+
console.log('> ', JSON.stringify({ url, body }));
|
|
44
|
+
const resp = (await axios.post(url, body)).data;
|
|
45
|
+
if (Array.isArray(resp.result)) {
|
|
46
|
+
let countAppErro = 0;
|
|
47
|
+
for (let i = 0; i < resp.result.length; i++) {
|
|
48
|
+
const result = resp.result[i];
|
|
49
|
+
if (!result.validated || result.error) {
|
|
50
|
+
countAppErro += 1;
|
|
51
|
+
console.error(result.response);
|
|
52
|
+
logger.error(result.response);
|
|
53
|
+
}
|
|
59
54
|
}
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
return null;
|
|
55
|
+
if (resp.result.length === countAppErro) {
|
|
56
|
+
return null;
|
|
63
57
|
}
|
|
58
|
+
}
|
|
59
|
+
return resp.result;
|
|
60
|
+
} catch (e) {
|
|
61
|
+
logger.error('>>erro: ', e);
|
|
62
|
+
return null;
|
|
64
63
|
}
|
|
65
|
-
|
|
64
|
+
}
|
|
65
|
+
return null;
|
|
66
66
|
};
|
|
67
|
-
|
|
67
|
+
// # sourceMappingURL=request-to-module.js.map
|
|
@@ -1,225 +1,227 @@
|
|
|
1
1
|
// eslint-disable-next-line padding-line-between-statements
|
|
2
2
|
import logger from 'firebase-functions/lib/logger';
|
|
3
|
+
|
|
3
4
|
const sendError = (res, status, errorCode, message, userMessage, moreInfo) => {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
5
|
+
return res.status(status)
|
|
6
|
+
.send({
|
|
7
|
+
status,
|
|
8
|
+
error_code: errorCode,
|
|
9
|
+
message,
|
|
10
|
+
user_message: userMessage,
|
|
11
|
+
more_info: moreInfo,
|
|
11
12
|
});
|
|
12
13
|
};
|
|
13
14
|
const fixAmount = (amount, body, orderBody) => {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
}
|
|
18
|
-
});
|
|
19
|
-
amount.total = Math.round(((amount.subtotal || 0) + (amount.freight || 0) - (amount.discount || 0)) * 100) / 100;
|
|
20
|
-
if (amount.total < 0) {
|
|
21
|
-
amount.total = 0;
|
|
15
|
+
Object.keys(amount).forEach((field) => {
|
|
16
|
+
if (amount[field] > 0 && field !== 'total') {
|
|
17
|
+
amount[field] = Math.round(amount[field] * 100) / 100;
|
|
22
18
|
}
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
19
|
+
});
|
|
20
|
+
amount.total = Math.round(((amount.subtotal || 0) + (amount.freight || 0) - (amount.discount || 0)) * 100) / 100;
|
|
21
|
+
if (amount.total < 0) {
|
|
22
|
+
amount.total = 0;
|
|
23
|
+
}
|
|
24
|
+
// also save amount to checkout and order body objects
|
|
25
|
+
body.amount = amount;
|
|
26
|
+
orderBody.amount = amount;
|
|
26
27
|
};
|
|
27
28
|
const getValidResults = (results, checkProp) => {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
}
|
|
43
|
-
// use it
|
|
44
|
-
validResults.push(result);
|
|
45
|
-
}
|
|
46
|
-
else {
|
|
47
|
-
// help identify likely app response errors
|
|
48
|
-
logger.error(result.response_errors);
|
|
49
|
-
}
|
|
29
|
+
// results array returned from module
|
|
30
|
+
// see ./#applications.js
|
|
31
|
+
const validResults = [];
|
|
32
|
+
if (Array.isArray(results)) {
|
|
33
|
+
for (let i = 0; i < results.length; i++) {
|
|
34
|
+
const result = results[i];
|
|
35
|
+
if (result.validated) {
|
|
36
|
+
if (checkProp) {
|
|
37
|
+
// validate one property from response object
|
|
38
|
+
const responseProp = result.response[checkProp];
|
|
39
|
+
if (!responseProp || (Array.isArray(responseProp) && !responseProp.length)) {
|
|
40
|
+
// try next module result
|
|
41
|
+
continue;
|
|
42
|
+
}
|
|
50
43
|
}
|
|
44
|
+
// use it
|
|
45
|
+
validResults.push(result);
|
|
46
|
+
} else {
|
|
47
|
+
// help identify likely app response errors
|
|
48
|
+
logger.error(result.response_errors);
|
|
49
|
+
}
|
|
51
50
|
}
|
|
52
|
-
|
|
51
|
+
}
|
|
52
|
+
return validResults;
|
|
53
53
|
};
|
|
54
54
|
const handleListPayments = (body, listPayment, paymentsBody, amount, orderBody) => {
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
55
|
+
for (let i = 0; i < listPayment.length; i++) {
|
|
56
|
+
const result = listPayment[i];
|
|
57
|
+
// treat list payments response
|
|
58
|
+
const { response } = result;
|
|
59
|
+
if (response && response.payment_gateways) {
|
|
60
|
+
// check chosen payment method code and name
|
|
61
|
+
const paymentMethod = paymentsBody.transaction.payment_method;
|
|
62
|
+
let paymentMethodCode;
|
|
63
|
+
let paymentMethodName;
|
|
64
|
+
if (paymentMethod) {
|
|
65
|
+
paymentMethodCode = paymentMethod.code;
|
|
66
|
+
paymentMethodName = paymentMethod.name;
|
|
67
|
+
}
|
|
68
|
+
// filter gateways by method code
|
|
69
|
+
const possibleGateways = response.payment_gateways.filter((paymentGatewayFound) => {
|
|
70
|
+
const paymentMethodFound = paymentGatewayFound.payment_method;
|
|
71
|
+
return !paymentMethodCode
|
|
72
72
|
|| (paymentMethodFound && paymentMethodFound.code === paymentMethodCode);
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
discountValue = maxDiscount;
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
amount.discount = amount.discount ? amount.discount : 0;
|
|
102
|
-
amount.discount += discountValue;
|
|
103
|
-
fixAmount(amount, body, orderBody);
|
|
104
|
-
}
|
|
105
|
-
// add to order body
|
|
106
|
-
orderBody.payment_method_label = paymentGateway.label || '';
|
|
107
|
-
// finally start creating new order
|
|
73
|
+
});
|
|
74
|
+
let paymentGateway;
|
|
75
|
+
if (possibleGateways.length > 1 && paymentMethodName) {
|
|
76
|
+
// prefer respective method name
|
|
77
|
+
paymentGateway = possibleGateways.find((paymentGatewayFound) => {
|
|
78
|
+
return paymentGatewayFound.payment_method.name === paymentMethodName;
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
if (!paymentGateway) {
|
|
82
|
+
[paymentGateway] = possibleGateways;
|
|
83
|
+
}
|
|
84
|
+
if (paymentGateway) {
|
|
85
|
+
const { discount } = paymentGateway;
|
|
86
|
+
// handle discount by payment method
|
|
87
|
+
const applyDiscountIn = discount && discount.apply_at;
|
|
88
|
+
if (applyDiscountIn && discount.value && amount[applyDiscountIn]) {
|
|
89
|
+
const maxDiscount = amount[applyDiscountIn] || 0;
|
|
90
|
+
// update amount discount and total
|
|
91
|
+
let discountValue;
|
|
92
|
+
if (discount.type === 'percentage') {
|
|
93
|
+
discountValue = (maxDiscount * discount.value) / 100;
|
|
94
|
+
} else {
|
|
95
|
+
discountValue = discount.value;
|
|
96
|
+
if (discountValue > maxDiscount) {
|
|
97
|
+
discountValue = maxDiscount;
|
|
108
98
|
}
|
|
99
|
+
}
|
|
100
|
+
amount.discount = amount.discount ? amount.discount : 0;
|
|
101
|
+
amount.discount += discountValue;
|
|
102
|
+
fixAmount(amount, body, orderBody);
|
|
109
103
|
}
|
|
104
|
+
// add to order body
|
|
105
|
+
orderBody.payment_method_label = paymentGateway.label || '';
|
|
106
|
+
// finally start creating new order
|
|
107
|
+
}
|
|
110
108
|
}
|
|
109
|
+
}
|
|
111
110
|
};
|
|
112
111
|
// simulate requets to calculate shipping endpoint
|
|
113
112
|
const handleShippingServices = (body, listShipping, amount, orderBody) => {
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
});
|
|
163
|
-
}
|
|
164
|
-
if (maxProductionDays) {
|
|
165
|
-
if (!shippingLine.posting_deadline) {
|
|
166
|
-
shippingLine.posting_deadline = {
|
|
167
|
-
days: 0,
|
|
168
|
-
};
|
|
169
|
-
}
|
|
170
|
-
shippingLine.posting_deadline.days += maxProductionDays;
|
|
171
|
-
}
|
|
172
|
-
// add to order body
|
|
173
|
-
orderBody.shipping_lines = [
|
|
174
|
-
// generate new object id and compose shipping line object
|
|
175
|
-
{ ...shippingApp, ...shippingLine },
|
|
176
|
-
];
|
|
177
|
-
orderBody.shipping_method_label = shippingService.label || '';
|
|
178
|
-
// continue to discount step
|
|
113
|
+
for (let i = 0; i < listShipping.length; i++) {
|
|
114
|
+
const result = listShipping[i];
|
|
115
|
+
// treat calculate shipping response
|
|
116
|
+
const { response } = result;
|
|
117
|
+
if (response && response.shipping_services) {
|
|
118
|
+
// check chosen shipping code
|
|
119
|
+
const shippingCode = body.shipping.service_code;
|
|
120
|
+
for (let index = 0; index < response.shipping_services.length; index++) {
|
|
121
|
+
const shippingService = response.shipping_services[index];
|
|
122
|
+
const shippingLine = shippingService.shipping_line;
|
|
123
|
+
if (shippingLine && (!shippingCode || shippingCode === shippingService.service_code)) {
|
|
124
|
+
// update amount freight and total
|
|
125
|
+
const priceFreight = (typeof shippingLine.price === 'number'
|
|
126
|
+
? shippingLine.price
|
|
127
|
+
: 0);
|
|
128
|
+
let freight = typeof shippingLine.total_price === 'number'
|
|
129
|
+
? shippingLine.total_price
|
|
130
|
+
: priceFreight;
|
|
131
|
+
if (freight < 0) {
|
|
132
|
+
freight = 0;
|
|
133
|
+
}
|
|
134
|
+
amount.freight = freight;
|
|
135
|
+
fixAmount(amount, body, orderBody);
|
|
136
|
+
// app info
|
|
137
|
+
const shippingApp = {
|
|
138
|
+
app: { _id: result._id, ...shippingService },
|
|
139
|
+
};
|
|
140
|
+
// remove shipping line property
|
|
141
|
+
delete shippingApp.app.shipping_line;
|
|
142
|
+
// sum production time to posting deadline
|
|
143
|
+
let maxProductionDays = 0;
|
|
144
|
+
if (orderBody.items) {
|
|
145
|
+
orderBody.items.forEach((item) => {
|
|
146
|
+
const productionTime = item.production_time;
|
|
147
|
+
if (productionTime) {
|
|
148
|
+
let productionDays = productionTime.days;
|
|
149
|
+
if (productionDays && productionTime.cumulative) {
|
|
150
|
+
productionDays *= item.quantity;
|
|
151
|
+
}
|
|
152
|
+
if (productionTime.max_time) {
|
|
153
|
+
if (productionDays > productionTime.max_time) {
|
|
154
|
+
productionDays = productionTime.max_time;
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
if (maxProductionDays < productionDays) {
|
|
158
|
+
maxProductionDays = productionDays;
|
|
179
159
|
}
|
|
160
|
+
}
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
if (maxProductionDays) {
|
|
164
|
+
if (!shippingLine.posting_deadline) {
|
|
165
|
+
shippingLine.posting_deadline = {
|
|
166
|
+
days: 0,
|
|
167
|
+
};
|
|
180
168
|
}
|
|
169
|
+
shippingLine.posting_deadline.days += maxProductionDays;
|
|
170
|
+
}
|
|
171
|
+
// add to order body
|
|
172
|
+
orderBody.shipping_lines = [
|
|
173
|
+
// generate new object id and compose shipping line object
|
|
174
|
+
{ ...shippingApp, ...shippingLine },
|
|
175
|
+
];
|
|
176
|
+
orderBody.shipping_method_label = shippingService.label || '';
|
|
177
|
+
// continue to discount step
|
|
181
178
|
}
|
|
179
|
+
}
|
|
182
180
|
}
|
|
181
|
+
}
|
|
183
182
|
};
|
|
184
183
|
const handleApplyDiscount = (body, listDiscount, amount, orderBody) => {
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
}
|
|
213
|
-
if (response.freebie_product_ids.includes(item.product_id)) {
|
|
214
|
-
item.flags.push('discount-set-free');
|
|
215
|
-
}
|
|
216
|
-
});
|
|
217
|
-
}
|
|
218
|
-
break;
|
|
184
|
+
// simulate request to apply discount endpoint to get extra discount value
|
|
185
|
+
for (let i = 0; i < listDiscount.length; i++) {
|
|
186
|
+
const result = listDiscount[i];
|
|
187
|
+
// treat apply discount response
|
|
188
|
+
const { response } = result;
|
|
189
|
+
if (response && response.discount_rule) {
|
|
190
|
+
// check discount value
|
|
191
|
+
const discountRule = response.discount_rule;
|
|
192
|
+
const extraDiscount = discountRule.extra_discount;
|
|
193
|
+
if (extraDiscount && extraDiscount.value) {
|
|
194
|
+
// update amount and save extra discount to order body
|
|
195
|
+
amount.discount += extraDiscount.value;
|
|
196
|
+
fixAmount(amount, body, orderBody);
|
|
197
|
+
orderBody.extra_discount = {
|
|
198
|
+
...body.discount,
|
|
199
|
+
...extraDiscount,
|
|
200
|
+
// app info
|
|
201
|
+
app: {
|
|
202
|
+
...discountRule,
|
|
203
|
+
_id: result._id,
|
|
204
|
+
},
|
|
205
|
+
};
|
|
206
|
+
if (response.freebie_product_ids) {
|
|
207
|
+
// mark items provided for free
|
|
208
|
+
orderBody.items.forEach((item) => {
|
|
209
|
+
if (!item.flags) {
|
|
210
|
+
item.flags = [];
|
|
219
211
|
}
|
|
212
|
+
if (response.freebie_product_ids.includes(item.product_id)) {
|
|
213
|
+
item.flags.push('discount-set-free');
|
|
214
|
+
}
|
|
215
|
+
});
|
|
220
216
|
}
|
|
217
|
+
break;
|
|
218
|
+
}
|
|
221
219
|
}
|
|
222
|
-
|
|
220
|
+
}
|
|
221
|
+
// proceed to list payments
|
|
222
|
+
};
|
|
223
|
+
|
|
224
|
+
export {
|
|
225
|
+
sendError, fixAmount, getValidResults, handleShippingServices, handleApplyDiscount, handleListPayments,
|
|
223
226
|
};
|
|
224
|
-
|
|
225
|
-
//# sourceMappingURL=utils.js.map
|
|
227
|
+
// # sourceMappingURL=utils.js.map
|