cloudcommerce 0.0.96 → 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.
Files changed (84) hide show
  1. package/CHANGELOG.md +21 -0
  2. package/package.json +3 -3
  3. package/packages/api/package.json +1 -1
  4. package/packages/apps/correios/lib-mjs/correios-ws.mjs +2 -1
  5. package/packages/apps/correios/package.json +1 -1
  6. package/packages/apps/custom-shipping/package.json +1 -1
  7. package/packages/apps/discounts/package.json +1 -1
  8. package/packages/apps/frenet/package.json +1 -1
  9. package/packages/apps/tiny-erp/lib/event-to-tiny.js +94 -94
  10. package/packages/apps/tiny-erp/lib/index.js +1 -1
  11. package/packages/apps/tiny-erp/lib/integration/after-tiny-queue.js +74 -71
  12. package/packages/apps/tiny-erp/lib/integration/export-order-to-tiny.js +73 -70
  13. package/packages/apps/tiny-erp/lib/integration/export-product-to-tiny.js +53 -49
  14. package/packages/apps/tiny-erp/lib/integration/helpers/format-tiny-date.js +3 -3
  15. package/packages/apps/tiny-erp/lib/integration/import-order-from-tiny.js +75 -76
  16. package/packages/apps/tiny-erp/lib/integration/import-product-from-tiny.js +140 -137
  17. package/packages/apps/tiny-erp/lib/integration/parsers/order-from-tiny.js +39 -40
  18. package/packages/apps/tiny-erp/lib/integration/parsers/order-to-tiny.js +178 -173
  19. package/packages/apps/tiny-erp/lib/integration/parsers/product-from-tiny.js +171 -173
  20. package/packages/apps/tiny-erp/lib/integration/parsers/product-to-tiny.js +127 -123
  21. package/packages/apps/tiny-erp/lib/integration/parsers/status-from-tiny.js +32 -32
  22. package/packages/apps/tiny-erp/lib/integration/parsers/status-to-tiny.js +37 -37
  23. package/packages/apps/tiny-erp/lib/integration/post-tiny-erp.js +43 -42
  24. package/packages/apps/tiny-erp/lib/tiny-erp.js +6 -8
  25. package/packages/apps/tiny-erp/lib/tiny-webhook.js +73 -76
  26. package/packages/apps/tiny-erp/package.json +2 -2
  27. package/packages/cli/package.json +1 -1
  28. package/packages/config/package.json +1 -1
  29. package/packages/events/package.json +2 -2
  30. package/packages/firebase/package.json +3 -3
  31. package/packages/modules/lib/firebase/ajv.js +19 -24
  32. package/packages/modules/lib/firebase/call-app-module.js +116 -110
  33. package/packages/modules/lib/firebase/checkout.js +151 -152
  34. package/packages/modules/lib/firebase/functions-checkout/fix-items.js +194 -187
  35. package/packages/modules/lib/firebase/functions-checkout/get-custumerId.js +25 -26
  36. package/packages/modules/lib/firebase/functions-checkout/handle-order-transaction.js +110 -109
  37. package/packages/modules/lib/firebase/functions-checkout/new-order.js +177 -177
  38. package/packages/modules/lib/firebase/functions-checkout/request-to-module.js +59 -59
  39. package/packages/modules/lib/firebase/functions-checkout/utils.js +195 -197
  40. package/packages/modules/lib/firebase/handle-module.js +144 -146
  41. package/packages/modules/lib/firebase/proxy-apps.js +2 -1
  42. package/packages/modules/lib/firebase/serve-modules-api.js +52 -53
  43. package/packages/modules/lib/firebase.js +4 -6
  44. package/packages/modules/lib/index.js +12 -15
  45. package/packages/modules/package.json +2 -2
  46. package/packages/passport/package.json +2 -2
  47. package/packages/ssr/package.json +2 -2
  48. package/packages/storefront/.eslintrc.cjs +1 -0
  49. package/packages/storefront/astro.config.mjs +11 -1
  50. package/packages/storefront/dist/client/LoginOffcanvas.daf3f717.js +1 -0
  51. package/packages/storefront/dist/client/assets/_...522e6bf2.css +4 -0
  52. package/packages/storefront/dist/client/assets/{_...ee104f19.css → _...a48b75c7.css} +1 -1
  53. package/packages/storefront/dist/client/chunks/LoginForm.d9251274.js +1066 -0
  54. package/packages/storefront/dist/client/chunks/LoginOffcanvas.07fe6492.js +1 -0
  55. package/packages/storefront/dist/client/{hoisted.46e058d2.js → chunks/index.esm.84a649c7.js} +77 -17
  56. package/packages/storefront/dist/client/chunks/preload-helper.f15ab524.js +1 -0
  57. package/packages/storefront/dist/client/chunks/runtime-dom.esm-bundler.738639ee.js +1 -0
  58. package/packages/storefront/dist/client/client.b552d86a.js +1 -0
  59. package/packages/storefront/dist/client/hoisted.054c36ac.js +1 -0
  60. package/packages/storefront/dist/client/manifest.webmanifest +1 -1
  61. package/packages/storefront/dist/client/sw.js +1 -1
  62. package/packages/storefront/dist/server/entry.mjs +370 -180
  63. package/packages/storefront/dist/server/manifest.webmanifest +1 -1
  64. package/packages/storefront/package.json +6 -5
  65. package/packages/storefront/src/assets/pico.css +0 -1
  66. package/packages/storefront/src/env.d.ts +1 -1
  67. package/packages/storefront/src/lib/components/AOffcanvas.vue +98 -0
  68. package/packages/storefront/src/lib/components/LoginForm.vue +54 -0
  69. package/packages/storefront/src/lib/components/LoginOffcanvas.vue +41 -0
  70. package/packages/storefront/src/lib/components/TheHeader.vue +37 -3
  71. package/packages/storefront/src/lib/components/TopBar.vue +13 -21
  72. package/packages/storefront/src/lib/layouts/BaseBody.astro +41 -38
  73. package/packages/storefront/src/lib/layouts/BaseHead.astro +0 -5
  74. package/packages/storefront/src/lib/layouts/BaseStateJson.astro +12 -11
  75. package/packages/storefront/src/lib/layouts/PagesHeader.astro +29 -20
  76. package/packages/storefront/src/lib/scripts/firebase-app.ts +16 -0
  77. package/packages/storefront/src/lib/{helpers → ssr}/image.ts +1 -1
  78. package/packages/storefront/src/pages/app/account.astro +0 -0
  79. package/packages/storefront/storefront.config.mjs +1 -1
  80. package/packages/storefront/tsconfig.json +4 -1
  81. package/packages/types/package.json +1 -1
  82. package/packages/storefront/dist/client/assets/_...73e01db2.css +0 -4
  83. package/packages/storefront/dist/client/client.80baece3.js +0 -1
  84. package/packages/storefront/src/lib/components/LoginModal.vue +0 -82
