n8n-nodes-mercadopago-pix-assinatura 1.0.3 → 1.0.5

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
- const resource = this.getNodeParameter('resource', i);
726
- const operation = this.getNodeParameter('operation', i);
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':
@@ -891,10 +902,13 @@ class PixPayment {
891
902
  }
892
903
  }
893
904
  static async createPlan(executeFunctions, itemIndex, baseUrl, credentials) {
894
- const reason = executeFunctions.getNodeParameter('reason', itemIndex);
895
- const amount = executeFunctions.getNodeParameter('amount', itemIndex);
896
- const frequency = executeFunctions.getNodeParameter('frequency', itemIndex);
897
- const frequencyType = executeFunctions.getNodeParameter('frequencyType', itemIndex);
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');
909
+ // Normaliza valores numéricos (converte vírgula para ponto)
910
+ const amount = (0, helpers_1.normalizeNumericValue)(amountRaw);
911
+ const frequency = (0, helpers_1.normalizeNumericValue)(frequencyRaw);
898
912
  if (!reason || reason.trim() === '') {
899
913
  throw new Error('Nome do plano é obrigatório');
900
914
  }
@@ -960,12 +974,14 @@ class PixPayment {
960
974
  return response;
961
975
  }
962
976
  static async updatePlan(executeFunctions, itemIndex, baseUrl, credentials) {
963
- const planId = executeFunctions.getNodeParameter('planId', itemIndex);
964
- const reason = executeFunctions.getNodeParameter('reason', itemIndex);
965
- const amount = executeFunctions.getNodeParameter('amount', itemIndex);
977
+ const planId = (0, helpers_1.getNodeParameterSafe)(executeFunctions.getNodeParameter.bind(executeFunctions), 'planId', itemIndex, '');
978
+ const reason = (0, helpers_1.getNodeParameterSafe)(executeFunctions.getNodeParameter.bind(executeFunctions), 'reason', itemIndex, '');
979
+ const amountRaw = (0, helpers_1.getNodeParameterSafe)(executeFunctions.getNodeParameter.bind(executeFunctions), 'amount', itemIndex, 0);
966
980
  if (!planId || planId.trim() === '') {
967
981
  throw new Error('ID do plano é obrigatório');
968
982
  }
983
+ // Normaliza valor numérico (converte vírgula para ponto)
984
+ const amount = (0, helpers_1.normalizeNumericValue)(amountRaw);
969
985
  const body = {};
970
986
  if (reason && reason.trim() !== '') {
971
987
  body.reason = reason;
@@ -36,3 +36,14 @@ export declare function getDocumentType(document: string): 'CPF' | 'CNPJ' | null
36
36
  * Valida se o email tem formato válido
37
37
  */
38
38
  export declare function validateEmail(email: string): boolean;
39
+ /**
40
+ * Normaliza valores numéricos convertendo vírgula para ponto decimal
41
+ * Aceita string ou number e retorna number
42
+ * Exemplo: "14,9" -> 14.9, "14.9" -> 14.9
43
+ */
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.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
  */
@@ -105,3 +105,39 @@ function validateEmail(email) {
105
105
  return emailRegex.test(email);
106
106
  }
107
107
  exports.validateEmail = validateEmail;
108
+ /**
109
+ * Normaliza valores numéricos convertendo vírgula para ponto decimal
110
+ * Aceita string ou number e retorna number
111
+ * Exemplo: "14,9" -> 14.9, "14.9" -> 14.9
112
+ */
113
+ function normalizeNumericValue(value) {
114
+ if (value === undefined || value === null) {
115
+ return 0;
116
+ }
117
+ if (typeof value === 'number') {
118
+ return value;
119
+ }
120
+ // Converte string: substitui vírgula por ponto e remove espaços
121
+ const normalized = String(value).trim().replace(',', '.');
122
+ const parsed = parseFloat(normalized);
123
+ return isNaN(parsed) ? 0 : parsed;
124
+ }
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",
3
+ "version": "1.0.5",
4
4
  "description": "n8n node para processamento de pagamentos PIX e assinaturas via Mercado Pago",
5
5
  "keywords": [
6
6
  "n8n",