n8n-nodes-mercadopago-pix-assinatura 1.0.4 → 1.0.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.
|
@@ -722,8 +722,19 @@ class PixPayment {
|
|
|
722
722
|
const baseUrl = (0, helpers_1.getBaseUrl)(credentials.environment);
|
|
723
723
|
for (let i = 0; i < items.length; i++) {
|
|
724
724
|
try {
|
|
725
|
-
|
|
726
|
-
|
|
725
|
+
let resource;
|
|
726
|
+
let operation;
|
|
727
|
+
try {
|
|
728
|
+
resource = this.getNodeParameter('resource', i);
|
|
729
|
+
operation = this.getNodeParameter('operation', i);
|
|
730
|
+
}
|
|
731
|
+
catch (error) {
|
|
732
|
+
if (error?.message?.includes('Could not get parameter')) {
|
|
733
|
+
throw new Error(`Erro ao obter parâmetros do node. Verifique se os campos "Resource" e "Operation" estão preenchidos corretamente. ` +
|
|
734
|
+
`Detalhes: ${error.message}`);
|
|
735
|
+
}
|
|
736
|
+
throw error;
|
|
737
|
+
}
|
|
727
738
|
let responseData;
|
|
728
739
|
switch (resource) {
|
|
729
740
|
case 'pix':
|
|
@@ -827,7 +838,7 @@ class PixPayment {
|
|
|
827
838
|
Authorization: `Bearer ${credentials.accessToken}`,
|
|
828
839
|
'Content-Type': 'application/json',
|
|
829
840
|
};
|
|
830
|
-
if (idempotencyKey) {
|
|
841
|
+
if (idempotencyKey && idempotencyKey.trim() !== '') {
|
|
831
842
|
headers['X-Idempotency-Key'] = idempotencyKey;
|
|
832
843
|
}
|
|
833
844
|
const response = await executeFunctions.helpers.requestWithAuthentication.call(executeFunctions, 'pixPaymentApi', {
|
|
@@ -891,10 +902,10 @@ class PixPayment {
|
|
|
891
902
|
}
|
|
892
903
|
}
|
|
893
904
|
static async createPlan(executeFunctions, itemIndex, baseUrl, credentials) {
|
|
894
|
-
const reason = executeFunctions.getNodeParameter('reason', itemIndex, '');
|
|
895
|
-
const amountRaw = executeFunctions.getNodeParameter('amount', itemIndex, 0);
|
|
896
|
-
const frequencyRaw = executeFunctions.getNodeParameter('frequency', itemIndex, 1);
|
|
897
|
-
const frequencyType = executeFunctions.getNodeParameter('frequencyType', itemIndex, 'months');
|
|
905
|
+
const reason = (0, helpers_1.getNodeParameterSafe)(executeFunctions.getNodeParameter.bind(executeFunctions), 'reason', itemIndex, '');
|
|
906
|
+
const amountRaw = (0, helpers_1.getNodeParameterSafe)(executeFunctions.getNodeParameter.bind(executeFunctions), 'amount', itemIndex, 0);
|
|
907
|
+
const frequencyRaw = (0, helpers_1.getNodeParameterSafe)(executeFunctions.getNodeParameter.bind(executeFunctions), 'frequency', itemIndex, 1);
|
|
908
|
+
const frequencyType = (0, helpers_1.getNodeParameterSafe)(executeFunctions.getNodeParameter.bind(executeFunctions), 'frequencyType', itemIndex, 'months');
|
|
898
909
|
// Normaliza valores numéricos (converte vírgula para ponto)
|
|
899
910
|
const amount = (0, helpers_1.normalizeNumericValue)(amountRaw);
|
|
900
911
|
const frequency = (0, helpers_1.normalizeNumericValue)(frequencyRaw);
|
|
@@ -923,6 +934,7 @@ class PixPayment {
|
|
|
923
934
|
{ id: 'credit_card' },
|
|
924
935
|
],
|
|
925
936
|
},
|
|
937
|
+
back_url: 'https://www.mercadopago.com.br',
|
|
926
938
|
};
|
|
927
939
|
const response = await executeFunctions.helpers.requestWithAuthentication.call(executeFunctions, 'pixPaymentApi', {
|
|
928
940
|
method: 'POST',
|
|
@@ -963,9 +975,9 @@ class PixPayment {
|
|
|
963
975
|
return response;
|
|
964
976
|
}
|
|
965
977
|
static async updatePlan(executeFunctions, itemIndex, baseUrl, credentials) {
|
|
966
|
-
const planId = executeFunctions.getNodeParameter('planId', itemIndex, '');
|
|
967
|
-
const reason = executeFunctions.getNodeParameter('reason', itemIndex, '');
|
|
968
|
-
const amountRaw = executeFunctions.getNodeParameter('amount', itemIndex, 0);
|
|
978
|
+
const planId = (0, helpers_1.getNodeParameterSafe)(executeFunctions.getNodeParameter.bind(executeFunctions), 'planId', itemIndex, '');
|
|
979
|
+
const reason = (0, helpers_1.getNodeParameterSafe)(executeFunctions.getNodeParameter.bind(executeFunctions), 'reason', itemIndex, '');
|
|
980
|
+
const amountRaw = (0, helpers_1.getNodeParameterSafe)(executeFunctions.getNodeParameter.bind(executeFunctions), 'amount', itemIndex, 0);
|
|
969
981
|
if (!planId || planId.trim() === '') {
|
|
970
982
|
throw new Error('ID do plano é obrigatório');
|
|
971
983
|
}
|
|
@@ -42,3 +42,8 @@ export declare function validateEmail(email: string): boolean;
|
|
|
42
42
|
* Exemplo: "14,9" -> 14.9, "14.9" -> 14.9
|
|
43
43
|
*/
|
|
44
44
|
export declare function normalizeNumericValue(value: string | number | undefined | null): number;
|
|
45
|
+
/**
|
|
46
|
+
* Obtém parâmetro do node de forma segura, retornando valor padrão em caso de erro
|
|
47
|
+
* Útil para parâmetros que podem não estar visíveis devido a displayOptions
|
|
48
|
+
*/
|
|
49
|
+
export declare function getNodeParameterSafe<T>(getNodeParameter: (name: string, itemIndex: number, fallback?: T) => T, name: string, itemIndex: number, fallback: T): T;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.normalizeNumericValue = exports.validateEmail = exports.getDocumentType = exports.cleanDocument = exports.handleMercadoPagoError = exports.formatDate = exports.validateCNPJ = exports.validateCPF = exports.normalizeAmount = exports.getBaseUrl = void 0;
|
|
3
|
+
exports.getNodeParameterSafe = exports.normalizeNumericValue = exports.validateEmail = exports.getDocumentType = exports.cleanDocument = exports.handleMercadoPagoError = exports.formatDate = exports.validateCNPJ = exports.validateCPF = exports.normalizeAmount = exports.getBaseUrl = void 0;
|
|
4
4
|
/**
|
|
5
5
|
* Retorna a URL base da API do Mercado Pago conforme o ambiente
|
|
6
6
|
*/
|
|
@@ -123,3 +123,21 @@ function normalizeNumericValue(value) {
|
|
|
123
123
|
return isNaN(parsed) ? 0 : parsed;
|
|
124
124
|
}
|
|
125
125
|
exports.normalizeNumericValue = normalizeNumericValue;
|
|
126
|
+
/**
|
|
127
|
+
* Obtém parâmetro do node de forma segura, retornando valor padrão em caso de erro
|
|
128
|
+
* Útil para parâmetros que podem não estar visíveis devido a displayOptions
|
|
129
|
+
*/
|
|
130
|
+
function getNodeParameterSafe(getNodeParameter, name, itemIndex, fallback) {
|
|
131
|
+
try {
|
|
132
|
+
return getNodeParameter(name, itemIndex, fallback);
|
|
133
|
+
}
|
|
134
|
+
catch (error) {
|
|
135
|
+
// Se o erro for "Could not get parameter", retorna o valor padrão
|
|
136
|
+
if (error?.message?.includes('Could not get parameter') || error?.message?.includes('parameter')) {
|
|
137
|
+
return fallback;
|
|
138
|
+
}
|
|
139
|
+
// Para outros erros, relança
|
|
140
|
+
throw error;
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
exports.getNodeParameterSafe = getNodeParameterSafe;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "n8n-nodes-mercadopago-pix-assinatura",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.6",
|
|
4
4
|
"description": "n8n node para processamento de pagamentos PIX e assinaturas via Mercado Pago",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"n8n",
|
|
@@ -40,6 +40,7 @@
|
|
|
40
40
|
"test:coverage": "jest --coverage",
|
|
41
41
|
"test:unit": "jest test/unit",
|
|
42
42
|
"test:integration": "jest test/integration",
|
|
43
|
+
"test:local": "ts-node test/local/index.ts",
|
|
43
44
|
"prepublishOnly": "npm run build"
|
|
44
45
|
},
|
|
45
46
|
"files": [
|
|
@@ -59,6 +60,8 @@
|
|
|
59
60
|
"@types/jest": "^30.0.0",
|
|
60
61
|
"@typescript-eslint/eslint-plugin": "^5.45.0",
|
|
61
62
|
"@typescript-eslint/parser": "^5.45.0",
|
|
63
|
+
"axios": "^1.6.0",
|
|
64
|
+
"dotenv": "^16.3.1",
|
|
62
65
|
"eslint": "^8.28.0",
|
|
63
66
|
"eslint-plugin-n8n-nodes-base": "~1.11.0",
|
|
64
67
|
"gulp": "^4.0.2",
|
|
@@ -67,6 +70,7 @@
|
|
|
67
70
|
"n8n-workflow": "*",
|
|
68
71
|
"prettier": "^2.8.0",
|
|
69
72
|
"ts-jest": "^29.4.6",
|
|
73
|
+
"ts-node": "^10.9.2",
|
|
70
74
|
"typescript": "~5.3.0"
|
|
71
75
|
},
|
|
72
76
|
"peerDependencies": {
|