n8n-nodes-mercadopago-pix-assinatura 1.0.2 → 1.0.4
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.
|
@@ -237,6 +237,154 @@ class PixPayment {
|
|
|
237
237
|
default: 0,
|
|
238
238
|
description: 'Valor do reembolso em reais (deixe vazio para reembolso total)',
|
|
239
239
|
},
|
|
240
|
+
// Plan Operations
|
|
241
|
+
{
|
|
242
|
+
displayName: 'Operation',
|
|
243
|
+
name: 'operation',
|
|
244
|
+
type: 'options',
|
|
245
|
+
noDataExpression: true,
|
|
246
|
+
displayOptions: {
|
|
247
|
+
show: {
|
|
248
|
+
resource: ['plans'],
|
|
249
|
+
},
|
|
250
|
+
},
|
|
251
|
+
options: [
|
|
252
|
+
{
|
|
253
|
+
name: 'Criar',
|
|
254
|
+
value: 'create',
|
|
255
|
+
description: 'Criar um plano de assinatura',
|
|
256
|
+
action: 'Criar plano',
|
|
257
|
+
},
|
|
258
|
+
{
|
|
259
|
+
name: 'Consultar',
|
|
260
|
+
value: 'get',
|
|
261
|
+
description: 'Consultar um plano',
|
|
262
|
+
action: 'Consultar plano',
|
|
263
|
+
},
|
|
264
|
+
{
|
|
265
|
+
name: 'Listar',
|
|
266
|
+
value: 'list',
|
|
267
|
+
description: 'Listar planos',
|
|
268
|
+
action: 'Listar planos',
|
|
269
|
+
},
|
|
270
|
+
{
|
|
271
|
+
name: 'Atualizar',
|
|
272
|
+
value: 'update',
|
|
273
|
+
description: 'Atualizar um plano',
|
|
274
|
+
action: 'Atualizar plano',
|
|
275
|
+
},
|
|
276
|
+
],
|
|
277
|
+
default: 'create',
|
|
278
|
+
},
|
|
279
|
+
// Plan Create Fields
|
|
280
|
+
{
|
|
281
|
+
displayName: 'Nome do Plano',
|
|
282
|
+
name: 'reason',
|
|
283
|
+
type: 'string',
|
|
284
|
+
required: true,
|
|
285
|
+
displayOptions: {
|
|
286
|
+
show: {
|
|
287
|
+
resource: ['plans'],
|
|
288
|
+
operation: ['create'],
|
|
289
|
+
},
|
|
290
|
+
},
|
|
291
|
+
default: '',
|
|
292
|
+
description: 'Nome/descrição do plano',
|
|
293
|
+
},
|
|
294
|
+
{
|
|
295
|
+
displayName: 'Valor',
|
|
296
|
+
name: 'amount',
|
|
297
|
+
type: 'number',
|
|
298
|
+
required: true,
|
|
299
|
+
displayOptions: {
|
|
300
|
+
show: {
|
|
301
|
+
resource: ['plans'],
|
|
302
|
+
operation: ['create'],
|
|
303
|
+
},
|
|
304
|
+
},
|
|
305
|
+
default: 0,
|
|
306
|
+
description: 'Valor do plano em reais (ex: 99.99)',
|
|
307
|
+
},
|
|
308
|
+
{
|
|
309
|
+
displayName: 'Frequência',
|
|
310
|
+
name: 'frequency',
|
|
311
|
+
type: 'number',
|
|
312
|
+
required: true,
|
|
313
|
+
displayOptions: {
|
|
314
|
+
show: {
|
|
315
|
+
resource: ['plans'],
|
|
316
|
+
operation: ['create'],
|
|
317
|
+
},
|
|
318
|
+
},
|
|
319
|
+
default: 1,
|
|
320
|
+
description: 'Frequência de cobrança (ex: 1 para mensal)',
|
|
321
|
+
},
|
|
322
|
+
{
|
|
323
|
+
displayName: 'Tipo de Frequência',
|
|
324
|
+
name: 'frequencyType',
|
|
325
|
+
type: 'options',
|
|
326
|
+
required: true,
|
|
327
|
+
displayOptions: {
|
|
328
|
+
show: {
|
|
329
|
+
resource: ['plans'],
|
|
330
|
+
operation: ['create'],
|
|
331
|
+
},
|
|
332
|
+
},
|
|
333
|
+
options: [
|
|
334
|
+
{
|
|
335
|
+
name: 'Dias',
|
|
336
|
+
value: 'days',
|
|
337
|
+
},
|
|
338
|
+
{
|
|
339
|
+
name: 'Meses',
|
|
340
|
+
value: 'months',
|
|
341
|
+
},
|
|
342
|
+
],
|
|
343
|
+
default: 'months',
|
|
344
|
+
description: 'Tipo de frequência (dias ou meses)',
|
|
345
|
+
},
|
|
346
|
+
// Plan Get/Update Fields
|
|
347
|
+
{
|
|
348
|
+
displayName: 'ID do Plano',
|
|
349
|
+
name: 'planId',
|
|
350
|
+
type: 'string',
|
|
351
|
+
required: true,
|
|
352
|
+
displayOptions: {
|
|
353
|
+
show: {
|
|
354
|
+
resource: ['plans'],
|
|
355
|
+
operation: ['get', 'update'],
|
|
356
|
+
},
|
|
357
|
+
},
|
|
358
|
+
default: '',
|
|
359
|
+
description: 'ID do plano',
|
|
360
|
+
},
|
|
361
|
+
// Plan Update Fields
|
|
362
|
+
{
|
|
363
|
+
displayName: 'Nome do Plano',
|
|
364
|
+
name: 'reason',
|
|
365
|
+
type: 'string',
|
|
366
|
+
displayOptions: {
|
|
367
|
+
show: {
|
|
368
|
+
resource: ['plans'],
|
|
369
|
+
operation: ['update'],
|
|
370
|
+
},
|
|
371
|
+
},
|
|
372
|
+
default: '',
|
|
373
|
+
description: 'Novo nome/descrição do plano',
|
|
374
|
+
},
|
|
375
|
+
{
|
|
376
|
+
displayName: 'Valor',
|
|
377
|
+
name: 'amount',
|
|
378
|
+
type: 'number',
|
|
379
|
+
displayOptions: {
|
|
380
|
+
show: {
|
|
381
|
+
resource: ['plans'],
|
|
382
|
+
operation: ['update'],
|
|
383
|
+
},
|
|
384
|
+
},
|
|
385
|
+
default: 0,
|
|
386
|
+
description: 'Novo valor do plano em reais',
|
|
387
|
+
},
|
|
240
388
|
// Subscription Operations
|
|
241
389
|
{
|
|
242
390
|
displayName: 'Operation',
|
|
@@ -743,10 +891,13 @@ class PixPayment {
|
|
|
743
891
|
}
|
|
744
892
|
}
|
|
745
893
|
static async createPlan(executeFunctions, itemIndex, baseUrl, credentials) {
|
|
746
|
-
const reason = executeFunctions.getNodeParameter('reason', itemIndex);
|
|
747
|
-
const
|
|
748
|
-
const
|
|
749
|
-
const frequencyType = executeFunctions.getNodeParameter('frequencyType', itemIndex);
|
|
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');
|
|
898
|
+
// Normaliza valores numéricos (converte vírgula para ponto)
|
|
899
|
+
const amount = (0, helpers_1.normalizeNumericValue)(amountRaw);
|
|
900
|
+
const frequency = (0, helpers_1.normalizeNumericValue)(frequencyRaw);
|
|
750
901
|
if (!reason || reason.trim() === '') {
|
|
751
902
|
throw new Error('Nome do plano é obrigatório');
|
|
752
903
|
}
|
|
@@ -812,12 +963,14 @@ class PixPayment {
|
|
|
812
963
|
return response;
|
|
813
964
|
}
|
|
814
965
|
static async updatePlan(executeFunctions, itemIndex, baseUrl, credentials) {
|
|
815
|
-
const planId = executeFunctions.getNodeParameter('planId', itemIndex);
|
|
816
|
-
const reason = executeFunctions.getNodeParameter('reason', itemIndex);
|
|
817
|
-
const
|
|
966
|
+
const planId = executeFunctions.getNodeParameter('planId', itemIndex, '');
|
|
967
|
+
const reason = executeFunctions.getNodeParameter('reason', itemIndex, '');
|
|
968
|
+
const amountRaw = executeFunctions.getNodeParameter('amount', itemIndex, 0);
|
|
818
969
|
if (!planId || planId.trim() === '') {
|
|
819
970
|
throw new Error('ID do plano é obrigatório');
|
|
820
971
|
}
|
|
972
|
+
// Normaliza valor numérico (converte vírgula para ponto)
|
|
973
|
+
const amount = (0, helpers_1.normalizeNumericValue)(amountRaw);
|
|
821
974
|
const body = {};
|
|
822
975
|
if (reason && reason.trim() !== '') {
|
|
823
976
|
body.reason = reason;
|
|
@@ -36,3 +36,9 @@ 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;
|
|
@@ -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.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,21 @@ 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;
|