n8n-nodes-mercadopago-pix-assinatura 1.0.7 → 1.0.8

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.
@@ -343,6 +343,193 @@ class PixPayment {
343
343
  default: "months",
344
344
  description: "Tipo de frequência (dias ou meses)",
345
345
  },
346
+ {
347
+ displayName: "Moeda",
348
+ name: "currencyId",
349
+ type: "options",
350
+ required: true,
351
+ displayOptions: {
352
+ show: {
353
+ resource: ["plans"],
354
+ operation: ["create"],
355
+ },
356
+ },
357
+ options: [
358
+ {
359
+ name: "BRL - Real Brasileiro",
360
+ value: "BRL",
361
+ },
362
+ {
363
+ name: "ARS - Peso Argentino",
364
+ value: "ARS",
365
+ },
366
+ {
367
+ name: "CLP - Peso Chileno",
368
+ value: "CLP",
369
+ },
370
+ {
371
+ name: "MXN - Peso Mexicano",
372
+ value: "MXN",
373
+ },
374
+ {
375
+ name: "COP - Peso Colombiano",
376
+ value: "COP",
377
+ },
378
+ {
379
+ name: "PEN - Sol Peruano",
380
+ value: "PEN",
381
+ },
382
+ {
383
+ name: "UYU - Peso Uruguaio",
384
+ value: "UYU",
385
+ },
386
+ ],
387
+ default: "BRL",
388
+ description: "Moeda do plano",
389
+ },
390
+ {
391
+ displayName: "URL de Retorno",
392
+ name: "backUrl",
393
+ type: "string",
394
+ required: true,
395
+ displayOptions: {
396
+ show: {
397
+ resource: ["plans"],
398
+ operation: ["create"],
399
+ },
400
+ },
401
+ default: "https://www.mercadopago.com.br",
402
+ description: "URL de retorno após o checkout",
403
+ },
404
+ {
405
+ displayName: "Número de Repetições",
406
+ name: "repetitions",
407
+ type: "number",
408
+ displayOptions: {
409
+ show: {
410
+ resource: ["plans"],
411
+ operation: ["create"],
412
+ },
413
+ },
414
+ default: 0,
415
+ description: "Número de ciclos da assinatura (deixe 0 ou vazio para assinatura ilimitada)",
416
+ },
417
+ {
418
+ displayName: "Dia do Mês para Cobrança",
419
+ name: "billingDay",
420
+ type: "number",
421
+ displayOptions: {
422
+ show: {
423
+ resource: ["plans"],
424
+ operation: ["create"],
425
+ },
426
+ },
427
+ default: 0,
428
+ description: "Dia do mês (1-28) em que a assinatura será cobrada",
429
+ },
430
+ {
431
+ displayName: "Cobrança Proporcional",
432
+ name: "billingDayProportional",
433
+ type: "boolean",
434
+ displayOptions: {
435
+ show: {
436
+ resource: ["plans"],
437
+ operation: ["create"],
438
+ },
439
+ },
440
+ default: false,
441
+ description: "Cobrar valor proporcional no primeiro ciclo baseado nos dias restantes",
442
+ },
443
+ {
444
+ displayName: "Frequência do Trial",
445
+ name: "freeTrialFrequency",
446
+ type: "number",
447
+ displayOptions: {
448
+ show: {
449
+ resource: ["plans"],
450
+ operation: ["create"],
451
+ },
452
+ },
453
+ default: 0,
454
+ description: "Frequência do período de trial grátis (deixe 0 para sem trial)",
455
+ },
456
+ {
457
+ displayName: "Tipo de Frequência do Trial",
458
+ name: "freeTrialFrequencyType",
459
+ type: "options",
460
+ displayOptions: {
461
+ show: {
462
+ resource: ["plans"],
463
+ operation: ["create"],
464
+ },
465
+ },
466
+ options: [
467
+ {
468
+ name: "Dias",
469
+ value: "days",
470
+ },
471
+ {
472
+ name: "Meses",
473
+ value: "months",
474
+ },
475
+ ],
476
+ default: "months",
477
+ description: "Tipo de frequência do período de trial",
478
+ },
479
+ {
480
+ displayName: "Tipos de Pagamento Permitidos",
481
+ name: "paymentTypes",
482
+ type: "multiOptions",
483
+ displayOptions: {
484
+ show: {
485
+ resource: ["plans"],
486
+ operation: ["create"],
487
+ },
488
+ },
489
+ options: [
490
+ {
491
+ name: "Cartão de Crédito",
492
+ value: "credit_card",
493
+ },
494
+ {
495
+ name: "Cartão de Débito",
496
+ value: "debit_card",
497
+ },
498
+ ],
499
+ default: ["credit_card"],
500
+ description: "Tipos de pagamento permitidos no checkout",
501
+ },
502
+ {
503
+ displayName: "Meios de Pagamento Permitidos",
504
+ name: "paymentMethods",
505
+ type: "multiOptions",
506
+ displayOptions: {
507
+ show: {
508
+ resource: ["plans"],
509
+ operation: ["create"],
510
+ },
511
+ },
512
+ options: [
513
+ {
514
+ name: "Visa",
515
+ value: "visa",
516
+ },
517
+ {
518
+ name: "Mastercard",
519
+ value: "mastercard",
520
+ },
521
+ {
522
+ name: "American Express",
523
+ value: "amex",
524
+ },
525
+ {
526
+ name: "Boleto",
527
+ value: "bolbradesco",
528
+ },
529
+ ],
530
+ default: [],
531
+ description: "Meios de pagamento específicos permitidos (deixe vazio para permitir todos)",
532
+ },
346
533
  // Plan Get/Update Fields