@@ -1,123 +1,124 @@
1
1
  import { logger } from 'firebase-functions';
2
2
  import api from '@cloudcommerce/api';
3
3
  import { sendError } from './utils.js';
4
-
5
4
  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
- });
5
+ return res.send({
6
+ status: 200,
7
+ order: {
8
+ _id: orderId,
9
+ number: orderNumber,
10
+ },
11
+ transaction,
12
+ });
14
13
  };
15
14
  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}`, {
15
+ try {
16
+ const orderId = (await api.post('orders', orderBody, {
24
17
  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
- }
18
+ })).data._id;
19
+ return new Promise((resolve) => {
20
+ setTimeout(async () => {
21
+ try {
22
+ const order = (await api.get(`orders/${orderId}`, {
23
+ accessToken,
24
+ })).data;
25
+ resolve(order);
26
+ }
27
+ catch (e) {
28
+ logger.error(e);
29
+ resolve(null);
30
+ }
31
+ }, 800);
32
+ });
33
+ }
34
+ catch (e) {
35
+ logger.error(e);
36
+ return null;
37
+ }
37
38
  };
38
39
  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);
40
+ let msgErro;
41
+ if (!isOrderCancelled) {
42
+ const msgCancell = () => {
43
+ return new Promise((resolve) => {
44
+ setTimeout(async () => {
45
+ const body = {
46
+ status: 'cancelled',
47
+ staff_notes: staffNotes,
48
+ };
49
+ if (errorMessage) {
50
+ body.staff_notes += ` - \`${errorMessage.substring(0, 200)}\``;
51
+ }
52
+ try {
53
+ const response = (await api.patch(`orders/${orderId}`, body, {
54
+ accessToken,
55
+ }));
56
+ if (response.status === 204) {
57
+ isOrderCancelled = true;
58
+ }
59
+ }
60
+ catch (e) {
61
+ logger.error(e);
62
+ }
63
+ resolve(`${body.staff_notes}`);
64
+ }, 400);
65
+ });
66
+ };
67
+ msgErro = await msgCancell();
68
+ }
69
+ return sendError(res, 409, 'CKT704', msgErro || staffNotes, usrMsg);
68
70
  };
