@cloudcommerce/app-pagarme-v5 2.41.3 → 2.41.6
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 =
|
|
21
|
+
let queryString = `transactions.intermediator.transaction_id=${invoiceId}`;
|
|
22
22
|
queryString += '&fields=transactions,financial_status.current,status';
|
|
23
|
-
const data = await api.get(`orders
|
|
24
|
-
|
|
25
|
-
return data?.result.length ? data?.result[0] : null;
|
|
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
|
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { getFirestore } from 'firebase-admin/firestore';
|
|
2
|
-
import config from '@cloudcommerce/firebase/lib/config';
|
|
3
2
|
import api from '@cloudcommerce/api';
|
|
4
|
-
import logger from 'firebase
|
|
3
|
+
import { logger } from '@cloudcommerce/firebase/lib/config';
|
|
4
|
+
import getAppData from '@cloudcommerce/firebase/lib/helpers/get-app-data';
|
|
5
5
|
import axios from './functions-lib/pagarme/create-axios.mjs';
|
|
6
6
|
import {
|
|
7
7
|
getOrderById,
|
|
@@ -14,27 +14,13 @@ import {
|
|
|
14
14
|
} from './functions-lib/api-utils.mjs';
|
|
15
15
|
import { parserChangeStatusToEcom } from './functions-lib/pagarme/parses-utils.mjs';
|
|
16
16
|
|
|
17
|
-
const getAppData = async () => {
|
|
18
|
-
return new Promise((resolve, reject) => {
|
|
19
|
-
api.get(
|
|
20
|
-
`applications?app_id=${config.get().apps.pagarMeV5.appId}&fields=hidden_data`,
|
|
21
|
-
)
|
|
22
|
-
.then(({ data: result }) => {
|
|
23
|
-
resolve(result[0]);
|
|
24
|
-
})
|
|
25
|
-
.catch((err) => {
|
|
26
|
-
reject(err);
|
|
27
|
-
});
|
|
28
|
-
});
|
|
29
|
-
};
|
|
30
|
-
|
|
31
17
|
const handleWehook = async (req, res) => {
|
|
32
18
|
const colletionFirebase = getFirestore().collection('pagarmeV5Subscriptions');
|
|
33
19
|
const { body } = req;
|
|
34
20
|
|
|
35
21
|
try {
|
|
36
22
|
const type = body.type;
|
|
37
|
-
const appData = await getAppData();
|
|
23
|
+
const appData = await getAppData('pagarMeV5');
|
|
38
24
|
|
|
39
25
|
if (!process.env.PAGARMEV5_API_TOKEN) {
|
|
40
26
|
const pagarmeApiToken = appData.pagarme_api_token;
|
|
@@ -42,7 +28,6 @@ const handleWehook = async (req, res) => {
|
|
|
42
28
|
process.env.PAGARMEV5_API_TOKEN = pagarmeApiToken;
|
|
43
29
|
} else {
|
|
44
30
|
logger.warn('Missing PAGARMEV5 API TOKEN');
|
|
45
|
-
|
|
46
31
|
return res.status(401)
|
|
47
32
|
.send({
|
|
48
33
|
error: 'NO_PAGARME_KEYS',
|
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.6",
|
|
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.6",
|
|
35
|
+
"@cloudcommerce/firebase": "2.41.6"
|
|
36
36
|
},
|
|
37
37
|
"devDependencies": {
|
|
38
|
-
"@cloudcommerce/
|
|
39
|
-
"@cloudcommerce/
|
|
38
|
+
"@cloudcommerce/test-base": "2.41.6",
|
|
39
|
+
"@cloudcommerce/types": "2.41.6"
|
|
40
40
|
},
|
|
41
41
|
"scripts": {
|
|
42
42
|
"build": "bash scripts/build.sh",
|