n8n-nodes-mercadopago-pix-assinatura 1.0.7 → 1.0.9
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: "
|
|
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: "
|
|
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,46 @@ 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
|
+
// NOTA: Para planos, a API do Mercado Pago espera transaction_amount em formato decimal (não centavos)
|
|
1139
|
+
// Exemplo: 10.9 (não 1090)
|
|
1140
|
+
const autoRecurring = {
|
|
1141
|
+
frequency,
|
|
1142
|
+
frequency_type: frequencyType,
|
|
1143
|
+
transaction_amount: amount, // Valor já está em formato decimal após normalizeNumericValue
|
|
1144
|
+
currency_id: currencyId,
|
|
1145
|
+
};
|
|
1146
|
+
if (repetitions && repetitions > 0) {
|
|
1147
|
+
autoRecurring.repetitions = repetitions;
|
|
1148
|
+
}
|
|
1149
|
+
if (billingDay && billingDay >= 1 && billingDay <= 28) {
|
|
1150
|
+
autoRecurring.billing_day = billingDay;
|
|
1151
|
+
autoRecurring.billing_day_proportional = billingDayProportional;
|
|
1152
|
+
}
|
|
1153
|
+
if (freeTrialFrequency && freeTrialFrequency > 0) {
|
|
1154
|
+
autoRecurring.free_trial = {
|
|
1155
|
+
frequency: freeTrialFrequency,
|
|
1156
|
+
frequency_type: freeTrialFrequencyType,
|
|
1157
|
+
};
|
|
1158
|
+
}
|
|
1159
|
+
// Construir payment_methods_allowed
|
|
1160
|
+
const paymentMethodsAllowed = {
|
|
1161
|
+
payment_types: paymentTypes.map((id) => ({ id })),
|
|
1162
|
+
};
|
|
1163
|
+
if (paymentMethods.length > 0) {
|
|
1164
|
+
paymentMethodsAllowed.payment_methods = paymentMethods.map((id) => ({
|
|
1165
|
+
id,
|
|
1166
|
+
}));
|
|
1167
|
+
}
|
|
1168
|
+
// Body final
|
|
926
1169
|
const body = {
|
|
927
1170
|
reason,
|
|
928
|
-
auto_recurring:
|
|
929
|
-
|
|
930
|
-
|
|
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",
|
|
1171
|
+
auto_recurring: autoRecurring,
|
|
1172
|
+
payment_methods_allowed: paymentMethodsAllowed,
|
|
1173
|
+
back_url: backUrl,
|
|
938
1174
|
};
|
|
939
1175
|
const response = await executeFunctions.helpers.requestWithAuthentication.call(executeFunctions, "pixPaymentApi", {
|
|
940
1176
|
method: "POST",
|
|
@@ -976,8 +1212,8 @@ class PixPayment {
|
|
|
976
1212
|
}
|
|
977
1213
|
static async updatePlan(executeFunctions, itemIndex, baseUrl, credentials) {
|
|
978
1214
|
const planId = (0, helpers_1.getNodeParameterSafe)(executeFunctions.getNodeParameter.bind(executeFunctions), "planId", itemIndex, "");
|
|
979
|
-
const reason = (0, helpers_1.getNodeParameterSafe)(executeFunctions.getNodeParameter.bind(executeFunctions), "
|
|
980
|
-
const amountRaw = (0, helpers_1.getNodeParameterSafe)(executeFunctions.getNodeParameter.bind(executeFunctions), "
|
|
1215
|
+
const reason = (0, helpers_1.getNodeParameterSafe)(executeFunctions.getNodeParameter.bind(executeFunctions), "updateReason", itemIndex, "");
|
|
1216
|
+
const amountRaw = (0, helpers_1.getNodeParameterSafe)(executeFunctions.getNodeParameter.bind(executeFunctions), "updateAmount", itemIndex, 0);
|
|
981
1217
|
if (!planId || planId.trim() === "") {
|
|
982
1218
|
throw new Error("ID do plano é obrigatório");
|
|
983
1219
|
}
|
|
@@ -988,8 +1224,9 @@ class PixPayment {
|
|
|
988
1224
|
body.reason = reason;
|
|
989
1225
|
}
|
|
990
1226
|
if (amount && amount > 0) {
|
|
1227
|
+
// NOTA: Para planos, a API do Mercado Pago espera transaction_amount em formato decimal (não centavos)
|
|
991
1228
|
body.auto_recurring = {
|
|
992
|
-
transaction_amount:
|
|
1229
|
+
transaction_amount: amount, // Valor já está em formato decimal após normalizeNumericValue
|
|
993
1230
|
};
|
|
994
1231
|
}
|
|
995
1232
|
if (Object.keys(body).length === 0) {
|
|
@@ -1312,9 +1549,9 @@ class PixPayment {
|
|
|
1312
1549
|
break;
|
|
1313
1550
|
case "plans":
|
|
1314
1551
|
normalized.planId = data.id;
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
|
|
1552
|
+
// NOTA: Para planos, a API retorna transaction_amount em formato decimal (não centavos)
|
|
1553
|
+
// Exemplo: 10.9 (não 1090), então não precisa dividir por 100
|
|
1554
|
+
normalized.amount = data.auto_recurring?.transaction_amount;
|
|
1318
1555
|
normalized.description = data.reason;
|
|
1319
1556
|
break;
|
|
1320
1557
|
case "subscriptions":
|