69
71
  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
- });
72
+ return new Promise((resolve, reject) => {
73
+ api.post(`orders/${orderId}/transactions`, transactionBody, {
74
+ accessToken,
75
+ })
76
+ .then(({ data }) => {
77
+ resolve(data._id);
78
+ })
79
+ .catch((e) => {
80
+ reject(e);
81
+ });
82
+ });
81
83
  };
82
84
  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,
85
+ return new Promise((resolve, reject) => {
86
+ setTimeout(async () => {
87
+ const body = {
88
+ amount,
89
+ };
90
+ body.payments_history = paymentHistory;
91
+ if (isFirstTransaction) {
92
+ body.financial_status = {
93
+ current: paymentEntry.status,
94
+ updated_at: dateTime,
95
+ };
96
+ }
97
+ if (loyaltyPointsBalance > 0) {
98
+ const balance = Math.round(loyaltyPointsBalance * 100) / 100;
99
+ body.amount = {
100
+ ...amount,
101
+ balance,
102
+ total: amount.total - balance,
103
+ };
104
+ }
105
+ try {
106
+ const response = (await api.patch(`orders/${orderId}`, body, {
107
+ accessToken,
108
+ }));
109
+ if (response.status === 204) {
110
+ resolve(true);
111
+ }
112
+ else {
113
+ reject(new Error('Error adding payment history'));
114
+ }
115
+ }
116
+ catch (e) {
117
+ logger.error(e);
118
+ reject(e);
119
+ }
120
+ }, isFirstTransaction ? 200 : 400);
121
+ });
122
122
  };
123
- // # sourceMappingURL=handle-order-transaction.js.map
123
+ export { newOrder, cancelOrder, saveTransaction, addPaymentHistory, checkoutRespond, };
124
+ //# sourceMappingURL=handle-order-transaction.js.map
@@ -1,191 +1,191 @@
1
1
  import logger from 'firebase-functions/lib/logger';
2
2
  import { sendError, getValidResults } from './utils.js';
3
- import {
4
- newOrder, cancelOrder, saveTransaction, addPaymentHistory, checkoutRespond,
5
- } from './handle-order-transaction.js';
3
+ import { newOrder, cancelOrder, saveTransaction, addPaymentHistory, checkoutRespond, } from './handle-order-transaction.js';
6
4
  import requestModule from './request-to-module.js';
7
-
8
5
  const usrMsg = {
9
- en_us: 'Your order was saved, but we were unable to make the payment, '
6
+ en_us: 'Your order was saved, but we were unable to make the payment, '
10
7
  + 'please contact us',
11
- pt_br: 'Seu pedido foi salvo, mas não conseguimos efetuar o pagamento, '
8
+ pt_br: 'Seu pedido foi salvo, mas não conseguimos efetuar o pagamento, '
12
9
  + 'por favor entre em contato',
13
10
  };
