cloudcommerce 0.0.92 → 0.0.94
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 +19 -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/package.json +1 -1
- package/packages/cli/config/firebase.json +7 -2
- package/packages/cli/package.json +1 -1
- package/packages/config/package.json +1 -1
- package/packages/events/lib/firebase.js +2 -1
- package/packages/events/lib/index.js +1 -1
- package/packages/events/package.json +1 -1
- package/packages/firebase/package.json +1 -1
- package/packages/modules/lib/firebase/checkout.js +162 -0
- package/packages/modules/lib/firebase/checkout.js.map +1 -1
- package/packages/modules/lib/firebase/functions-checkout/fix-items.js +200 -0
- package/packages/modules/lib/firebase/functions-checkout/fix-items.js.map +1 -0
- package/packages/modules/lib/firebase/functions-checkout/get-custumerId.js +34 -0
- package/packages/modules/lib/firebase/functions-checkout/get-custumerId.js.map +1 -0
- package/packages/modules/lib/firebase/functions-checkout/handle-order-transaction.js +123 -0
- package/packages/modules/lib/firebase/functions-checkout/handle-order-transaction.js.map +1 -0
- package/packages/modules/lib/firebase/functions-checkout/new-order.js +191 -0
- package/packages/modules/lib/firebase/functions-checkout/new-order.js.map +1 -0
- package/packages/modules/lib/firebase/functions-checkout/request-to-module.js +67 -0
- package/packages/modules/lib/firebase/functions-checkout/request-to-module.js.map +1 -0
- package/packages/modules/lib/firebase/functions-checkout/utils.js +227 -0
- package/packages/modules/lib/firebase/functions-checkout/utils.js.map +1 -0
- package/packages/modules/lib/firebase/serve-modules-api.js +9 -4
- package/packages/modules/lib/firebase/serve-modules-api.js.map +1 -1
- package/packages/modules/package.json +1 -1
- package/packages/modules/schemas/@checkout.cjs +1 -1
- package/packages/modules/src/firebase/checkout.ts +235 -0
- package/packages/modules/src/firebase/functions-checkout/fix-items.ts +219 -0
- package/packages/modules/src/firebase/functions-checkout/get-custumerId.ts +33 -0
- package/packages/modules/src/firebase/functions-checkout/handle-order-transaction.ts +195 -0
- package/packages/modules/src/firebase/functions-checkout/new-order.ts +273 -0
- package/packages/modules/src/firebase/functions-checkout/request-to-module.ts +76 -0
- package/packages/modules/src/firebase/functions-checkout/utils.ts +301 -0
- package/packages/modules/src/firebase/serve-modules-api.ts +9 -4
- package/packages/modules/src/types/index.d.ts +67 -0
- package/packages/passport/lib/firebase/handle-passport.js +3 -1
- package/packages/passport/lib/firebase/handle-passport.js.map +1 -1
- package/packages/passport/lib/index.js +1 -0
- package/packages/passport/lib/index.js.map +1 -1
- package/packages/passport/package.json +1 -1
- package/packages/passport/src/firebase/handle-passport.ts +2 -0
- package/packages/passport/src/index.ts +1 -0
- package/packages/ssr/lib/firebase.js +5 -3
- package/packages/ssr/lib/firebase.js.map +1 -1
- package/packages/ssr/package.json +1 -4
- package/packages/ssr/src/firebase.ts +6 -3
- package/packages/storefront/astro.config.mjs +4 -9
- package/packages/storefront/dist/client/sw.js +1 -1
- package/packages/storefront/dist/server/entry.mjs +23 -348
- package/packages/storefront/package.json +1 -2
- package/packages/storefront/src/lib/helpers/image.ts +16 -29
- package/packages/storefront/src/lib/layouts/PagesHeader.astro +2 -5
- package/packages/storefront/storefront.config.mjs +7 -7
- package/packages/types/package.json +1 -1
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import { logger } from 'firebase-functions';
|
|
2
|
+
import api from '@cloudcommerce/api';
|
|
3
|
+
import { sendError } from './utils.js';
|
|
4
|
+
|
|
5
|
+
const checkoutRespond = (res, orderId, orderNumber, transaction) => {
|
|
6
|
+
return res.send({
|
|
7
|
+
status: 200,
|
|
8
|
+
order: {
|
|
9
|
+
_id: orderId,
|
|
10
|
+
number: orderNumber,
|
|
11
|
+
},
|
|
12
|
+
transaction,
|
|
13
|
+
});
|
|
14
|
+
};
|
|
15
|
+
const newOrder = async (orderBody, accessToken) => {
|
|
16
|
+
try {
|
|
17
|
+
const orderId = (await api.post('orders', orderBody, {
|
|
18
|
+
accessToken,
|
|
19
|
+
})).data._id;
|
|
20
|
+
return new Promise((resolve) => {
|
|
21
|
+
setTimeout(async () => {
|
|
22
|
+
try {
|
|
23
|
+
const order = (await api.get(`orders/${orderId}`, {
|
|
24
|
+
accessToken,
|
|
25
|
+
})).data;
|
|
26
|
+
resolve(order);
|
|
27
|
+
} catch (e) {
|
|
28
|
+
logger.error(e);
|
|
29
|
+
resolve(null);
|
|
30
|
+
}
|
|
31
|
+
}, 800);
|
|
32
|
+
});
|
|
33
|
+
} catch (e) {
|
|
34
|
+
logger.error(e);
|
|
35
|
+
return null;
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
const cancelOrder = async (staffNotes, orderId, accessToken, isOrderCancelled, res, usrMsg, errorMessage) => {
|
|
39
|
+
let msgErro;
|
|
40
|
+
if (!isOrderCancelled) {
|
|
41
|
+
const msgCancell = () => {
|
|
42
|
+
return new Promise((resolve) => {
|
|
43
|
+
setTimeout(async () => {
|
|
44
|
+
const body = {
|
|
45
|
+
status: 'cancelled',
|
|
46
|
+
staff_notes: staffNotes,
|
|
47
|
+
};
|
|
48
|
+
if (errorMessage) {
|
|
49
|
+
body.staff_notes += ` - \`${errorMessage.substring(0, 200)}\``;
|
|
50
|
+
}
|
|
51
|
+
try {
|
|
52
|
+
const response = (await api.patch(`orders/${orderId}`, body, {
|
|
53
|
+
accessToken,
|
|
54
|
+
}));
|
|
55
|
+
if (response.status === 204) {
|
|
56
|
+
isOrderCancelled = true;
|
|
57
|
+
}
|
|
58
|
+
} catch (e) {
|
|
59
|
+
logger.error(e);
|
|
60
|
+
}
|
|
61
|
+
resolve(`${body.staff_notes}`);
|
|
62
|
+
}, 400);
|
|
63
|
+
});
|
|
64
|
+
};
|
|
65
|
+
msgErro = await msgCancell();
|
|
66
|
+
}
|
|
67
|
+
return sendError(res, 409, 'CKT704', msgErro || staffNotes, usrMsg);
|
|
68
|
+
};
|
|
69
|
+
const saveTransaction = (accessToken, orderId, transactionBody) => {
|
|
70
|
+
return new Promise((resolve, reject) => {
|
|
71
|
+
api.post(`orders/${orderId}/transactions`, transactionBody, {
|
|
72
|
+
accessToken,
|
|
73
|
+
})
|
|
74
|
+
.then(({ data }) => {
|
|
75
|
+
resolve(data._id);
|
|
76
|
+
})
|
|
77
|
+
.catch((e) => {
|
|
78
|
+
reject(e);
|
|
79
|
+
});
|
|
80
|
+
});
|
|
81
|
+
};
|
|
82
|
+
const addPaymentHistory = async (orderId, accessToken, paymentHistory, isFirstTransaction, paymentEntry, dateTime, loyaltyPointsBalance, amount) => {
|
|
83
|
+
return new Promise((resolve, reject) => {
|
|
84
|
+
setTimeout(async () => {
|
|
85
|
+
const body = {
|
|
86
|
+
amount,
|
|
87
|
+
};
|
|
88
|
+
body.payments_history = paymentHistory;
|
|
89
|
+
if (isFirstTransaction) {
|
|
90
|
+
body.financial_status = {
|
|
91
|
+
current: paymentEntry.status,
|
|
92
|
+
updated_at: dateTime,
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
if (loyaltyPointsBalance > 0) {
|
|
96
|
+
const balance = Math.round(loyaltyPointsBalance * 100) / 100;
|
|
97
|
+
body.amount = {
|
|
98
|
+
...amount,
|
|
99
|
+
balance,
|
|
100
|
+
total: amount.total - balance,
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
try {
|
|
104
|
+
const response = (await api.patch(`orders/${orderId}`, body, {
|
|
105
|
+
accessToken,
|
|
106
|
+
}));
|
|
107
|
+
if (response.status === 204) {
|
|
108
|
+
resolve(true);
|
|
109
|
+
} else {
|
|
110
|
+
reject(new Error('Error adding payment history'));
|
|
111
|
+
}
|
|
112
|
+
} catch (e) {
|
|
113
|
+
logger.error(e);
|
|
114
|
+
reject(e);
|
|
115
|
+
}
|
|
116
|
+
}, isFirstTransaction ? 200 : 400);
|
|
117
|
+
});
|
|
118
|
+
};
|
|
119
|
+
|
|
120
|
+
export {
|
|
121
|
+
newOrder, cancelOrder, saveTransaction, addPaymentHistory, checkoutRespond,
|
|
122
|
+
};
|
|
123
|
+
// # sourceMappingURL=handle-order-transaction.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"handle-order-transaction.js","sourceRoot":"","sources":["../../../src/firebase/functions-checkout/handle-order-transaction.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAC5C,OAAO,GAAG,MAAM,oBAAoB,CAAC;AACrC,OAAO,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAEpC,MAAM,eAAe,GAAG,CACtB,GAAa,EACb,OAA6B,EAC7B,WAA+B,EAC/B,WAA8B,EAC9B,EAAE;IACF,OAAO,GAAG,CAAC,IAAI,CAAC;QACd,MAAM,EAAE,GAAG;QACX,KAAK,EAAE;YACL,GAAG,EAAE,OAAO;YACZ,MAAM,EAAE,WAAW;SACpB;QACD,WAAW;KACZ,CAAC,CAAC;AACL,CAAC,CAAC;AAEF,MAAM,QAAQ,GAAG,KAAK,EACpB,SAAmB,EACnB,WAAkB,EAClB,EAAE;IACF,IAAI;QACF,MAAM,OAAO,GAAG,CAAC,MAAM,GAAG,CAAC,IAAI,CAC7B,QAAQ,EACR,SAAS,EACT;YACE,WAAW;SACZ,CACF,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC;QAEZ,OAAO,IAAI,OAAO,CAAc,CAAC,OAAO,EAAE,EAAE;YAC1C,UAAU,CAAC,KAAK,IAAI,EAAE;gBACpB,IAAI;oBACF,MAAM,KAAK,GAAG,CAAC,MAAM,GAAG,CAAC,GAAG,CAC1B,UAAU,OAAO,EAAE,EACnB;wBACE,WAAW;qBACZ,CACF,CAAC,CAAC,IAAI,CAAC;oBACR,OAAO,CAAC,KAAK,CAAC,CAAC;iBAChB;gBAAC,OAAO,CAAC,EAAE;oBACV,MAAM,CAAC,KAAK,CAAC,CAAC,CAA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AG,GAAG,CAAC,GAAG,GAAG,CAAC;gBAC7D,IAAI,CAAC,MAAM,GAAG;oBACZ,GAAG,MAAM;oBACT,OAAO;oBACP,KAAK,EAAE,MAAM,CAAC,KAAK,GAAG,OAAO;iBAC9B,CAAC;aACH;YAED,IAAI;gBACF,MAAM,QAAQ,GAAG,CAAC,MAAM,GAAG,CAAC,KAAK,CAC/B,UAAU,OAAO,EAAE,EACnB,IAAI,EACJ;oBACE,WAAW;iBACZ,CACF,CAAC,CAAC;gBACH,IAAI,QAAQ,CAAC,MAAM,KAAK,GAAG,EAAE;oBAC3B,OAAO,CAAC,IAAI,CAAC,CAAC;iBACf;qBAAM;oBACL,MAAM,CAAC,IAAI,KAAK,CAAC,8BAA8B,CAAC,CAAC,CAAC;iBACnD;aACF;YAAC,OAAO,CAAC,EAAE;gBACV,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;gBAChB,MAAM,CAAC,CAAC,CAAC,CAAC;aACX;QACH,CAAC,EAAE,kBAAkB,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC;IACrC,CAAC,CAAC,CAAC;AACL,CAAC,CAAC;AAEF,OAAO,EACL,QAAQ,EACR,WAAW,EACX,eAAe,EACf,iBAAiB,EACjB,eAAe,GAChB,CAAC"}
|
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
import logger from 'firebase-functions/lib/logger';
|
|
2
|
+
import { sendError, getValidResults } from './utils.js';
|
|
3
|
+
import {
|
|
4
|
+
newOrder, cancelOrder, saveTransaction, addPaymentHistory, checkoutRespond,
|
|
5
|
+
} from './handle-order-transaction.js';
|
|
6
|
+
import requestModule from './request-to-module.js';
|
|
7
|
+
|
|
8
|
+
const usrMsg = {
|
|
9
|
+
en_us: 'Your order was saved, but we were unable to make the payment, '
|
|
10
|
+
+ 'please contact us',
|
|
11
|
+
pt_br: 'Seu pedido foi salvo, mas não conseguimos efetuar o pagamento, '
|
|
12
|
+
+ 'por favor entre em contato',
|
|
13
|
+
};
|
|
14
|
+
const createOrder = async (res, accessToken, hostname, amount, checkoutBody, orderBody, transactions, dateTime) => {
|
|
15
|
+
// start creating new order to API
|
|
16
|
+
const order = await newOrder(orderBody, accessToken);
|
|
17
|
+
if (order) {
|
|
18
|
+
const orderId = order._id;
|
|
19
|
+
const orderNumber = order.number;
|
|
20
|
+
const isOrderCancelled = false;
|
|
21
|
+
let countDone = 0;
|
|
22
|
+
let paymentsAmount = 0;
|
|
23
|
+
let loyaltyPointsBalance = 0;
|
|
24
|
+
const paymentHistory = [];
|
|
25
|
+
const nextTransaction = async (index = 0) => {
|
|
26
|
+
const newTransaction = transactions[index];
|
|
27
|
+
// merge objects to create transaction request body
|
|
28
|
+
const transactionBody = {
|
|
29
|
+
...checkoutBody,
|
|
30
|
+
transaction: newTransaction,
|
|
31
|
+
order_id: orderId,
|
|
32
|
+
order_number: orderNumber,
|
|
33
|
+
// also need shipping address
|
|
34
|
+
// send from shipping object if undefined on transaction object
|
|
35
|
+
to: { ...checkoutBody.shipping.to },
|
|
36
|
+
...newTransaction,
|
|
37
|
+
amount: { ...amount },
|
|
38
|
+
};
|
|
39
|
+
newTransaction.amount_part = newTransaction.amount_part || 0;
|
|
40
|
+
if (transactionBody.amount && newTransaction.amount_part > 0
|
|
41
|
+
&& newTransaction.amount_part < 1) {
|
|
42
|
+
// fix amount for multiple transactions
|
|
43
|
+
const partialAmount = transactionBody.amount.total * newTransaction.amount_part;
|
|
44
|
+
transactionBody.amount.discount = transactionBody.amount.discount || 0;
|
|
45
|
+
transactionBody.amount.discount += transactionBody.amount.total - partialAmount;
|
|
46
|
+
transactionBody.amount.total = partialAmount;
|
|
47
|
+
if (transactionBody.payment_method.code === 'loyalty_points') {
|
|
48
|
+
loyaltyPointsBalance += partialAmount;
|
|
49
|
+
}
|
|
50
|
+
delete transactionBody.amount_part;
|
|
51
|
+
}
|
|
52
|
+
// logger.log(JSON.stringify(transactionBody, null, 2))
|
|
53
|
+
// logger.log(JSON.stringify(checkoutBody, null, 2))
|
|
54
|
+
// finally pass to create transaction
|
|
55
|
+
let listTransactions = await requestModule(transactionBody, hostname, 'transaction');
|
|
56
|
+
if (listTransactions) {
|
|
57
|
+
listTransactions = getValidResults(listTransactions);
|
|
58
|
+
// simulateRequest(transactionBody, checkoutRespond, 'transaction', storeId, (results) => {
|
|
59
|
+
const isFirstTransaction = index === 0;
|
|
60
|
+
let isDone = false;
|
|
61
|
+
for (let i = 0; i < listTransactions.length; i++) {
|
|
62
|
+
const result = listTransactions[i];
|
|
63
|
+
// treat transaction response
|
|
64
|
+
const { response } = result;
|
|
65
|
+
const transaction = response && response.transaction;
|
|
66
|
+
if (transaction) {
|
|
67
|
+
// complete transaction object with some request body fields
|
|
68
|
+
[
|
|
69
|
+
'type',
|
|
70
|
+
'payment_method',
|
|
71
|
+
'payer',
|
|
72
|
+
'currency_id',
|
|
73
|
+
'currency_symbol',
|
|
74
|
+
].forEach((field) => {
|
|
75
|
+
if (transactionBody[field] !== undefined && transaction[field] === undefined) {
|
|
76
|
+
transaction[field] = transactionBody[field];
|
|
77
|
+
}
|
|
78
|
+
});
|
|
79
|
+
// setup transaction app object
|
|
80
|
+
if (!transaction.app) {
|
|
81
|
+
transaction.app = { _id: result._id };
|
|
82
|
+
// complete app object with some request body fields
|
|
83
|
+
const transactionOptions = Array.isArray(checkoutBody.transaction)
|
|
84
|
+
? checkoutBody.transaction.find((transactionFound) => transactionFound.app_id === result._id)
|
|
85
|
+
: checkoutBody.transaction;
|
|
86
|
+
if (transactionOptions) {
|
|
87
|
+
[
|
|
88
|
+
'label',
|
|
89
|
+
'icon',
|
|
90
|
+
'intermediator',
|
|
91
|
+
'payment_url',
|
|
92
|
+
].forEach((field) => {
|
|
93
|
+
if (transactionOptions[field] !== undefined && transaction.app) {
|
|
94
|
+
transaction.app[field] = transactionOptions[field];
|
|
95
|
+
}
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
// logger.log(transaction.app)
|
|
99
|
+
}
|
|
100
|
+
// check for transaction status
|
|
101
|
+
if (!transaction.status) {
|
|
102
|
+
transaction.status = {
|
|
103
|
+
current: 'pending',
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
transaction.status.updated_at = dateTime;
|
|
107
|
+
if (isFirstTransaction) {
|
|
108
|
+
// merge transaction body with order info and respond
|
|
109
|
+
return checkoutRespond(res, orderId, orderNumber, transaction);
|
|
110
|
+
}
|
|
111
|
+
// save transaction info on order data
|
|
112
|
+
// saveTransaction(transaction, orderId, storeId, (err, transactionId) => {
|
|
113
|
+
try {
|
|
114
|
+
// eslint-disable-next-line no-await-in-loop
|
|
115
|
+
const transactionId = await saveTransaction(accessToken, orderId, transaction);
|
|
116
|
+
// add entry to payments history
|
|
117
|
+
const paymentEntry = {
|
|
118
|
+
transaction_id: transactionId,
|
|
119
|
+
status: transaction.status.current,
|
|
120
|
+
date_time: dateTime,
|
|
121
|
+
flags: ['checkout'],
|
|
122
|
+
};
|
|
123
|
+
paymentHistory.push(paymentEntry);
|
|
124
|
+
try {
|
|
125
|
+
// eslint-disable-next-line no-await-in-loop
|
|
126
|
+
await addPaymentHistory(orderId, accessToken, paymentHistory, isFirstTransaction, paymentEntry, dateTime, loyaltyPointsBalance, amount);
|
|
127
|
+
} catch (e) {
|
|
128
|
+
logger.error(e);
|
|
129
|
+
}
|
|
130
|
+
} catch (e) {
|
|
131
|
+
logger.error(e);
|
|
132
|
+
}
|
|
133
|
+
index += 1;
|
|
134
|
+
if (index < transactions.length) {
|
|
135
|
+
return nextTransaction(index);
|
|
136
|
+
}
|
|
137
|
+
// });
|
|
138
|
+
isDone = true;
|
|
139
|
+
paymentsAmount += transaction.amount;
|
|
140
|
+
break;
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
if (isDone) {
|
|
144
|
+
countDone += 1;
|
|
145
|
+
if (countDone === transactions.length) {
|
|
146
|
+
if (amount.total / paymentsAmount > 1.01) {
|
|
147
|
+
return cancelOrder('Transaction amounts doesn\'t match (is lower) order total value', orderId, accessToken, isOrderCancelled, res, usrMsg);
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
// return
|
|
151
|
+
return checkoutRespond(res, orderId, orderNumber);
|
|
152
|
+
}
|
|
153
|
+
// unexpected response object from create transaction module
|
|
154
|
+
const firstResult = listTransactions && listTransactions[0];
|
|
155
|
+
let errorMessage;
|
|
156
|
+
if (firstResult) {
|
|
157
|
+
const { response } = firstResult;
|
|
158
|
+
if (response) {
|
|
159
|
+
// send devMsg with app response
|
|
160
|
+
if (response.message) {
|
|
161
|
+
errorMessage = response.message;
|
|
162
|
+
if (response.error) {
|
|
163
|
+
errorMessage += ` (${response.error})`;
|
|
164
|
+
}
|
|
165
|
+
} else {
|
|
166
|
+
errorMessage = JSON.stringify(response);
|
|
167
|
+
}
|
|
168
|
+
} else {
|
|
169
|
+
errorMessage = firstResult.error_message;
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
if (isFirstTransaction) {
|
|
173
|
+
return sendError(res, 409, 'CKT704', errorMessage || 'No valid transaction object', usrMsg);
|
|
174
|
+
}
|
|
175
|
+
return cancelOrder('Error trying to create transaction', orderId, accessToken, isOrderCancelled, res, usrMsg, errorMessage);
|
|
176
|
+
}
|
|
177
|
+
// send error no exist transaction
|
|
178
|
+
return sendError(res, 409, 'CKT704', 'There was a problem saving your order, please try again later', usrMsg);
|
|
179
|
+
};
|
|
180
|
+
return nextTransaction();
|
|
181
|
+
}
|
|
182
|
+
// send error
|
|
183
|
+
const userMessage = {
|
|
184
|
+
en_us: 'There was a problem saving your order, please try again later',
|
|
185
|
+
pt_br: 'Houve um problema ao salvar o pedido, por favor tente novamente mais tarde',
|
|
186
|
+
};
|
|
187
|
+
return sendError(res, 409, 'CKT701', 'There was a problem saving your order, please try again later', userMessage);
|
|
188
|
+
};
|
|
189
|
+
|
|
190
|
+
export default createOrder;
|
|
191
|
+
// # sourceMappingURL=new-order.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"new-order.js","sourceRoot":"","sources":["../../../src/firebase/functions-checkout/new-order.ts"],"names":[],"mappings":"AASA,OAAO,MAAM,MAAM,+BAA+B,CAAC;AACnD,OAAO,EAAE,SAAS,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AACrD,OAAO,EACL,QAAQ,EACR,WAAW,EACX,eAAe,EACf,iBAAiB,EACjB,eAAe,GAChB,MAAM,4BAA4B,CAAC;AACpC,OAAO,aAAa,MAAM,qBAAqB,CAAC;AAEhD,MAAM,MAAM,GAAG;IACb,KAAK,EAAE,gEAAgE;UACnE,mBAAmB;IACvB,KAAK,EAAE,iEAAiE;UACpE,4BAA4B;CACjC,CAAC;AAEF,MAAM,WAAW,GAAG,KAAK,EACvB,GAAa,EACb,WAAmB,EACnB,QAAgB,EAChB,MAAc,EACd,YAA0B,EAC1B,SAAmB,EACnB,YAAmC,EACnC,QAAgB,EAChB,EAAE;IACF,kCAAkC;IAElC,MAAM,KAAK,GAAG,MAAM,QAAQ,CAAC,SAAS,EAAE,WAAW,CAAC,CAAC;IACrD,IAAI,KAAK,EAAE;QACT,MAAM,OAAO,GAAG,KAAK,CAAC,GAAG,CAAC;QAC1B,MAAM,WAAW,GAAG,KAAK,CAAC,MAAM,CAAC;QACjC,MAAM,gBAAgB,GAAG,KAAK,CAAC;QAE/B,IAAI,SAAS,GAAG,CAAC,CAAC;QAClB,IAAI,cAAc,GAAG,CAAC,CAAC;QACvB,IAAI,oBAAoB,GAAG,CAAC,CAAC;QAC7B,MAAM,cAAc,GAAyB,EAAE,CAAC;QAEhD,MAAM,eAAe,GAAG,KAAK,EAAE,KAAK,GAAG,CAAC,EAAE,EAAE;YAC1C,MAAM,cAAc,GAAG,YAAY,CAAC,KAAK,CAAC,CAAC;YAE3C,mDAAmD;YACnD,MAAM,eAAe,GAAG;gBACtB,GAAG,YAAY;gBACf,WAAW,EAAE,cAAc;gBAC3B,QAAQ,EAAE,OAAO;gBACjB,YAAY,EAAE,WAAW;gBAC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iBACH;gBACD,OAAO,WAAW,CAChB,oCAAoC,EACpC,OAAO,EACP,WAAW,EACX,gBAAgB,EAChB,GAAG,EACH,MAAM,EACN,YAAY,CACb,CAAC;aACH;YACD,kCAAkC;YAClC,OAAO,SAAS,CACd,GAAG,EACH,GAAG,EACH,QAAQ,EACR,+DAA+D,EAC/D,MAAM,CACP,CAAC;QACJ,CAAC,CAAC;QAEF,OAAO,eAAe,EAAE,CAAC;KAC1B;IACD,aAAa;IACb,MAAM,WAAW,GAAG;QAClB,KAAK,EAAE,+DAA+D;QACtE,KAAK,EAAE,4EAA4E;KACpF,CAAC;IACF,OAAO,SAAS,CACd,GAAG,EACH,GAAG,EACH,QAAQ,EACR,+DAA+D,EAC/D,WAAW,CACZ,CAAC;AACJ,CAAC,CAAC;AAEF,eAAe,WAAW,CAAC"}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { logger } from 'firebase-functions';
|
|
2
|
+
import axios from 'axios';
|
|
3
|
+
|
|
4
|
+
// handle other modules endpoints directly
|
|
5
|
+
export default async (checkoutBody, hostname, label) => {
|
|
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
|
+
}
|
|
54
|
+
}
|
|
55
|
+
if (resp.result.length === countAppErro) {
|
|
56
|
+
return null;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
return resp.result;
|
|
60
|
+
} catch (e) {
|
|
61
|
+
logger.error('>>erro: ', e);
|
|
62
|
+
return null;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
return null;
|
|
66
|
+
};
|
|
67
|
+
// # sourceMappingURL=request-to-module.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"request-to-module.js","sourceRoot":"","sources":["../../../src/firebase/functions-checkout/request-to-module.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAC5C,OAAO,KAAK,MAAM,OAAO,CAA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IAAI;SAC/B,CAAC;QACF,IAAI;YACF,OAAO,CAAC,GAAG,CAAC,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,EAAE,GAAG,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC;YACjD,MAAM,IAAI,GAAG,CAAC,MAAM,KAAK,CAAC,IAAI,CAC5B,GAAG,EACH,IAAI,CACL,CAAC,CAAC,IAAI,CAAC;YACR,IAAI,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE;gBAC9B,IAAI,YAAY,GAAG,CAAC,CAAC;gBACrB,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE;oBAC3C,MAAM,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;oBAC9B,IAAI,CAAC,MAAM,CAAC,SAAS,IAAI,MAAM,CAAC,KAAK,EAAE;wBACrC,YAAY,IAAI,CAAC,CAAC;wBAClB,OAAO,CAAC,KAAK,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;wBAC/B,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;qBAC/B;iBACF;gBACD,IAAI,IAAI,CAAC,MAAM,CAAC,MAAM,KAAK,YAAY,EAAE;oBACvC,OAAO,IAAI,CAAC;iBACb;aACF;YACD,OAAO,IAAI,CAAC,MAAM,CAAC;SACpB;QAAC,OAAO,CAAC,EAAE;YACV,MAAM,CAAC,KAAK,CAAC,UAAU,EAAE,CAAC,CAAC,CAAC;YAC5B,OAAO,IAAI,CAAC;SACb;KACF;IACD,OAAO,IAAI,CAAC;AACd,CAAC,CAAC"}
|
|
@@ -0,0 +1,227 @@
|
|
|
1
|
+
// eslint-disable-next-line padding-line-between-statements
|
|
2
|
+
import logger from 'firebase-functions/lib/logger';
|
|
3
|
+
|
|
4
|
+
const sendError = (res, status, errorCode, message, userMessage, moreInfo) => {
|
|
5
|
+
return res.status(status)
|
|
6
|
+
.send({
|
|
7
|
+
status,
|
|
8
|
+
error_code: errorCode,
|
|
9
|
+
message,
|
|
10
|
+
user_message: userMessage,
|
|
11
|
+
more_info: moreInfo,
|
|
12
|
+
});
|
|
13
|
+
};
|
|
14
|
+
const fixAmount = (amount, body, orderBody) => {
|
|
15
|
+
Object.keys(amount).forEach((field) => {
|
|
16
|
+
if (amount[field] > 0 && field !== 'total') {
|
|
17
|
+
amount[field] = Math.round(amount[field] * 100) / 100;
|
|
18
|
+
}
|
|
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;
|
|
27
|
+
};
|
|
28
|
+
const getValidResults = (results, checkProp) => {
|
|
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
|
+
}
|
|
43
|
+
}
|
|
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
|
+
}
|
|
52
|
+
return validResults;
|
|
53
|
+
};
|
|
54
|
+
const handleListPayments = (body, listPayment, paymentsBody, amount, orderBody) => {
|
|
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
|
+
|| (paymentMethodFound && paymentMethodFound.code === paymentMethodCode);
|
|
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;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
amount.discount = amount.discount ? amount.discount : 0;
|
|
101
|
+
amount.discount += discountValue;
|
|
102
|
+
fixAmount(amount, body, orderBody);
|
|
103
|
+
}
|
|
104
|
+
// add to order body
|
|
105
|
+
orderBody.payment_method_label = paymentGateway.label || '';
|
|
106
|
+
// finally start creating new order
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
};
|
|
111
|
+
// simulate requets to calculate shipping endpoint
|
|
112
|
+
const handleShippingServices = (body, listShipping, amount, orderBody) => {
|
|
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;
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
if (maxProductionDays) {
|
|
164
|
+
if (!shippingLine.posting_deadline) {
|
|
165
|
+
shippingLine.posting_deadline = {
|
|
166
|
+
days: 0,
|
|
167
|
+
};
|
|
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
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
};
|
|
183
|
+
const handleApplyDiscount = (body, listDiscount, amount, orderBody) => {
|
|
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 = [];
|
|
211
|
+
}
|
|
212
|
+
if (response.freebie_product_ids.includes(item.product_id)) {
|
|
213
|
+
item.flags.push('discount-set-free');
|
|
214
|
+
}
|
|
215
|
+
});
|
|
216
|
+
}
|
|
217
|
+
break;
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
// proceed to list payments
|
|
222
|
+
};
|
|
223
|
+
|
|
224
|
+
export {
|
|
225
|
+
sendError, fixAmount, getValidResults, handleShippingServices, handleApplyDiscount, handleListPayments,
|
|
226
|
+
};
|
|
227
|
+
// # sourceMappingURL=utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../src/firebase/functions-checkout/utils.ts"],"names":[],"mappings":"AAaA,2DAA2D;AAC3D,OAAO,MAAM,MAAM,+BAA+B,CAAC;AAInD,MAAM,SAAS,GAAG,CAChB,GAAY,EACZ,MAAc,EACd,SAA0B,EAC1B,OAAe,EACf,WAAmC,EACnC,QAAgB,EAChB,EAAE;IACF,OAAO,GAAG,CAAC,MAAM,CAAC,MAAM,CAAC;SACtB,IAAI,CAAC;QACJ,MAAM;QACN,UAAU,EAAE,SAAS;QACrB,OAAO;QACP,YAAY,EAAE,WAAW;Q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