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.
Files changed (55) hide show
  1. package/CHANGELOG.md +7 -0
  2. package/package.json +1 -1
  3. package/packages/api/package.json +1 -1
  4. package/packages/apps/correios/package.json +1 -1
  5. package/packages/apps/custom-shipping/package.json +1 -1
  6. package/packages/apps/discounts/package.json +1 -1
  7. package/packages/apps/frenet/package.json +1 -1
  8. package/packages/apps/tiny-erp/lib/event-to-tiny.js +94 -94
  9. package/packages/apps/tiny-erp/lib/index.js +1 -1
  10. package/packages/apps/tiny-erp/lib/integration/after-tiny-queue.js +71 -74
  11. package/packages/apps/tiny-erp/lib/integration/export-order-to-tiny.js +70 -73
  12. package/packages/apps/tiny-erp/lib/integration/export-product-to-tiny.js +49 -53
  13. package/packages/apps/tiny-erp/lib/integration/helpers/format-tiny-date.js +3 -3
  14. package/packages/apps/tiny-erp/lib/integration/import-order-from-tiny.js +76 -75
  15. package/packages/apps/tiny-erp/lib/integration/import-product-from-tiny.js +137 -140
  16. package/packages/apps/tiny-erp/lib/integration/parsers/order-from-tiny.js +40 -39
  17. package/packages/apps/tiny-erp/lib/integration/parsers/order-to-tiny.js +173 -178
  18. package/packages/apps/tiny-erp/lib/integration/parsers/product-from-tiny.js +173 -171
  19. package/packages/apps/tiny-erp/lib/integration/parsers/product-to-tiny.js +123 -127
  20. package/packages/apps/tiny-erp/lib/integration/parsers/status-from-tiny.js +32 -32
  21. package/packages/apps/tiny-erp/lib/integration/parsers/status-to-tiny.js +37 -37
  22. package/packages/apps/tiny-erp/lib/integration/post-tiny-erp.js +42 -43
  23. package/packages/apps/tiny-erp/lib/tiny-erp.js +8 -6
  24. package/packages/apps/tiny-erp/lib/tiny-webhook.js +76 -73
  25. package/packages/apps/tiny-erp/package.json +1 -1
  26. package/packages/cli/package.json +1 -1
  27. package/packages/config/package.json +1 -1
  28. package/packages/events/package.json +1 -1
  29. package/packages/firebase/package.json +1 -1
  30. package/packages/modules/lib/firebase/ajv.js +24 -19
  31. package/packages/modules/lib/firebase/call-app-module.js +110 -116
  32. package/packages/modules/lib/firebase/checkout.js +152 -151
  33. package/packages/modules/lib/firebase/functions-checkout/fix-items.js +187 -194
  34. package/packages/modules/lib/firebase/functions-checkout/get-custumerId.js +26 -25
  35. package/packages/modules/lib/firebase/functions-checkout/handle-order-transaction.js +109 -110
  36. package/packages/modules/lib/firebase/functions-checkout/new-order.js +177 -177
  37. package/packages/modules/lib/firebase/functions-checkout/request-to-module.js +59 -59
  38. package/packages/modules/lib/firebase/functions-checkout/utils.js +197 -195
  39. package/packages/modules/lib/firebase/handle-module.js +146 -144
  40. package/packages/modules/lib/firebase/proxy-apps.js +1 -2
  41. package/packages/modules/lib/firebase/serve-modules-api.js +53 -52
  42. package/packages/modules/lib/firebase.js +6 -4
  43. package/packages/modules/lib/index.js +15 -12
  44. package/packages/modules/package.json +1 -1
  45. package/packages/passport/package.json +1 -1
  46. package/packages/ssr/package.json +1 -1
  47. package/packages/storefront/astro.config.mjs +1 -1
  48. package/packages/storefront/dist/client/{LoginOffcanvas.daf3f717.js → LoginOffcanvas.c2faa1dc.js} +1 -1
  49. package/packages/storefront/dist/client/chunks/{LoginForm.d9251274.js → LoginForm.3bcb85fb.js} +10 -10
  50. package/packages/storefront/dist/client/chunks/{LoginOffcanvas.07fe6492.js → LoginOffcanvas.e48f274b.js} +1 -1
  51. package/packages/storefront/dist/client/sw.js +1 -1
  52. package/packages/storefront/dist/server/entry.mjs +2 -2
  53. package/packages/storefront/package.json +2 -2
  54. package/packages/storefront/tsconfig.json +1 -1
  55. package/packages/types/package.json +1 -1
@@ -1,124 +1,123 @@
1
1
  import { logger } from 'firebase-functions';
2
2
  import api from '@cloudcommerce/api';
3
3
  import { sendError } from './utils.js';
4
+
4
5
  const checkoutRespond = (res, orderId, orderNumber, transaction) => {
5
- return res.send({
6
- status: 200,
7
- order: {
8
- _id: orderId,
9
- number: orderNumber,
10
- },
11
- transaction,
12
- });
6
+ return res.send({
7
+ status: 200,
8
+ order: {
9
+ _id: orderId,
10
+ number: orderNumber,
11
+ },
12
+ transaction,
13
+ });
13
14
  };
14
15
  const newOrder = async (orderBody, accessToken) => {
15
- try {
16
- const orderId = (await api.post('orders', orderBody, {
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}`, {
17
24
  accessToken,
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
- }
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
+ }
38
37
  };
39
38
  const cancelOrder = async (staffNotes, orderId, accessToken, isOrderCancelled, res, usrMsg, errorMessage) => {
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);
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);
70
68
  };
71
69
  const saveTransaction = (accessToken, orderId, transactionBody) => {
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
- });
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
+ });
83
81
  };
84
82
  const addPaymentHistory = async (orderId, accessToken, paymentHistory, isFirstTransaction, paymentEntry, dateTime, loyaltyPointsBalance, amount) => {
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
- });
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
122
  };
123
- export { newOrder, cancelOrder, saveTransaction, addPaymentHistory, checkoutRespond, };
124
- //# sourceMappingURL=handle-order-transaction.js.map
123
+ // # 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 { newOrder, cancelOrder, saveTransaction, addPaymentHistory, checkoutRespond, } from './handle-order-transaction.js';
3
+ import {
4
+ newOrder, cancelOrder, saveTransaction, addPaymentHistory, checkoutRespond,
5
+ } from './handle-order-transaction.js';
4
6
  import requestModule from './request-to-module.js';
7
+
5
8
  const usrMsg = {
6
- en_us: 'Your order was saved, but we were unable to make the payment, '
9
+ en_us: 'Your order was saved, but we were unable to make the payment, '
7
10
  + 'please contact us',
8
- pt_br: 'Seu pedido foi salvo, mas não conseguimos efetuar o pagamento, '
11
+ pt_br: 'Seu pedido foi salvo, mas não conseguimos efetuar o pagamento, '
9
12
  + 'por favor entre em contato',
10
13
  };
11
14
  const createOrder = async (res, accessToken, hostname, amount, checkoutBody, orderBody, transactions, dateTime) => {
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
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
38
41
  && newTransaction.amount_part < 1) {
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;
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)
48
99
  }
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);
100
+ // check for transaction status
101
+ if (!transaction.status) {
102
+ transaction.status = {
103
+ current: 'pending',
104
+ };
177
105
  }
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',
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);
187
179
  };
188
- return sendError(res, 409, 'CKT701', 'There was a problem saving your order, please try again later', userMessage);
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);
189
188
  };
189
+
190
190
  export default createOrder;
191
- //# sourceMappingURL=new-order.js.map
191
+ // # sourceMappingURL=new-order.js.map