@cloudcommerce/app-pagarme-v5 2.41.5 → 2.41.7
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.
|
@@ -4,7 +4,6 @@ import logger from 'firebase-functions/logger';
|
|
|
4
4
|
import { getFirestore } from 'firebase-admin/firestore';
|
|
5
5
|
import ecomUtils from '@ecomplus/utils';
|
|
6
6
|
import axios from './functions-lib/pagarme/create-axios.mjs';
|
|
7
|
-
import { getOrderWithQueryString } from './functions-lib/api-utils.mjs';
|
|
8
7
|
import { getDocFirestore } from './functions-lib/firestore-utils.mjs';
|
|
9
8
|
|
|
10
9
|
const colletionFirebase = getFirestore().collection('pagarmeV5Subscriptions');
|
|
@@ -32,8 +31,11 @@ const eventOrderCancelled = async (
|
|
|
32
31
|
return null;
|
|
33
32
|
} catch (err) {
|
|
34
33
|
logger.error(err);
|
|
35
|
-
|
|
36
|
-
.
|
|
34
|
+
try {
|
|
35
|
+
await api.patch(order._id, { status: 'open' });
|
|
36
|
+
} catch (_err) {
|
|
37
|
+
logger.error(_err);
|
|
38
|
+
}
|
|
37
39
|
return null;
|
|
38
40
|
}
|
|
39
41
|
} else {
|
|
@@ -55,8 +57,7 @@ const eventProducts = async (
|
|
|
55
57
|
let query = 'status!=cancelled&transactions.type=recurrence';
|
|
56
58
|
query += '&transactions.app.intermediator.code=pagarme';
|
|
57
59
|
query += `&items.product_id=${product._id}`;
|
|
58
|
-
|
|
59
|
-
const result = await getOrderWithQueryString(query);
|
|
60
|
+
const { data: { result } } = await api.get(`orders?${query}`);
|
|
60
61
|
|
|
61
62
|
if (result && result.length) {
|
|
62
63
|
let i = 0;
|
|
@@ -11,18 +11,17 @@ const addPaymentHistory = async (orderId, body) => {
|
|
|
11
11
|
};
|
|
12
12
|
|
|
13
13
|
const updateTransaction = (orderId, body, transactionId) => {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
return api
|
|
14
|
+
if (transactionId) {
|
|
15
|
+
return api.patch(`orders/${orderId}/transactions/${transactionId}`, body);
|
|
16
|
+
}
|
|
17
|
+
return api.post(`orders/${orderId}/transactions`, body);
|
|
18
18
|
};
|
|
19
19
|
|
|
20
20
|
const getOrderIntermediatorTransactionId = async (invoiceId) => {
|
|
21
|
-
let queryString =
|
|
22
|
-
queryString += '&fields=transactions,financial_status
|
|
23
|
-
const data = await api.get(`orders
|
|
24
|
-
|
|
25
|
-
return data?.result.length ? data?.result[0] : null;
|
|
21
|
+
let queryString = `transactions.intermediator.transaction_id=${invoiceId}`;
|
|
22
|
+
queryString += '&fields=transactions,financial_status,status';
|
|
23
|
+
const { data } = await api.get(`orders?${queryString}`);
|
|
24
|
+
return data.result[0] || null;
|
|
26
25
|
};
|
|
27
26
|
|
|
28
27
|
const checkItemsAndRecalculeteOrder = (amount, items, plan, itemsPagarme) => {
|
|
@@ -154,17 +153,6 @@ const createNewOrderBasedOld = (oldOrder, plan, status, charge, subscriptionPaga
|
|
|
154
153
|
return api.post('orders', body);
|
|
155
154
|
};
|
|
156
155
|
|
|
157
|
-
const getOrderWithQueryString = async (query) => {
|
|
158
|
-
const { data } = await api.get(`orders?${query}`);
|
|
159
|
-
|
|
160
|
-
return data?.result.length ? data?.result : null;
|
|
161
|
-
};
|
|
162
|
-
|
|
163
|
-
const getProductById = async (productId) => {
|
|
164
|
-
const { data } = await api.get(`products/${productId}`);
|
|
165
|
-
return data;
|
|
166
|
-
};
|
|
167
|
-
|
|
168
156
|
const checkItemCategory = async (categoryIds, itemsPagarme, itemsApi) => {
|
|
169
157
|
let i = 0;
|
|
170
158
|
|
|
@@ -178,7 +166,7 @@ const checkItemCategory = async (categoryIds, itemsPagarme, itemsApi) => {
|
|
|
178
166
|
|
|
179
167
|
if (itemFound && !isItemFreigth) {
|
|
180
168
|
// eslint-disable-next-line no-await-in-loop
|
|
181
|
-
const product = await
|
|
169
|
+
const { data: product } = await api.get(`products/${itemFound.product_id}`);
|
|
182
170
|
if (product.categories) {
|
|
183
171
|
let canSign = false;
|
|
184
172
|
product.categories.forEach((category) => {
|
|
@@ -210,7 +198,5 @@ export {
|
|
|
210
198
|
updateTransaction,
|
|
211
199
|
getOrderIntermediatorTransactionId,
|
|
212
200
|
createNewOrderBasedOld,
|
|
213
|
-
getOrderWithQueryString,
|
|
214
|
-
getProductById,
|
|
215
201
|
checkItemCategory,
|
|
216
202
|
};
|
|
@@ -156,7 +156,7 @@ const handleWehook = async (req, res) => {
|
|
|
156
156
|
const { invoice, status } = charge;
|
|
157
157
|
const order = await getOrderIntermediatorTransactionId(invoice.id);
|
|
158
158
|
if (order) {
|
|
159
|
-
if (order.financial_status
|
|
159
|
+
if (order.financial_status?.current !== parserChangeStatusToEcom(status)) {
|
|
160
160
|
// updadte status
|
|
161
161
|
const transaction = order.transactions
|
|
162
162
|
.find(
|
|
@@ -247,7 +247,7 @@ const handleWehook = async (req, res) => {
|
|
|
247
247
|
const { order: orderPagarme, status } = charge;
|
|
248
248
|
const order = await getOrderIntermediatorTransactionId(orderPagarme.id);
|
|
249
249
|
if (order) {
|
|
250
|
-
if (order.financial_status
|
|
250
|
+
if (order.financial_status?.current !== parserChangeStatusToEcom(status)) {
|
|
251
251
|
// updadte status
|
|
252
252
|
let isUpdateTransaction = false;
|
|
253
253
|
let transactionBody;
|
|
@@ -286,12 +286,12 @@ const handleWehook = async (req, res) => {
|
|
|
286
286
|
.catch(logger.error);
|
|
287
287
|
}
|
|
288
288
|
logger.log(`>> Status update to ${parserChangeStatusToEcom(status)}`);
|
|
289
|
-
return res.sendStatus(
|
|
289
|
+
return res.sendStatus(201);
|
|
290
290
|
}
|
|
291
|
+
return res.sendStatus(200);
|
|
291
292
|
}
|
|
292
293
|
return res.sendStatus(404);
|
|
293
294
|
}
|
|
294
|
-
|
|
295
295
|
return res.sendStatus(405);
|
|
296
296
|
}
|
|
297
297
|
return res.sendStatus(405);
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cloudcommerce/app-pagarme-v5",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "2.41.
|
|
4
|
+
"version": "2.41.7",
|
|
5
5
|
"description": "e-com.plus Cloud Commerce app to integrate Pagar.me API v5 with recurring payments",
|
|
6
6
|
"main": "lib/index.js",
|
|
7
7
|
"exports": {
|
|
@@ -31,12 +31,12 @@
|
|
|
31
31
|
"axios": "^1.8.4",
|
|
32
32
|
"firebase-admin": "^13.2.0",
|
|
33
33
|
"firebase-functions": "^6.3.2",
|
|
34
|
-
"@cloudcommerce/api": "2.41.
|
|
35
|
-
"@cloudcommerce/firebase": "2.41.
|
|
34
|
+
"@cloudcommerce/api": "2.41.7",
|
|
35
|
+
"@cloudcommerce/firebase": "2.41.7"
|
|
36
36
|
},
|
|
37
37
|
"devDependencies": {
|
|
38
|
-
"@cloudcommerce/types": "2.41.
|
|
39
|
-
"@cloudcommerce/test-base": "2.41.
|
|
38
|
+
"@cloudcommerce/types": "2.41.7",
|
|
39
|
+
"@cloudcommerce/test-base": "2.41.7"
|
|
40
40
|
},
|
|
41
41
|
"scripts": {
|
|
42
42
|
"build": "bash scripts/build.sh",
|