347
534
  {
348
535
  displayName: "ID do Plano",
@@ -361,7 +548,7 @@ class PixPayment {
361
548
  // Plan Update Fields
362
549
  {
363
550
  displayName: "Nome do Plano",
364
- name: "reason",
551
+ name: "updateReason",
365
552
  type: "string",
366
553
  displayOptions: {
367
554
  show: {
@@ -374,7 +561,7 @@ class PixPayment {
374
561
  },
375
562
  {
376
563
  displayName: "Valor",
377
- name: "amount",
564
+ name: "updateAmount",
378
565
  type: "number",
379
566
  displayOptions: {
380
567
  show: {
@@ -904,13 +1091,34 @@ class PixPayment {
904
1091
  }
905
1092
  }
906
1093
  static async createPlan(executeFunctions, itemIndex, baseUrl, credentials) {
1094
+ // Campos obrigatórios
907
1095
  const reason = (0, helpers_1.getNodeParameterSafe)(executeFunctions.getNodeParameter.bind(executeFunctions), "reason", itemIndex, "");
908
1096
  const amountRaw = (0, helpers_1.getNodeParameterSafe)(executeFunctions.getNodeParameter.bind(executeFunctions), "amount", itemIndex, 0);
909
1097
  const frequencyRaw = (0, helpers_1.getNodeParameterSafe)(executeFunctions.getNodeParameter.bind(executeFunctions), "frequency", itemIndex, 1);
910
1098
  const frequencyType = (0, helpers_1.getNodeParameterSafe)(executeFunctions.getNodeParameter.bind(executeFunctions), "frequencyType", itemIndex, "months");
1099
+ const currencyId = (0, helpers_1.getNodeParameterSafe)(executeFunctions.getNodeParameter.bind(executeFunctions), "currencyId", itemIndex, "BRL");
1100
+ const backUrl = (0, helpers_1.getNodeParameterSafe)(executeFunctions.getNodeParameter.bind(executeFunctions), "backUrl", itemIndex, "https://www.mercadopago.com.br");
1101
+ // Campos opcionais
1102
+ const repetitionsRaw = (0, helpers_1.getNodeParameterSafe)(executeFunctions.getNodeParameter.bind(executeFunctions), "repetitions", itemIndex, 0);
1103
+ const billingDayRaw = (0, helpers_1.getNodeParameterSafe)(executeFunctions.getNodeParameter.bind(executeFunctions), "billingDay", itemIndex, 0);
1104
+ const billingDayProportional = (0, helpers_1.getNodeParameterSafe)(executeFunctions.getNodeParameter.bind(executeFunctions), "billingDayProportional", itemIndex, false);
1105
+ const freeTrialFrequencyRaw = (0, helpers_1.getNodeParameterSafe)(executeFunctions.getNodeParameter.bind(executeFunctions), "freeTrialFrequency", itemIndex, 0);
1106
+ const freeTrialFrequencyType = (0, helpers_1.getNodeParameterSafe)(executeFunctions.getNodeParameter.bind(executeFunctions), "freeTrialFrequencyType", itemIndex, "months");
1107
+ const paymentTypes = (0, helpers_1.getNodeParameterSafe)(executeFunctions.getNodeParameter.bind(executeFunctions), "paymentTypes", itemIndex, ["credit_card"]);
1108
+ const paymentMethods = (0, helpers_1.getNodeParameterSafe)(executeFunctions.getNodeParameter.bind(executeFunctions), "paymentMethods", itemIndex, []);
911
1109
  // Normaliza valores numéricos (converte vírgula para ponto)
912
1110
  const amount = (0, helpers_1.normalizeNumericValue)(amountRaw);
913
1111
  const frequency = (0, helpers_1.normalizeNumericValue)(frequencyRaw);
1112
+ const repetitions = repetitionsRaw
1113
+ ? (0, helpers_1.normalizeNumericValue)(repetitionsRaw)
1114
+ : undefined;
1115
+ const billingDay = billingDayRaw
1116
+ ? (0, helpers_1.normalizeNumericValue)(billingDayRaw)
1117
+ : undefined;
1118
+ const freeTrialFrequency = freeTrialFrequencyRaw
1119
+ ? (0, helpers_1.normalizeNumericValue)(freeTrialFrequencyRaw)
1120
+ : undefined;
1121
+ // Validações
914
1122
  if (!reason || reason.trim() === "") {
915
1123
  throw new Error("Nome do plano é obrigatório");
916
1124
  }
@@ -923,18 +1131,44 @@ class PixPayment {
923
1131
  if (frequencyType !== "days" && frequencyType !== "months") {
924
1132
  throw new Error('Tipo de frequência deve ser "days" ou "months"');
925
1133
  }
1134
+ if (billingDay !== undefined && (billingDay < 1 || billingDay > 28)) {
1135
+ throw new Error("Dia de cobrança deve estar entre 1 e 28");
1136
+ }
1137
+ // Construir auto_recurring
1138
+ const autoRecurring = {
1139
+ frequency,
1140
+ frequency_type: frequencyType,
1141
+ transaction_amount: (0, helpers_1.normalizeAmount)(amount),
1142
+ currency_id: currencyId,
1143
+ };
1144
+ if (repetitions && repetitions > 0) {
1145
+ autoRecurring.repetitions = repetitions;
1146
+ }
1147
+ if (billingDay && billingDay >= 1 && billingDay <= 28) {
1148
+ autoRecurring.billing_day = billingDay;
1149
+ autoRecurring.billing_day_proportional = billingDayProportional;
1150
+ }
1151
+ if (freeTrialFrequency && freeTrialFrequency > 0) {
1152
+ autoRecurring.free_trial = {
1153
+ frequency: freeTrialFrequency,
1154
+ frequency_type: freeTrialFrequencyType,
1155
+ };
1156
+ }
1157
+ // Construir payment_methods_allowed
1158
+ const paymentMethodsAllowed = {
1159
+ payment_types: paymentTypes.map((id) => ({ id })),
1160
+ };
1161
+ if (paymentMethods.length > 0) {
1162
+ paymentMethodsAllowed.payment_methods = paymentMethods.map((id) => ({
1163
+ id,
1164
+ }));
1165
+ }
1166
+ // Body final
926
1167
  const body = {
927
1168
  reason,
928
- auto_recurring: {
929
- frequency,
930
- frequency_type: frequencyType,
931
- transaction_amount: (0, helpers_1.normalizeAmount)(amount),
932
- currency_id: "BRL",
933
- },
934
- payment_methods_allowed: {
935
- payment_types: [{ id: "credit_card" }],
936
- },
937
- back_url: "https://www.mercadopago.com.br",
1169
+ auto_recurring: autoRecurring,
1170
+ payment_methods_allowed: paymentMethodsAllowed,
1171
+ back_url: backUrl,
938
1172
  };
939
1173
  const response = await executeFunctions.helpers.requestWithAuthentication.call(executeFunctions, "pixPaymentApi", {
940
1174
  method: "POST",
@@ -976,8 +1210,8 @@ class PixPayment {
976
1210
  }
977
1211
  static async updatePlan(executeFunctions, itemIndex, baseUrl, credentials) {
978
1212
  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);
1213
+ const reason = (0, helpers_1.getNodeParameterSafe)(executeFunctions.getNodeParameter.bind(executeFunctions), "updateReason", itemIndex, "");
1214
+ const amountRaw = (0, helpers_1.getNodeParameterSafe)(executeFunctions.getNodeParameter.bind(executeFunctions), "updateAmount", itemIndex, 0);
981
1215
  if (!planId || planId.trim() === "") {
982
1216
  throw new Error("ID do plano é obrigatório");
983
1217
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "n8n-nodes-mercadopago-pix-assinatura",
3
- "version": "1.0.7",
3
+ "version": "1.0.8",
4
4
  "description": "n8n node para processamento de pagamentos PIX e assinaturas via Mercado Pago",
5
5
  "keywords": [
6
6
  "n8n",