14
11
  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
12
+ // start creating new order to API
13
+ const order = await newOrder(orderBody, accessToken);
14
+ if (order) {
15
+ const orderId = order._id;
16
+ const orderNumber = order.number;
17
+ const isOrderCancelled = false;
18
+ let countDone = 0;
19
+ let paymentsAmount = 0;
20
+ let loyaltyPointsBalance = 0;
21
+ const paymentHistory = [];
22
+ const nextTransaction = async (index = 0) => {
23
+ const newTransaction = transactions[index];
24
+ // merge objects to create transaction request body
25
+ const transactionBody = {
26
+ ...checkoutBody,
27
+ transaction: newTransaction,
28
+ order_id: orderId,
29
+ order_number: orderNumber,
30
+ // also need shipping address
31
+ // send from shipping object if undefined on transaction object
32
+ to: { ...checkoutBody.shipping.to },
33
+ ...newTransaction,
34
+ amount: { ...amount },
35
+ };
36
+ newTransaction.amount_part = newTransaction.amount_part || 0;
37
+ if (transactionBody.amount && newTransaction.amount_part > 0
41
38
  && 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)
39
+ // fix amount for multiple transactions
40
+ const partialAmount = transactionBody.amount.total * newTransaction.amount_part;
41
+ transactionBody.amount.discount = transactionBody.amount.discount || 0;
42
+ transactionBody.amount.discount += transactionBody.amount.total - partialAmount;
43
+ transactionBody.amount.total = partialAmount;
44
+ if (transactionBody.payment_method.code === 'loyalty_points') {
45
+ loyaltyPointsBalance += partialAmount;
46
+ }
47
+ delete transactionBody.amount_part;
99
48
  }
100
- // check for transaction status
101
- if (!transaction.status) {
102
- transaction.status = {
103
- current: 'pending',
104
- };
49
+ // logger.log(JSON.stringify(transactionBody, null, 2))
50
+ // logger.log(JSON.stringify(checkoutBody, null, 2))
51
+ // finally pass to create transaction
52
+ let listTransactions = await requestModule(transactionBody, hostname, 'transaction');
53
+ if (listTransactions) {
54
+ listTransactions = getValidResults(listTransactions);
55
+ // simulateRequest(transactionBody, checkoutRespond, 'transaction', storeId, (results) => {
56
+ const isFirstTransaction = index === 0;
57
+ let isDone = false;
58
+ for (let i = 0; i < listTransactions.length; i++) {
59
+ const result = listTransactions[i];
60
+ // treat transaction response
61
+ const { response } = result;
62
+ const transaction = response && response.transaction;
63
+ if (transaction) {
64
+ // complete transaction object with some request body fields
65
+ [
66
+ 'type',
67
+ 'payment_method',
68
+ 'payer',
69
+ 'currency_id',
70
+ 'currency_symbol',
71
+ ].forEach((field) => {
72
+ if (transactionBody[field] !== undefined && transaction[field] === undefined) {
73
+ transaction[field] = transactionBody[field];
74
+ }
75
+ });
76
+ // setup transaction app object
77
+ if (!transaction.app) {
78
+ transaction.app = { _id: result._id };
79
+ // complete app object with some request body fields
80
+ const transactionOptions = Array.isArray(checkoutBody.transaction)
81
+ ? checkoutBody.transaction.find((transactionFound) => transactionFound.app_id === result._id)
82
+ : checkoutBody.transaction;
83
+ if (transactionOptions) {
84
+ [
85
+ 'label',
86
+ 'icon',
87
+ 'intermediator',
88
+ 'payment_url',
89
+ ].forEach((field) => {
90
+ if (transactionOptions[field] !== undefined && transaction.app) {
91
+ transaction.app[field] = transactionOptions[field];
92
+ }
93
+ });
94
+ }
95
+ // logger.log(transaction.app)
96
+ }
97
+ // check for transaction status
98
+ if (!transaction.status) {
99
+ transaction.status = {
100
+ current: 'pending',
101
+ };
102
+ }
103
+ transaction.status.updated_at = dateTime;
104
+ if (isFirstTransaction) {
105
+ // merge transaction body with order info and respond
106
+ return checkoutRespond(res, orderId, orderNumber, transaction);
107
+ }
108
+ // save transaction info on order data
109
+ // saveTransaction(transaction, orderId, storeId, (err, transactionId) => {
110
+ try {
111
+ // eslint-disable-next-line no-await-in-loop
112
+ const transactionId = await saveTransaction(accessToken, orderId, transaction);
113
+ // add entry to payments history
114
+ const paymentEntry = {
115
+ transaction_id: transactionId,
116
+ status: transaction.status.current,
117
+ date_time: dateTime,
118
+ flags: ['checkout'],
119
+ };
120
+ paymentHistory.push(paymentEntry);
121
+ try {
122
+ // eslint-disable-next-line no-await-in-loop
123
+ await addPaymentHistory(orderId, accessToken, paymentHistory, isFirstTransaction, paymentEntry, dateTime, loyaltyPointsBalance, amount);
124
+ }
125
+ catch (e) {
126
+ logger.error(e);
127
+ }
128
+ }
129
+ catch (e) {
130
+ logger.error(e);
131
+ }
132
+ index += 1;
133
+ if (index < transactions.length) {
134
+ return nextTransaction(index);
135
+ }
136
+ // });
137
+ isDone = true;
138
+ paymentsAmount += transaction.amount;
139
+ break;
140
+ }
141
+ }
142
+ if (isDone) {
143
+ countDone += 1;
144
+ if (countDone === transactions.length) {
145
+ if (amount.total / paymentsAmount > 1.01) {
146
+ return cancelOrder('Transaction amounts doesn\'t match (is lower) order total value', orderId, accessToken, isOrderCancelled, res, usrMsg);
147
+ }
148
+ }
149
+ // return
150
+ return checkoutRespond(res, orderId, orderNumber);
151
+ }
152
+ // unexpected response object from create transaction module
153
+ const firstResult = listTransactions && listTransactions[0];
154
+ let errorMessage;
155
+ if (firstResult) {
156
+ const { response } = firstResult;
157
+ if (response) {
158
+ // send devMsg with app response
159
+ if (response.message) {
160
+ errorMessage = response.message;
161
+ if (response.error) {
162
+ errorMessage += ` (${response.error})`;
163
+ }
164
+ }
165
+ else {
166
+ errorMessage = JSON.stringify(response);
167
+ }
168
+ }
169
+ else {
170
+ errorMessage = firstResult.error_message;
171
+ }
172
+ }
173
+ if (isFirstTransaction) {
174
+ return sendError(res, 409, 'CKT704', errorMessage || 'No valid transaction object', usrMsg);
175
+ }
176
+ return cancelOrder('Error trying to create transaction', orderId, accessToken, isOrderCancelled, res, usrMsg, errorMessage);
105
177
  }
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);
178
+ // send error no exist transaction
179
+ return sendError(res, 409, 'CKT704', 'There was a problem saving your order, please try again later', usrMsg);
180
+ };
181
+ return nextTransaction();
182
+ }
183
+ // send error
184
+ const userMessage = {
185
+ en_us: 'There was a problem saving your order, please try again later',
186
+ pt_br: 'Houve um problema ao salvar o pedido, por favor tente novamente mais tarde',
179
187
  };
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
+ return sendError(res, 409, 'CKT701', 'There was a problem saving your order, please try again later', userMessage);
188
189
  };
189
-
190
190
  export default createOrder;
191
- // # sourceMappingURL=new-order.js.map
191
+ //# sourceMappingURL=new-order.js.map