cloudcommerce 0.0.97 → 0.0.98
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 +74 -71
- package/packages/apps/tiny-erp/lib/integration/export-order-to-tiny.js +73 -70
- package/packages/apps/tiny-erp/lib/integration/export-product-to-tiny.js +53 -49
- 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 +75 -76
- package/packages/apps/tiny-erp/lib/integration/import-product-from-tiny.js +140 -137
- package/packages/apps/tiny-erp/lib/integration/parsers/order-from-tiny.js +39 -40
- package/packages/apps/tiny-erp/lib/integration/parsers/order-to-tiny.js +178 -173
- package/packages/apps/tiny-erp/lib/integration/parsers/product-from-tiny.js +171 -173
- package/packages/apps/tiny-erp/lib/integration/parsers/product-to-tiny.js +127 -123
- 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 +43 -42
- package/packages/apps/tiny-erp/lib/tiny-erp.js +6 -8
- package/packages/apps/tiny-erp/lib/tiny-webhook.js +73 -76
- 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/lib/config.js +27 -25
- package/packages/firebase/lib/const.js +3 -2
- package/packages/firebase/lib/env.js +2 -1
- package/packages/firebase/lib/handlers/check-store-events.js +146 -145
- package/packages/firebase/lib/helpers/pubsub.js +20 -18
- package/packages/firebase/lib/helpers/update-app-data.js +38 -38
- package/packages/firebase/lib/index.js +9 -7
- package/packages/firebase/lib/init.js +2 -1
- package/packages/firebase/package.json +1 -1
- package/packages/modules/lib/firebase/ajv.js +19 -24
- package/packages/modules/lib/firebase/call-app-module.js +116 -110
- package/packages/modules/lib/firebase/checkout.js +151 -152
- package/packages/modules/lib/firebase/functions-checkout/fix-items.js +194 -187
- package/packages/modules/lib/firebase/functions-checkout/get-custumerId.js +25 -26
- package/packages/modules/lib/firebase/functions-checkout/handle-order-transaction.js +110 -109
- 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 +195 -197
- package/packages/modules/lib/firebase/handle-module.js +144 -146
- package/packages/modules/lib/firebase/proxy-apps.js +2 -1
- package/packages/modules/lib/firebase/serve-modules-api.js +52 -53
- package/packages/modules/lib/firebase.js +4 -6
- package/packages/modules/lib/index.js +12 -15
- package/packages/modules/package.json +1 -1
- package/packages/passport/package.json +1 -1
- package/packages/ssr/package.json +1 -1
- package/packages/storefront/dist/client/LoginOffcanvas.daf3f717.js +1 -0
- package/packages/storefront/dist/client/admin/config.json +1 -0
- package/packages/storefront/dist/client/assets/_...522e6bf2.css +4 -0
- package/packages/storefront/dist/client/assets/_...a48b75c7.css +1 -0
- package/packages/storefront/dist/client/assets/cms-preview.css +274 -0
- package/packages/storefront/dist/client/assets/cms.css +114 -0
- package/packages/storefront/dist/client/assets/cvv.png +0 -0
- package/packages/storefront/dist/client/assets/icons/bootstrap-icons/font/storefront-icons.woff2 +0 -0
- package/packages/storefront/dist/client/assets/icons/feather-icons/font/storefront-icons.woff2 +0 -0
- package/packages/storefront/dist/client/assets/icons/font-awesome/font/storefront-icons.woff2 +0 -0
- package/packages/storefront/dist/client/assets/icons/line-awesome/font/storefront-icons.woff2 +0 -0
- package/packages/storefront/dist/client/assets/icons/tabler-icons/font/storefront-icons.woff2 +0 -0
- package/packages/storefront/dist/client/assets/img-placeholder.png +0 -0
- package/packages/storefront/dist/client/assets/payments.png +0 -0
- package/packages/storefront/dist/client/assets/ssl-safe.png +0 -0
- package/packages/storefront/dist/client/chunks/LoginForm.d9251274.js +1066 -0
- package/packages/storefront/dist/client/chunks/LoginOffcanvas.07fe6492.js +1 -0
- package/packages/storefront/dist/client/chunks/index.esm.84a649c7.js +331 -0
- package/packages/storefront/dist/client/chunks/preload-helper.f15ab524.js +1 -0
- package/packages/storefront/dist/client/chunks/runtime-dom.esm-bundler.738639ee.js +1 -0
- package/packages/storefront/dist/client/chunks/workbox-window.prod.es5.4b654ae6.js +2 -0
- package/packages/storefront/dist/client/client.b552d86a.js +1 -0
- package/packages/storefront/dist/client/hoisted.054c36ac.js +1 -0
- package/packages/storefront/dist/client/img/icon.png +0 -0
- package/packages/storefront/dist/client/img/large-icon.png +0 -0
- package/packages/storefront/dist/client/img/uploads/banner1.png +0 -0
- package/packages/storefront/dist/client/img/uploads/banner2.png +0 -0
- package/packages/storefront/dist/client/img/uploads/banner2.webp +0 -0
- package/packages/storefront/dist/client/img/uploads/favicon.png +0 -0
- package/packages/storefront/dist/client/img/uploads/headless.png +0 -0
- package/packages/storefront/dist/client/img/uploads/headphone.png +0 -0
- package/packages/storefront/dist/client/img/uploads/headphone.webp +0 -0
- package/packages/storefront/dist/client/img/uploads/icon.png +0 -0
- package/packages/storefront/dist/client/img/uploads/large-icon.png +0 -0
- package/packages/storefront/dist/client/img/uploads/logo.png +0 -0
- package/packages/storefront/dist/client/img/uploads/logo.webp +0 -0
- package/packages/storefront/dist/client/img/uploads/og-image.png +0 -0
- package/packages/storefront/dist/client/img/uploads/passion.png +0 -0
- package/packages/storefront/dist/client/img/uploads/passion.webp +0 -0
- package/packages/storefront/dist/client/img/uploads/pwa-reliable.png +0 -0
- package/packages/storefront/dist/client/img/uploads/rect8589.png +0 -0
- package/packages/storefront/dist/client/img/uploads/rect859.png +0 -0
- package/packages/storefront/dist/client/img/uploads/rect89.png +0 -0
- package/packages/storefront/dist/client/img/uploads/rect89.webp +0 -0
- package/packages/storefront/dist/client/img/uploads/ssl-safe.png +0 -0
- package/packages/storefront/dist/client/manifest.webmanifest +1 -0
- package/packages/storefront/dist/client/page.3aa82516.js +1 -0
- package/packages/storefront/dist/client/robots.txt +8 -0
- package/packages/storefront/dist/client/sw.js +1 -0
- package/packages/storefront/dist/client/workbox-6f0d1f78.js +1 -0
- package/packages/storefront/dist/client/~partytown/partytown-atomics.js +2 -0
- package/packages/storefront/dist/client/~partytown/partytown-media.js +2 -0
- package/packages/storefront/dist/client/~partytown/partytown-sw.js +2 -0
- package/packages/storefront/dist/client/~partytown/partytown.js +2 -0
- package/packages/storefront/dist/server/entry.mjs +2852 -0
- package/packages/storefront/dist/server/manifest.webmanifest +1 -0
- package/packages/storefront/dist/server/registerSW.js +1 -0
- package/packages/storefront/package.json +1 -1
- package/packages/storefront/src/lib/layouts/PagesHeader.astro +2 -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
|
-
|
|
4
3
|
// handle other modules endpoints directly
|
|
5
4
|
export default async (checkoutBody, hostname, label) => {
|
|
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
|
-
|
|
5
|
+
const locationId = process.env.FIREBASE_CONFIG
|
|
6
|
+
? (JSON.parse(process.env.FIREBASE_CONFIG).locationId || 'southamerica-east1')
|
|
7
|
+
: 'southamerica-east1';
|
|
8
|
+
const baseUrl = hostname !== 'localhost' ? `https://${hostname}`
|
|
9
|
+
: `http://localhost:5001/${process.env.GCLOUD_PROJECT}/${locationId}/modules`; // To LocalTest
|
|
10
|
+
let moduleBody;
|
|
11
|
+
let modName;
|
|
12
|
+
switch (label) {
|
|
13
|
+
case 'shipping':
|
|
14
|
+
modName = 'calculate_shipping';
|
|
15
|
+
moduleBody = checkoutBody.shipping;
|
|
16
|
+
break;
|
|
17
|
+
case 'payment':
|
|
18
|
+
modName = 'list_payments';
|
|
19
|
+
moduleBody = checkoutBody.transaction;
|
|
20
|
+
break;
|
|
21
|
+
case 'discount':
|
|
22
|
+
modName = 'apply_discount';
|
|
23
|
+
moduleBody = checkoutBody.discount;
|
|
24
|
+
break;
|
|
25
|
+
case 'transaction':
|
|
26
|
+
modName = 'create_transaction';
|
|
27
|
+
moduleBody = checkoutBody.transaction;
|
|
28
|
+
break;
|
|
29
|
+
default:
|
|
30
|
+
break;
|
|
31
|
+
}
|
|
32
|
+
if (moduleBody && moduleBody.app_id && modName) {
|
|
33
|
+
// mask request objects
|
|
34
|
+
const url = `${baseUrl}/${modName}?app_id=${moduleBody.app_id}`;
|
|
35
|
+
// mount request body with received checkout body object
|
|
36
|
+
const body = {
|
|
37
|
+
...checkoutBody,
|
|
38
|
+
...moduleBody,
|
|
39
|
+
is_checkout_confirmation: true,
|
|
40
|
+
};
|
|
41
|
+
try {
|
|
42
|
+
console.log('> ', JSON.stringify({ url, body }));
|
|
43
|
+
const resp = (await axios.post(url, body)).data;
|
|
44
|
+
if (Array.isArray(resp.result)) {
|
|
45
|
+
let countAppErro = 0;
|
|
46
|
+
for (let i = 0; i < resp.result.length; i++) {
|
|
47
|
+
const result = resp.result[i];
|
|
48
|
+
if (!result.validated || result.error) {
|
|
49
|
+
countAppErro += 1;
|
|
50
|
+
console.error(result.response);
|
|
51
|
+
logger.error(result.response);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
if (resp.result.length === countAppErro) {
|
|
55
|
+
return null;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
return resp.result;
|
|
54
59
|
}
|
|
55
|
-
|
|
56
|
-
|
|
60
|
+
catch (e) {
|
|
61
|
+
logger.error('>>erro: ', e);
|
|
62
|
+
return null;
|
|
57
63
|
}
|
|
58
|
-
}
|
|
59
|
-
return resp.result;
|
|
60
|
-
} catch (e) {
|
|
61
|
-
logger.error('>>erro: ', e);
|
|
62
|
-
return null;
|
|
63
64
|
}
|
|
64
|
-
|
|
65
|
-
return null;
|
|
65
|
+
return null;
|
|
66
66
|
};
|
|
67
|
-
|
|
67
|
+
//# sourceMappingURL=request-to-module.js.map
|
|
@@ -1,227 +1,225 @@
|
|
|
1
1
|
// eslint-disable-next-line padding-line-between-statements
|
|
2
2
|
import logger from 'firebase-functions/lib/logger';
|
|
3
|
-
|
|
4
3
|
const sendError = (res, status, errorCode, message, userMessage, moreInfo) => {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
4
|
+
return res.status(status)
|
|
5
|
+
.send({
|
|
6
|
+
status,
|
|
7
|
+
error_code: errorCode,
|
|
8
|
+
message,
|
|
9
|
+
user_message: userMessage,
|
|
10
|
+
more_info: moreInfo,
|
|
12
11
|
});
|
|
13
12
|
};
|
|
14
13
|
const fixAmount = (amount, body, orderBody) => {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
14
|
+
Object.keys(amount).forEach((field) => {
|
|
15
|
+
if (amount[field] > 0 && field !== 'total') {
|
|
16
|
+
amount[field] = Math.round(amount[field] * 100) / 100;
|
|
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;
|
|
18
22
|
}
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
amount.total = 0;
|
|
23
|
-
}
|
|
24
|
-
// also save amount to checkout and order body objects
|
|
25
|
-
body.amount = amount;
|
|
26
|
-
orderBody.amount = amount;
|
|
23
|
+
// also save amount to checkout and order body objects
|
|
24
|
+
body.amount = amount;
|
|
25
|
+
orderBody.amount = amount;
|
|
27
26
|
};
|
|
28
27
|
const getValidResults = (results, checkProp) => {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
28
|
+
// results array returned from module
|
|
29
|
+
// see ./#applications.js
|
|
30
|
+
const validResults = [];
|
|
31
|
+
if (Array.isArray(results)) {
|
|
32
|
+
for (let i = 0; i < results.length; i++) {
|
|
33
|
+
const result = results[i];
|
|
34
|
+
if (result.validated) {
|
|
35
|
+
if (checkProp) {
|
|
36
|
+
// validate one property from response object
|
|
37
|
+
const responseProp = result.response[checkProp];
|
|
38
|
+
if (!responseProp || (Array.isArray(responseProp) && !responseProp.length)) {
|
|
39
|
+
// try next module result
|
|
40
|
+
continue;
|
|
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
|
+
}
|
|
43
50
|
}
|
|
44
|
-
// use it
|
|
45
|
-
validResults.push(result);
|
|
46
|
-
} else {
|
|
47
|
-
// help identify likely app response errors
|
|
48
|
-
logger.error(result.response_errors);
|
|
49
|
-
}
|
|
50
51
|
}
|
|
51
|
-
|
|
52
|
-
return validResults;
|
|
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
|
-
|
|
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
|
+
}
|
|
95
|
+
else {
|
|
96
|
+
discountValue = discount.value;
|
|
97
|
+
if (discountValue > maxDiscount) {
|
|
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
|
|
98
108
|
}
|
|
99
|
-
}
|
|
100
|
-
amount.discount = amount.discount ? amount.discount : 0;
|
|
101
|
-
amount.discount += discountValue;
|
|
102
|
-
fixAmount(amount, body, orderBody);
|
|
103
109
|
}
|
|
104
|
-
// add to order body
|
|
105
|
-
orderBody.payment_method_label = paymentGateway.label || '';
|
|
106
|
-
// finally start creating new order
|
|
107
|
-
}
|
|
108
110
|
}
|
|
109
|
-
}
|
|
110
111
|
};
|
|
111
112
|
// simulate requets to calculate shipping endpoint
|
|
112
113
|
const handleShippingServices = (body, listShipping, amount, orderBody) => {
|
|
113
|
-
|
|
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
|
-
|
|
114
|
+
for (let i = 0; i < listShipping.length; i++) {
|
|
115
|
+
const result = listShipping[i];
|
|
116
|
+
// treat calculate shipping response
|
|
117
|
+
const { response } = result;
|
|
118
|
+
if (response && response.shipping_services) {
|
|
119
|
+
// check chosen shipping code
|
|
120
|
+
const shippingCode = body.shipping.service_code;
|
|
121
|
+
for (let index = 0; index < response.shipping_services.length; index++) {
|
|
122
|
+
const shippingService = response.shipping_services[index];
|
|
123
|
+
const shippingLine = shippingService.shipping_line;
|
|
124
|
+
if (shippingLine && (!shippingCode || shippingCode === shippingService.service_code)) {
|
|
125
|
+
// update amount freight and total
|
|
126
|
+
const priceFreight = (typeof shippingLine.price === 'number'
|
|
127
|
+
? shippingLine.price
|
|
128
|
+
: 0);
|
|
129
|
+
let freight = typeof shippingLine.total_price === 'number'
|
|
130
|
+
? shippingLine.total_price
|
|
131
|
+
: priceFreight;
|
|
132
|
+
if (freight < 0) {
|
|
133
|
+
freight = 0;
|
|
134
|
+
}
|
|
135
|
+
amount.freight = freight;
|
|
136
|
+
fixAmount(amount, body, orderBody);
|
|
137
|
+
// app info
|
|
138
|
+
const shippingApp = {
|
|
139
|
+
app: { _id: result._id, ...shippingService },
|
|
140
|
+
};
|
|
141
|
+
// remove shipping line property
|
|
142
|
+
delete shippingApp.app.shipping_line;
|
|
143
|
+
// sum production time to posting deadline
|
|
144
|
+
let maxProductionDays = 0;
|
|
145
|
+
if (orderBody.items) {
|
|
146
|
+
orderBody.items.forEach((item) => {
|
|
147
|
+
const productionTime = item.production_time;
|
|
148
|
+
if (productionTime) {
|
|
149
|
+
let productionDays = productionTime.days;
|
|
150
|
+
if (productionDays && productionTime.cumulative) {
|
|
151
|
+
productionDays *= item.quantity;
|
|
152
|
+
}
|
|
153
|
+
if (productionTime.max_time) {
|
|
154
|
+
if (productionDays > productionTime.max_time) {
|
|
155
|
+
productionDays = productionTime.max_time;
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
if (maxProductionDays < productionDays) {
|
|
159
|
+
maxProductionDays = productionDays;
|
|
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
|
|
159
179
|
}
|
|
160
|
-
}
|
|
161
|
-
});
|
|
162
|
-
}
|
|
163
|
-
if (maxProductionDays) {
|
|
164
|
-
if (!shippingLine.posting_deadline) {
|
|
165
|
-
shippingLine.posting_deadline = {
|
|
166
|
-
days: 0,
|
|
167
|
-
};
|
|
168
180
|
}
|
|
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
|
|
178
181
|
}
|
|
179
|
-
}
|
|
180
182
|
}
|
|
181
|
-
}
|
|
182
183
|
};
|
|
183
184
|
const handleApplyDiscount = (body, listDiscount, amount, orderBody) => {
|
|
184
|
-
|
|
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
|
-
|
|
185
|
+
// simulate request to apply discount endpoint to get extra discount value
|
|
186
|
+
for (let i = 0; i < listDiscount.length; i++) {
|
|
187
|
+
const result = listDiscount[i];
|
|
188
|
+
// treat apply discount response
|
|
189
|
+
const { response } = result;
|
|
190
|
+
if (response && response.discount_rule) {
|
|
191
|
+
// check discount value
|
|
192
|
+
const discountRule = response.discount_rule;
|
|
193
|
+
const extraDiscount = discountRule.extra_discount;
|
|
194
|
+
if (extraDiscount && extraDiscount.value) {
|
|
195
|
+
// update amount and save extra discount to order body
|
|
196
|
+
amount.discount += extraDiscount.value;
|
|
197
|
+
fixAmount(amount, body, orderBody);
|
|
198
|
+
orderBody.extra_discount = {
|
|
199
|
+
...body.discount,
|
|
200
|
+
...extraDiscount,
|
|
201
|
+
// app info
|
|
202
|
+
app: {
|
|
203
|
+
...discountRule,
|
|
204
|
+
_id: result._id,
|
|
205
|
+
},
|
|
206
|
+
};
|
|
207
|
+
if (response.freebie_product_ids) {
|
|
208
|
+
// mark items provided for free
|
|
209
|
+
orderBody.items.forEach((item) => {
|
|
210
|
+
if (!item.flags) {
|
|
211
|
+
item.flags = [];
|
|
212
|
+
}
|
|
213
|
+
if (response.freebie_product_ids.includes(item.product_id)) {
|
|
214
|
+
item.flags.push('discount-set-free');
|
|
215
|
+
}
|
|
216
|
+
});
|
|
217
|
+
}
|
|
218
|
+
break;
|
|
214
219
|
}
|
|
215
|
-
});
|
|
216
220
|
}
|
|
217
|
-
break;
|
|
218
|
-
}
|
|
219
221
|
}
|
|
220
|
-
|
|
221
|
-
// proceed to list payments
|
|
222
|
-
};
|
|
223
|
-
|
|
224
|
-
export {
|
|
225
|
-
sendError, fixAmount, getValidResults, handleShippingServices, handleApplyDiscount, handleListPayments,
|
|
222
|
+
// proceed to list payments
|
|
226
223
|
};
|
|
227
|
-
|
|
224
|
+
export { sendError, fixAmount, getValidResults, handleShippingServices, handleApplyDiscount, handleListPayments, };
|
|
225
|
+
//# sourceMappingURL=utils.js.map
|