n8n-nodes-mercadopago-pix-assinatura 1.0.6 → 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.
@@ -5,712 +5,899 @@ const helpers_1 = require("./helpers");
5
5
  class PixPayment {
6
6
  constructor() {
7
7
  this.description = {
8
- displayName: 'Mercado Pago PIX e Assinaturas',
9
- name: 'pixPayment',
10
- icon: 'file:mercadopago.svg',
11
- group: ['transform'],
8
+ displayName: "Mercado Pago PIX e Assinaturas",
9
+ name: "pixPayment",
10
+ icon: "file:mercadopago.svg",
11
+ group: ["transform"],
12
12
  version: 1,
13
13
  subtitle: '={{$parameter["resource"] + ": " + $parameter["operation"]}}',
14
- description: 'Processamento de pagamentos PIX, assinaturas e webhooks via Mercado Pago',
14
+ description: "Processamento de pagamentos PIX, assinaturas e webhooks via Mercado Pago",
15
15
  defaults: {
16
- name: 'Mercado Pago',
16
+ name: "Mercado Pago",
17
17
  },
18
- inputs: ['main'],
19
- outputs: ['main'],
18
+ inputs: ["main"],
19
+ outputs: ["main"],
20
20
  credentials: [
21
21
  {
22
- name: 'pixPaymentApi',
22
+ name: "pixPaymentApi",
23
23
  required: true,
24
24
  },
25
25
  ],
26
26
  properties: [
27
27
  {
28
- displayName: 'Resource',
29
- name: 'resource',
30
- type: 'options',
28
+ displayName: "Resource",
29
+ name: "resource",
30
+ type: "options",
31
31
  noDataExpression: true,
32
32
  options: [
33
33
  {
34
- name: 'PIX',
35
- value: 'pix',
34
+ name: "PIX",
35
+ value: "pix",
36
36
  },
37
37
  {
38
- name: 'Plano',
39
- value: 'plans',
38
+ name: "Plano",
39
+ value: "plans",
40
40
  },
41
41
  {
42
- name: 'Assinatura',
43
- value: 'subscriptions',
42
+ name: "Assinatura",
43
+ value: "subscriptions",
44
44
  },
45
45
  {
46
- name: 'Pagamento Recorrente',
47
- value: 'recurringPayments',
46
+ name: "Pagamento Recorrente",
47
+ value: "recurringPayments",
48
48
  },
49
49
  {
50
- name: 'Webhook',
51
- value: 'webhooks',
50
+ name: "Webhook",
51
+ value: "webhooks",
52
52
  },
53
53
  ],
54
- default: 'pix',
54
+ default: "pix",
55
55
  },
56
56
  // PIX Operations
57
57
  {
58
- displayName: 'Operation',
59
- name: 'operation',
60
- type: 'options',
58
+ displayName: "Operation",
59
+ name: "operation",
60
+ type: "options",
61
61
  noDataExpression: true,
62
62
  displayOptions: {
63
63
  show: {
64
- resource: ['pix'],
64
+ resource: ["pix"],
65
65
  },
66
66
  },
67
67
  options: [
68
68
  {
69
- name: 'Criar',
70
- value: 'create',
71
- description: 'Criar um pagamento PIX',
72
- action: 'Criar pagamento PIX',
69
+ name: "Criar",
70
+ value: "create",
71
+ description: "Criar um pagamento PIX",
72
+ action: "Criar pagamento PIX",
73
73
  },
74
74
  {
75
- name: 'Consultar',
76
- value: 'get',
77
- description: 'Consultar um pagamento PIX',
78
- action: 'Consultar pagamento PIX',
75
+ name: "Consultar",
76
+ value: "get",
77
+ description: "Consultar um pagamento PIX",
78
+ action: "Consultar pagamento PIX",
79
79
  },
80
80
  {
81
- name: 'Reembolsar',
82
- value: 'refund',
83
- description: 'Reembolsar um pagamento PIX',
84
- action: 'Reembolsar pagamento PIX',
81
+ name: "Reembolsar",
82
+ value: "refund",
83
+ description: "Reembolsar um pagamento PIX",
84
+ action: "Reembolsar pagamento PIX",
85
85
  },
86
86
  ],
87
- default: 'create',
87
+ default: "create",
88
88
  },
89
89
  // PIX Create Fields
90
90
  {
91
- displayName: 'Valor',
92
- name: 'amount',
93
- type: 'number',
91
+ displayName: "Valor",
92
+ name: "amount",
93
+ type: "number",
94
94
  required: true,
95
95
  displayOptions: {
96
96
  show: {
97
- resource: ['pix'],
98
- operation: ['create'],
97
+ resource: ["pix"],
98
+ operation: ["create"],
99
99
  },
100
100
  },
101
101
  default: 0,
102
- description: 'Valor do pagamento em reais (ex: 10.50)',
102
+ description: "Valor do pagamento em reais (ex: 10.50)",
103
103
  },
104
104
  {
105
- displayName: 'Descrição',
106
- name: 'description',
107
- type: 'string',
105
+ displayName: "Descrição",
106
+ name: "description",
107
+ type: "string",
108
108
  required: true,
109
109
  displayOptions: {
110
110
  show: {
111
- resource: ['pix'],
112
- operation: ['create'],
111
+ resource: ["pix"],
112
+ operation: ["create"],
113
113
  },
114
114
  },
115
- default: '',
116
- description: 'Descrição do pagamento',
115
+ default: "",
116
+ description: "Descrição do pagamento",
117
117
  },
118
118
  {
119
- displayName: 'E-mail do Pagador',
120
- name: 'payerEmail',
121
- type: 'string',
119
+ displayName: "E-mail do Pagador",
120
+ name: "payerEmail",
121
+ type: "string",
122
122
  required: true,
123
123
  displayOptions: {
124
124
  show: {
125
- resource: ['pix'],
126
- operation: ['create'],
125
+ resource: ["pix"],
126
+ operation: ["create"],
127
127
  },
128
128
  },
129
- default: '',
130
- description: 'E-mail do pagador',
129
+ default: "",
130
+ description: "E-mail do pagador",
131
131
  },
132
132
  {
133
- displayName: 'CPF/CNPJ do Pagador',
134
- name: 'payerDocument',
135
- type: 'string',
133
+ displayName: "CPF/CNPJ do Pagador",
134
+ name: "payerDocument",
135
+ type: "string",
136
136
  displayOptions: {
137
137
  show: {
138
- resource: ['pix'],
139
- operation: ['create'],
138
+ resource: ["pix"],
139
+ operation: ["create"],
140
140
  },
141
141
  },
142
- default: '',
143
- description: 'CPF ou CNPJ do pagador (apenas números)',
142
+ default: "",
143
+ description: "CPF ou CNPJ do pagador (apenas números)",
144
144
  },
145
145
  {
146
- displayName: 'Nome do Pagador',
147
- name: 'payerName',
148
- type: 'string',
146
+ displayName: "Nome do Pagador",
147
+ name: "payerName",
148
+ type: "string",
149
149
  displayOptions: {
150
150
  show: {
151
- resource: ['pix'],
152
- operation: ['create'],
151
+ resource: ["pix"],
152
+ operation: ["create"],
153
153
  },
154
154
  },
155
- default: '',
156
- description: 'Nome completo do pagador',
155
+ default: "",
156
+ description: "Nome completo do pagador",
157
157
  },
158
158
  {
159
- displayName: 'Data de Expiração',
160
- name: 'expirationDate',
161
- type: 'dateTime',
159
+ displayName: "Data de Expiração",
160
+ name: "expirationDate",
161
+ type: "dateTime",
162
162
  displayOptions: {
163
163
  show: {
164
- resource: ['pix'],
165
- operation: ['create'],
164
+ resource: ["pix"],
165
+ operation: ["create"],
166
166
  },
167
167
  },
168
- default: '',
169
- description: 'Data e hora de expiração do QR Code PIX',
168
+ default: "",
169
+ description: "Data e hora de expiração do QR Code PIX",
170
170
  },
171
171
  {
172
- displayName: 'Referência Externa',
173
- name: 'externalReference',
174
- type: 'string',
172
+ displayName: "Referência Externa",
173
+ name: "externalReference",
174
+ type: "string",
175
175
  displayOptions: {
176
176
  show: {
177
- resource: ['pix'],
178
- operation: ['create'],
177
+ resource: ["pix"],
178
+ operation: ["create"],
179
179
  },
180
180
  },
181
- default: '',
182
- description: 'Referência externa para identificar o pagamento',
181
+ default: "",
182
+ description: "Referência externa para identificar o pagamento",
183
183
  },
184
184
  {
185
- displayName: 'Chave de Idempotência',
186
- name: 'idempotencyKey',
187
- type: 'string',
185
+ displayName: "Chave de Idempotência",
186
+ name: "idempotencyKey",
187
+ type: "string",
188
188
  displayOptions: {
189
189
  show: {
190
- resource: ['pix'],
191
- operation: ['create'],
190
+ resource: ["pix"],
191
+ operation: ["create"],
192
192
  },
193
193
  },
194
- default: '',
195
- description: 'Chave única para garantir idempotência da requisição',
194
+ default: "",
195
+ description: "Chave única para garantir idempotência da requisição",
196
196
  },
197
197
  // PIX Get Fields
198
198
  {
199
- displayName: 'ID do Pagamento',
200
- name: 'paymentId',
201
- type: 'string',
199
+ displayName: "ID do Pagamento",
200
+ name: "paymentId",
201
+ type: "string",
202
202
  required: true,
203
203
  displayOptions: {
204
204
  show: {
205
- resource: ['pix'],
206
- operation: ['get'],
205
+ resource: ["pix"],
206
+ operation: ["get"],
207
207
  },
208
208
  },
209
- default: '',
210
- description: 'ID do pagamento a ser consultado',
209
+ default: "",
210
+ description: "ID do pagamento a ser consultado",
211
211
  },
212
212
  // PIX Refund Fields
213
213
  {
214
- displayName: 'ID do Pagamento',
215
- name: 'paymentId',
216
- type: 'string',
214
+ displayName: "ID do Pagamento",
215
+ name: "paymentId",
216
+ type: "string",
217
217
  required: true,
218
218
  displayOptions: {
219
219
  show: {
220
- resource: ['pix'],
221
- operation: ['refund'],
220
+ resource: ["pix"],
221
+ operation: ["refund"],
222
222
  },
223
223
  },
224
- default: '',
225
- description: 'ID do pagamento a ser reembolsado',
224
+ default: "",
225
+ description: "ID do pagamento a ser reembolsado",
226
226
  },
227
227
  {
228
- displayName: 'Valor do Reembolso',
229
- name: 'refundAmount',
230
- type: 'number',
228
+ displayName: "Valor do Reembolso",
229
+ name: "refundAmount",
230
+ type: "number",
231
231
  displayOptions: {
232
232
  show: {
233
- resource: ['pix'],
234
- operation: ['refund'],
233
+ resource: ["pix"],
234
+ operation: ["refund"],
235
235
  },
236
236
  },
237
237
  default: 0,
238
- description: 'Valor do reembolso em reais (deixe vazio para reembolso total)',
238
+ description: "Valor do reembolso em reais (deixe vazio para reembolso total)",
239
239
  },
240
240
  // Plan Operations
241
241
  {
242
- displayName: 'Operation',
243
- name: 'operation',
244
- type: 'options',
242
+ displayName: "Operation",
243
+ name: "operation",
244
+ type: "options",
245
245
  noDataExpression: true,
246
246
  displayOptions: {
247
247
  show: {
248
- resource: ['plans'],
248
+ resource: ["plans"],
249
249
  },
250
250
  },
251
251
  options: [
252
252
  {
253
- name: 'Criar',
254
- value: 'create',
255
- description: 'Criar um plano de assinatura',
256
- action: 'Criar plano',
253
+ name: "Criar",
254
+ value: "create",
255
+ description: "Criar um plano de assinatura",
256
+ action: "Criar plano",
257
257
  },
258
258
  {
259
- name: 'Consultar',
260
- value: 'get',
261
- description: 'Consultar um plano',
262
- action: 'Consultar plano',
259
+ name: "Consultar",
260
+ value: "get",
261
+ description: "Consultar um plano",
262
+ action: "Consultar plano",
263
263
  },
264
264
  {
265
- name: 'Listar',
266
- value: 'list',
267
- description: 'Listar planos',
268
- action: 'Listar planos',
265
+ name: "Listar",
266
+ value: "list",
267
+ description: "Listar planos",
268
+ action: "Listar planos",
269
269
  },
270
270
  {
271
- name: 'Atualizar',
272
- value: 'update',
273
- description: 'Atualizar um plano',
274
- action: 'Atualizar plano',
271
+ name: "Atualizar",
272
+ value: "update",
273
+ description: "Atualizar um plano",
274
+ action: "Atualizar plano",
275
275
  },
276
276
  ],
277
- default: 'create',
277
+ default: "create",
278
278
  },
279
279
  // Plan Create Fields
280
280
  {
281
- displayName: 'Nome do Plano',
282
- name: 'reason',
283
- type: 'string',
281
+ displayName: "Nome do Plano",
282
+ name: "reason",
283
+ type: "string",
284
284
  required: true,
285
285
  displayOptions: {
286
286
  show: {
287
- resource: ['plans'],
288
- operation: ['create'],
287
+ resource: ["plans"],
288
+ operation: ["create"],
289
289
  },
290
290
  },
291
- default: '',
292
- description: 'Nome/descrição do plano',
291
+ default: "",
292
+ description: "Nome/descrição do plano",
293
293
  },
294
294
  {
295
- displayName: 'Valor',
296
- name: 'amount',
297
- type: 'number',
295
+ displayName: "Valor",
296
+ name: "amount",
297
+ type: "number",
298
298
  required: true,
299
299
  displayOptions: {
300
300
  show: {
301
- resource: ['plans'],
302
- operation: ['create'],
301
+ resource: ["plans"],
302
+ operation: ["create"],
303
303
  },
304
304
  },
305
305
  default: 0,
306
- description: 'Valor do plano em reais (ex: 99.99)',
306
+ description: "Valor do plano em reais (ex: 99.99)",
307
307
  },
308
308
  {
309
- displayName: 'Frequência',
310
- name: 'frequency',
311
- type: 'number',
309
+ displayName: "Frequência",
310
+ name: "frequency",
311
+ type: "number",
312
312
  required: true,
313
313
  displayOptions: {
314
314
  show: {
315
- resource: ['plans'],
316
- operation: ['create'],
315
+ resource: ["plans"],
316
+ operation: ["create"],
317
317
  },
318
318
  },
319
319
  default: 1,
320
- description: 'Frequência de cobrança (ex: 1 para mensal)',
320
+ description: "Frequência de cobrança (ex: 1 para mensal)",
321
321
  },
322
322
  {
323
- displayName: 'Tipo de Frequência',
324
- name: 'frequencyType',
325
- type: 'options',
323
+ displayName: "Tipo de Frequência",
324
+ name: "frequencyType",
325
+ type: "options",
326
326
  required: true,
327
327
  displayOptions: {
328
328
  show: {
329
- resource: ['plans'],
330
- operation: ['create'],
329
+ resource: ["plans"],
330
+ operation: ["create"],
331
331
  },
332
332
  },
333
333
  options: [
334
334
  {
335
- name: 'Dias',
336
- value: 'days',
335
+ name: "Dias",
336
+ value: "days",
337
337
  },
338
338
  {
339
- name: 'Meses',
340
- value: 'months',
339
+ name: "Meses",
340
+ value: "months",
341
341
  },
342
342
  ],
343
- default: 'months',
344
- description: 'Tipo de frequência (dias ou meses)',
343
+ default: "months",
344
+ description: "Tipo de frequência (dias ou meses)",
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)",
345
532
  },
346
533
  // Plan Get/Update Fields
347
534
  {
348
- displayName: 'ID do Plano',
349
- name: 'planId',
350
- type: 'string',
535
+ displayName: "ID do Plano",
536
+ name: "planId",
537
+ type: "string",
351
538
  required: true,
352
539
  displayOptions: {
353
540
  show: {
354
- resource: ['plans'],
355
- operation: ['get', 'update'],
541
+ resource: ["plans"],
542
+ operation: ["get", "update"],
356
543
  },
357
544
  },
358
- default: '',
359
- description: 'ID do plano',
545
+ default: "",
546
+ description: "ID do plano",
360
547
  },
361
548
  // Plan Update Fields
362
549
  {
363
- displayName: 'Nome do Plano',
364
- name: 'reason',
365
- type: 'string',
550
+ displayName: "Nome do Plano",
551
+ name: "updateReason",
552
+ type: "string",
366
553
  displayOptions: {
367
554
  show: {
368
- resource: ['plans'],
369
- operation: ['update'],
555
+ resource: ["plans"],
556
+ operation: ["update"],
370
557
  },
371
558
  },
372
- default: '',
373
- description: 'Novo nome/descrição do plano',
559
+ default: "",
560
+ description: "Novo nome/descrição do plano",
374
561
  },
375
562
  {
376
- displayName: 'Valor',
377
- name: 'amount',
378
- type: 'number',
563
+ displayName: "Valor",
564
+ name: "updateAmount",
565
+ type: "number",
379
566
  displayOptions: {
380
567
  show: {
381
- resource: ['plans'],
382
- operation: ['update'],
568
+ resource: ["plans"],
569
+ operation: ["update"],
383
570
  },
384
571
  },
385
572
  default: 0,
386
- description: 'Novo valor do plano em reais',
573
+ description: "Novo valor do plano em reais",
387
574
  },
388
575
  // Subscription Operations
389
576
  {
390
- displayName: 'Operation',
391
- name: 'operation',
392
- type: 'options',
577
+ displayName: "Operation",
578
+ name: "operation",
579
+ type: "options",
393
580
  noDataExpression: true,
394
581
  displayOptions: {
395
582
  show: {
396
- resource: ['subscriptions'],
583
+ resource: ["subscriptions"],
397
584
  },
398
585
  },
399
586
  options: [
400
587
  {
401
- name: 'Criar',
402
- value: 'create',
403
- description: 'Criar uma assinatura',
404
- action: 'Criar assinatura',
588
+ name: "Criar",
589
+ value: "create",
590
+ description: "Criar uma assinatura",
591
+ action: "Criar assinatura",
405
592
  },
406
593
  {
407
- name: 'Pausar',
408
- value: 'pause',
409
- description: 'Pausar uma assinatura',
410
- action: 'Pausar assinatura',
594
+ name: "Pausar",
595
+ value: "pause",
596
+ description: "Pausar uma assinatura",
597
+ action: "Pausar assinatura",
411
598
  },
412
599
  {
413
- name: 'Retomar',
414
- value: 'resume',
415
- description: 'Retomar uma assinatura pausada',
416
- action: 'Retomar assinatura',
600
+ name: "Retomar",
601
+ value: "resume",
602
+ description: "Retomar uma assinatura pausada",
603
+ action: "Retomar assinatura",
417
604
  },
418
605
  {
419
- name: 'Cancelar',
420
- value: 'cancel',
421
- description: 'Cancelar uma assinatura',
422
- action: 'Cancelar assinatura',
606
+ name: "Cancelar",
607
+ value: "cancel",
608
+ description: "Cancelar uma assinatura",
609
+ action: "Cancelar assinatura",
423
610
  },
424
611
  {
425
- name: 'Consultar',
426
- value: 'get',
427
- description: 'Consultar uma assinatura',
428
- action: 'Consultar assinatura',
612
+ name: "Consultar",
613
+ value: "get",
614
+ description: "Consultar uma assinatura",
615
+ action: "Consultar assinatura",
429
616
  },
430
617
  {
431
- name: 'Listar',
432
- value: 'list',
433
- description: 'Listar assinaturas',
434
- action: 'Listar assinaturas',
618
+ name: "Listar",
619
+ value: "list",
620
+ description: "Listar assinaturas",
621
+ action: "Listar assinaturas",
435
622
  },
436
623
  ],
437
- default: 'create',
624
+ default: "create",
438
625
  },
439
626
  // Subscription Create Fields
440
627
  {
441
- displayName: 'ID do Plano',
442
- name: 'planId',
443
- type: 'string',
628
+ displayName: "ID do Plano",
629
+ name: "planId",
630
+ type: "string",
444
631
  required: true,
445
632
  displayOptions: {
446
633
  show: {
447
- resource: ['subscriptions'],
448
- operation: ['create'],
634
+ resource: ["subscriptions"],
635
+ operation: ["create"],
449
636
  },
450
637
  },
451
- default: '',
452
- description: 'ID do plano de assinatura',
638
+ default: "",
639
+ description: "ID do plano de assinatura",
453
640
  },
454
641
  {
455
- displayName: 'E-mail do Pagador',
456
- name: 'payerEmail',
457
- type: 'string',
642
+ displayName: "E-mail do Pagador",
643
+ name: "payerEmail",
644
+ type: "string",
458
645
  required: true,
459
646
  displayOptions: {
460
647
  show: {
461
- resource: ['subscriptions'],
462
- operation: ['create'],
648
+ resource: ["subscriptions"],
649
+ operation: ["create"],
463
650
  },
464
651
  },
465
- default: '',
466
- description: 'E-mail do pagador',
652
+ default: "",
653
+ description: "E-mail do pagador",
467
654
  },
468
655
  {
469
- displayName: 'CPF/CNPJ do Pagador',
470
- name: 'payerDocument',
471
- type: 'string',
656
+ displayName: "CPF/CNPJ do Pagador",
657
+ name: "payerDocument",
658
+ type: "string",
472
659
  displayOptions: {
473
660
  show: {
474
- resource: ['subscriptions'],
475
- operation: ['create'],
661
+ resource: ["subscriptions"],
662
+ operation: ["create"],
476
663
  },
477
664
  },
478
- default: '',
479
- description: 'CPF ou CNPJ do pagador',
665
+ default: "",
666
+ description: "CPF ou CNPJ do pagador",
480
667
  },
481
668
  {
482
- displayName: 'Data de Início',
483
- name: 'startDate',
484
- type: 'dateTime',
669
+ displayName: "Data de Início",
670
+ name: "startDate",
671
+ type: "dateTime",
485
672
  displayOptions: {
486
673
  show: {
487
- resource: ['subscriptions'],
488
- operation: ['create'],
674
+ resource: ["subscriptions"],
675
+ operation: ["create"],
489
676
  },
490
677
  },
491
- default: '',
492
- description: 'Data de início da assinatura',
678
+ default: "",
679
+ description: "Data de início da assinatura",
493
680
  },
494
681
  {
495
- displayName: 'Período de Trial (dias)',
496
- name: 'trialPeriodDays',
497
- type: 'number',
682
+ displayName: "Período de Trial (dias)",
683
+ name: "trialPeriodDays",
684
+ type: "number",
498
685
  displayOptions: {
499
686
  show: {
500
- resource: ['subscriptions'],
501
- operation: ['create'],
687
+ resource: ["subscriptions"],
688
+ operation: ["create"],
502
689
  },
503
690
  },
504
691
  default: 0,
505
- description: 'Número de dias de período de trial',
692
+ description: "Número de dias de período de trial",
506
693
  },
507
694
  // Subscription Get/Cancel/Pause/Resume Fields
508
695
  {
509
- displayName: 'ID da Assinatura',
510
- name: 'subscriptionId',
511
- type: 'string',
696
+ displayName: "ID da Assinatura",
697
+ name: "subscriptionId",
698
+ type: "string",
512
699
  required: true,
513
700
  displayOptions: {
514
701
  show: {
515
- resource: ['subscriptions'],
516
- operation: ['get', 'cancel', 'pause', 'resume'],
702
+ resource: ["subscriptions"],
703
+ operation: ["get", "cancel", "pause", "resume"],
517
704
  },
518
705
  },
519
- default: '',
520
- description: 'ID da assinatura',
706
+ default: "",
707
+ description: "ID da assinatura",
521
708
  },
522
709
  // Recurring Payment Operations
523
710
  {
524
- displayName: 'Operation',
525
- name: 'operation',
526
- type: 'options',
711
+ displayName: "Operation",
712
+ name: "operation",
713
+ type: "options",
527
714
  noDataExpression: true,
528
715
  displayOptions: {
529
716
  show: {
530
- resource: ['recurringPayments'],
717
+ resource: ["recurringPayments"],
531
718
  },
532
719
  },
533
720
  options: [
534
721
  {
535
- name: 'Criar',
536
- value: 'create',
537
- description: 'Criar um pagamento recorrente',
538
- action: 'Criar pagamento recorrente',
722
+ name: "Criar",
723
+ value: "create",
724
+ description: "Criar um pagamento recorrente",
725
+ action: "Criar pagamento recorrente",
539
726
  },
540
727
  {
541
- name: 'Listar',
542
- value: 'list',
543
- description: 'Listar pagamentos recorrentes',
544
- action: 'Listar pagamentos recorrentes',
728
+ name: "Listar",
729
+ value: "list",
730
+ description: "Listar pagamentos recorrentes",
731
+ action: "Listar pagamentos recorrentes",
545
732
  },
546
733
  {
547
- name: 'Cancelar',
548
- value: 'cancel',
549
- description: 'Cancelar um pagamento recorrente',
550
- action: 'Cancelar pagamento recorrente',
734
+ name: "Cancelar",
735
+ value: "cancel",
736
+ description: "Cancelar um pagamento recorrente",
737
+ action: "Cancelar pagamento recorrente",
551
738
  },
552
739
  {
553
- name: 'Consultar',
554
- value: 'get',
555
- description: 'Consultar um pagamento recorrente',
556
- action: 'Consultar pagamento recorrente',
740
+ name: "Consultar",
741
+ value: "get",
742
+ description: "Consultar um pagamento recorrente",
743
+ action: "Consultar pagamento recorrente",
557
744
  },
558
745
  ],
559
- default: 'create',
746
+ default: "create",
560
747
  },
561
748
  // Recurring Payment Fields
562
749
  {
563
- displayName: 'ID do Plano',
564
- name: 'planId',
565
- type: 'string',
750
+ displayName: "ID do Plano",
751
+ name: "planId",
752
+ type: "string",
566
753
  required: true,
567
754
  displayOptions: {
568
755
  show: {
569
- resource: ['recurringPayments'],
570
- operation: ['create'],
756
+ resource: ["recurringPayments"],
757
+ operation: ["create"],
571
758
  },
572
759
  },
573
- default: '',
574
- description: 'ID do plano de pagamento recorrente',
760
+ default: "",
761
+ description: "ID do plano de pagamento recorrente",
575
762
  },
576
763
  {
577
- displayName: 'ID do Cliente',
578
- name: 'customerId',
579
- type: 'string',
764
+ displayName: "ID do Cliente",
765
+ name: "customerId",
766
+ type: "string",
580
767
  displayOptions: {
581
768
  show: {
582
- resource: ['recurringPayments'],
583
- operation: ['create', 'list', 'get'],
769
+ resource: ["recurringPayments"],
770
+ operation: ["create", "list", "get"],
584
771
  },
585
772
  },
586
- default: '',
587
- description: 'ID do cliente (filtro opcional)',
773
+ default: "",
774
+ description: "ID do cliente (filtro opcional)",
588
775
  },
589
776
  {
590
- displayName: 'ID do Pagamento Recorrente',
591
- name: 'recurringPaymentId',
592
- type: 'string',
777
+ displayName: "ID do Pagamento Recorrente",
778
+ name: "recurringPaymentId",
779
+ type: "string",
593
780
  required: true,
594
781
  displayOptions: {
595
782
  show: {
596
- resource: ['recurringPayments'],
597
- operation: ['get', 'cancel'],
783
+ resource: ["recurringPayments"],
784
+ operation: ["get", "cancel"],
598
785
  },
599
786
  },
600
- default: '',
601
- description: 'ID do pagamento recorrente',
787
+ default: "",
788
+ description: "ID do pagamento recorrente",
602
789
  },
603
790
  // Webhook Operations
604
791
  {
605
- displayName: 'Operation',
606
- name: 'operation',
607
- type: 'options',
792
+ displayName: "Operation",
793
+ name: "operation",
794
+ type: "options",
608
795
  noDataExpression: true,
609
796
  displayOptions: {
610
797
  show: {
611
- resource: ['webhooks'],
798
+ resource: ["webhooks"],
612
799
  },
613
800
  },
614
801
  options: [
615
802
  {
616
- name: 'Registrar',
617
- value: 'register',
618
- description: 'Registrar um novo webhook',
619
- action: 'Registrar webhook',
803
+ name: "Registrar",
804
+ value: "register",
805
+ description: "Registrar um novo webhook",
806
+ action: "Registrar webhook",
620
807
  },
621
808
  {
622
- name: 'Listar',
623
- value: 'list',
624
- description: 'Listar webhooks',
625
- action: 'Listar webhooks',
809
+ name: "Listar",
810
+ value: "list",
811
+ description: "Listar webhooks",
812
+ action: "Listar webhooks",
626
813
  },
627
814
  {
628
- name: 'Excluir',
629
- value: 'delete',
630
- description: 'Excluir um webhook',
631
- action: 'Excluir webhook',
815
+ name: "Excluir",
816
+ value: "delete",
817
+ description: "Excluir um webhook",
818
+ action: "Excluir webhook",
632
819
  },
633
820
  {
634
- name: 'Consultar',
635
- value: 'get',
636
- description: 'Consultar um webhook',
637
- action: 'Consultar webhook',
821
+ name: "Consultar",
822
+ value: "get",
823
+ description: "Consultar um webhook",
824
+ action: "Consultar webhook",
638
825
  },
639
826
  ],
640
- default: 'register',
827
+ default: "register",
641
828
  },
642
829
  // Webhook Fields
643
830
  {
644
- displayName: 'URL',
645
- name: 'url',
646
- type: 'string',
831
+ displayName: "URL",
832
+ name: "url",
833
+ type: "string",
647
834
  required: true,
648
835
  displayOptions: {
649
836
  show: {
650
- resource: ['webhooks'],
651
- operation: ['register'],
837
+ resource: ["webhooks"],
838
+ operation: ["register"],
652
839
  },
653
840
  },
654
- default: '',
655
- description: 'URL que receberá as notificações do webhook',
841
+ default: "",
842
+ description: "URL que receberá as notificações do webhook",
656
843
  },
657
844
  {
658
- displayName: 'Eventos',
659
- name: 'events',
660
- type: 'multiOptions',
845
+ displayName: "Eventos",
846
+ name: "events",
847
+ type: "multiOptions",
661
848
  displayOptions: {
662
849
  show: {
663
- resource: ['webhooks'],
664
- operation: ['register'],
850
+ resource: ["webhooks"],
851
+ operation: ["register"],
665
852
  },
666
853
  },
667
854
  options: [
668
855
  {
669
- name: 'payment.created',
670
- value: 'payment',
856
+ name: "payment.created",
857
+ value: "payment",
671
858
  },
672
859
  {
673
- name: 'payment.updated',
674
- value: 'payment',
860
+ name: "payment.updated",
861
+ value: "payment",
675
862
  },
676
863
  {
677
- name: 'subscription.created',
678
- value: 'subscription',
864
+ name: "subscription.created",
865
+ value: "subscription",
679
866
  },
680
867
  {
681
- name: 'subscription.updated',
682
- value: 'subscription',
868
+ name: "subscription.updated",
869
+ value: "subscription",
683
870
  },
684
871
  ],
685
- default: ['payment'],
686
- description: 'Eventos para os quais o webhook será notificado',
872
+ default: ["payment"],
873
+ description: "Eventos para os quais o webhook será notificado",
687
874
  },
688
875
  {
689
- displayName: 'Descrição',
690
- name: 'description',
691
- type: 'string',
876
+ displayName: "Descrição",
877
+ name: "description",
878
+ type: "string",
692
879
  displayOptions: {
693
880
  show: {
694
- resource: ['webhooks'],
695
- operation: ['register'],
881
+ resource: ["webhooks"],
882
+ operation: ["register"],
696
883
  },
697
884
  },
698
- default: '',
699
- description: 'Descrição do webhook',
885
+ default: "",
886
+ description: "Descrição do webhook",
700
887
  },
701
888
  {
702
- displayName: 'ID do Webhook',
703
- name: 'webhookId',
704
- type: 'string',
889
+ displayName: "ID do Webhook",
890
+ name: "webhookId",
891
+ type: "string",
705
892
  required: true,
706
893
  displayOptions: {
707
894
  show: {
708
- resource: ['webhooks'],
709
- operation: ['get', 'delete'],
895
+ resource: ["webhooks"],
896
+ operation: ["get", "delete"],
710
897
  },
711
898
  },
712
- default: '',
713
- description: 'ID do webhook',
899
+ default: "",
900
+ description: "ID do webhook",
714
901
  },
715
902
  ],
716
903
  };
@@ -718,18 +905,18 @@ class PixPayment {
718
905
  async execute() {
719
906
  const items = this.getInputData();
720
907
  const returnData = [];
721
- const credentials = (await this.getCredentials('pixPaymentApi'));
908
+ const credentials = (await this.getCredentials("pixPaymentApi"));
722
909
  const baseUrl = (0, helpers_1.getBaseUrl)(credentials.environment);
723
910
  for (let i = 0; i < items.length; i++) {
724
911
  try {
725
912
  let resource;
726
913
  let operation;
727
914
  try {
728
- resource = this.getNodeParameter('resource', i);
729
- operation = this.getNodeParameter('operation', i);
915
+ resource = this.getNodeParameter("resource", i);
916
+ operation = this.getNodeParameter("operation", i);
730
917
  }
731
918
  catch (error) {
732
- if (error?.message?.includes('Could not get parameter')) {
919
+ if (error?.message?.includes("Could not get parameter")) {
733
920
  throw new Error(`Erro ao obter parâmetros do node. Verifique se os campos "Resource" e "Operation" estão preenchidos corretamente. ` +
734
921
  `Detalhes: ${error.message}`);
735
922
  }
@@ -737,19 +924,19 @@ class PixPayment {
737
924
  }
738
925
  let responseData;
739
926
  switch (resource) {
740
- case 'pix':
927
+ case "pix":
741
928
  responseData = await PixPayment.handlePixOperation(this, operation, i, baseUrl, credentials);
742
929
  break;
743
- case 'plans':
930
+ case "plans":
744
931
  responseData = await PixPayment.handlePlanOperation(this, operation, i, baseUrl, credentials);
745
932
  break;
746
- case 'subscriptions':
933
+ case "subscriptions":
747
934
  responseData = await PixPayment.handleSubscriptionOperation(this, operation, i, baseUrl, credentials);
748
935
  break;
749
- case 'recurringPayments':
936
+ case "recurringPayments":
750
937
  responseData = await PixPayment.handleRecurringPaymentOperation(this, operation, i, baseUrl, credentials);
751
938
  break;
752
- case 'webhooks':
939
+ case "webhooks":
753
940
  responseData = await PixPayment.handleWebhookOperation(this, operation, i, baseUrl, credentials);
754
941
  break;
755
942
  default:
@@ -779,36 +966,37 @@ class PixPayment {
779
966
  }
780
967
  static async handlePixOperation(executeFunctions, operation, itemIndex, baseUrl, credentials) {
781
968
  switch (operation) {
782
- case 'create':
969
+ case "create":
783
970
  return await PixPayment.createPixPayment(executeFunctions, itemIndex, baseUrl, credentials);
784
- case 'get':
971
+ case "get":
785
972
  return await PixPayment.getPixPayment(executeFunctions, itemIndex, baseUrl, credentials);
786
- case 'refund':
973
+ case "refund":
787
974
  return await PixPayment.refundPixPayment(executeFunctions, itemIndex, baseUrl, credentials);
788
975
  default:
789
976
  throw new Error(`Operação PIX "${operation}" não é suportada`);
790
977
  }
791
978
  }
792
979
  static async createPixPayment(executeFunctions, itemIndex, baseUrl, credentials) {
793
- const amount = executeFunctions.getNodeParameter('amount', itemIndex);
794
- const description = executeFunctions.getNodeParameter('description', itemIndex);
795
- const payerEmail = executeFunctions.getNodeParameter('payerEmail', itemIndex);
796
- const payerDocument = executeFunctions.getNodeParameter('payerDocument', itemIndex);
797
- const payerName = executeFunctions.getNodeParameter('payerName', itemIndex);
798
- const expirationDate = executeFunctions.getNodeParameter('expirationDate', itemIndex);
799
- const externalReference = executeFunctions.getNodeParameter('externalReference', itemIndex);
800
- const idempotencyKey = executeFunctions.getNodeParameter('idempotencyKey', itemIndex);
980
+ const amount = executeFunctions.getNodeParameter("amount", itemIndex);
981
+ const description = executeFunctions.getNodeParameter("description", itemIndex);
982
+ const payerEmail = executeFunctions.getNodeParameter("payerEmail", itemIndex);
983
+ // Usar getNodeParameterSafe para campos opcionais
984
+ const payerDocument = (0, helpers_1.getNodeParameterSafe)(executeFunctions.getNodeParameter.bind(executeFunctions), "payerDocument", itemIndex, "");
985
+ const payerName = (0, helpers_1.getNodeParameterSafe)(executeFunctions.getNodeParameter.bind(executeFunctions), "payerName", itemIndex, "");
986
+ const expirationDate = (0, helpers_1.getNodeParameterSafe)(executeFunctions.getNodeParameter.bind(executeFunctions), "expirationDate", itemIndex, "");
987
+ const externalReference = (0, helpers_1.getNodeParameterSafe)(executeFunctions.getNodeParameter.bind(executeFunctions), "externalReference", itemIndex, "");
988
+ const idempotencyKey = (0, helpers_1.getNodeParameterSafe)(executeFunctions.getNodeParameter.bind(executeFunctions), "idempotencyKey", itemIndex, "");
801
989
  // Validações
802
990
  if (!(0, helpers_1.validateEmail)(payerEmail)) {
803
- throw new Error('E-mail do pagador inválido');
991
+ throw new Error("E-mail do pagador inválido");
804
992
  }
805
993
  if (amount <= 0) {
806
- throw new Error('Valor do pagamento deve ser maior que zero');
994
+ throw new Error("Valor do pagamento deve ser maior que zero");
807
995
  }
808
996
  const body = {
809
997
  transaction_amount: (0, helpers_1.normalizeAmount)(amount),
810
998
  description,
811
- payment_method_id: 'pix',
999
+ payment_method_id: "pix",
812
1000
  payer: {
813
1001
  email: payerEmail,
814
1002
  },
@@ -816,7 +1004,7 @@ class PixPayment {
816
1004
  if (payerDocument) {
817
1005
  const docType = (0, helpers_1.getDocumentType)(payerDocument);
818
1006
  if (!docType) {
819
- throw new Error('CPF/CNPJ inválido. Deve conter 11 ou 14 dígitos numéricos');
1007
+ throw new Error("CPF/CNPJ inválido. Deve conter 11 ou 14 dígitos numéricos");
820
1008
  }
821
1009
  body.payer.identification = {
822
1010
  type: docType,
@@ -824,9 +1012,9 @@ class PixPayment {
824
1012
  };
825
1013
  }
826
1014
  if (payerName) {
827
- const nameParts = payerName.trim().split(' ');
828
- body.payer.first_name = nameParts[0] || '';
829
- body.payer.last_name = nameParts.slice(1).join(' ') || '';
1015
+ const nameParts = payerName.trim().split(" ");
1016
+ body.payer.first_name = nameParts[0] || "";
1017
+ body.payer.last_name = nameParts.slice(1).join(" ") || "";
830
1018
  }
831
1019
  if (expirationDate) {
832
1020
  body.date_of_expiration = new Date(expirationDate).toISOString();
@@ -836,13 +1024,13 @@ class PixPayment {
836
1024
  }
837
1025
  const headers = {
838
1026
  Authorization: `Bearer ${credentials.accessToken}`,
839
- 'Content-Type': 'application/json',
1027
+ "Content-Type": "application/json",
840
1028
  };
841
- if (idempotencyKey && idempotencyKey.trim() !== '') {
842
- headers['X-Idempotency-Key'] = idempotencyKey;
1029
+ if (idempotencyKey && idempotencyKey.trim() !== "") {
1030
+ headers["X-Idempotency-Key"] = idempotencyKey;
843
1031
  }
844
- const response = await executeFunctions.helpers.requestWithAuthentication.call(executeFunctions, 'pixPaymentApi', {
845
- method: 'POST',
1032
+ const response = await executeFunctions.helpers.requestWithAuthentication.call(executeFunctions, "pixPaymentApi", {
1033
+ method: "POST",
846
1034
  url: `${baseUrl}/v1/payments`,
847
1035
  body,
848
1036
  headers,
@@ -851,12 +1039,12 @@ class PixPayment {
851
1039
  return response;
852
1040
  }
853
1041
  static async getPixPayment(executeFunctions, itemIndex, baseUrl, credentials) {
854
- const paymentId = executeFunctions.getNodeParameter('paymentId', itemIndex);
1042
+ const paymentId = executeFunctions.getNodeParameter("paymentId", itemIndex);
855
1043
  if (!paymentId) {
856
- throw new Error('ID do pagamento é obrigatório');
1044
+ throw new Error("ID do pagamento é obrigatório");
857
1045
  }
858
- const response = await executeFunctions.helpers.requestWithAuthentication.call(executeFunctions, 'pixPaymentApi', {
859
- method: 'GET',
1046
+ const response = await executeFunctions.helpers.requestWithAuthentication.call(executeFunctions, "pixPaymentApi", {
1047
+ method: "GET",
860
1048
  url: `${baseUrl}/v1/payments/${paymentId}`,
861
1049
  headers: {
862
1050
  Authorization: `Bearer ${credentials.accessToken}`,
@@ -866,22 +1054,23 @@ class PixPayment {
866
1054
  return response;
867
1055
  }
868
1056
  static async refundPixPayment(executeFunctions, itemIndex, baseUrl, credentials) {
869
- const paymentId = executeFunctions.getNodeParameter('paymentId', itemIndex);
870
- const refundAmount = executeFunctions.getNodeParameter('refundAmount', itemIndex);
1057
+ const paymentId = executeFunctions.getNodeParameter("paymentId", itemIndex);
1058
+ // Usar getNodeParameterSafe para campo opcional
1059
+ const refundAmount = (0, helpers_1.getNodeParameterSafe)(executeFunctions.getNodeParameter.bind(executeFunctions), "refundAmount", itemIndex, 0);
871
1060
  if (!paymentId) {
872
- throw new Error('ID do pagamento é obrigatório');
1061
+ throw new Error("ID do pagamento é obrigatório");
873
1062
  }
874
1063
  const body = {};
875
1064
  if (refundAmount && refundAmount > 0) {
876
1065
  body.amount = (0, helpers_1.normalizeAmount)(refundAmount);
877
1066
  }
878
- const response = await executeFunctions.helpers.requestWithAuthentication.call(executeFunctions, 'pixPaymentApi', {
879
- method: 'POST',
1067
+ const response = await executeFunctions.helpers.requestWithAuthentication.call(executeFunctions, "pixPaymentApi", {
1068
+ method: "POST",
880
1069
  url: `${baseUrl}/v1/payments/${paymentId}/refunds`,
881
1070
  body: Object.keys(body).length > 0 ? body : undefined,
882
1071
  headers: {
883
1072
  Authorization: `Bearer ${credentials.accessToken}`,
884
- 'Content-Type': 'application/json',
1073
+ "Content-Type": "application/json",
885
1074
  },
886
1075
  json: true,
887
1076
  });
@@ -889,72 +1078,117 @@ class PixPayment {
889
1078
  }
890
1079
  static async handlePlanOperation(executeFunctions, operation, itemIndex, baseUrl, credentials) {
891
1080
  switch (operation) {
892
- case 'create':
1081
+ case "create":
893
1082
  return await PixPayment.createPlan(executeFunctions, itemIndex, baseUrl, credentials);
894
- case 'get':
1083
+ case "get":
895
1084
  return await PixPayment.getPlan(executeFunctions, itemIndex, baseUrl, credentials);
896
- case 'list':
1085
+ case "list":
897
1086
  return await PixPayment.listPlans(executeFunctions, itemIndex, baseUrl, credentials);
898
- case 'update':
1087
+ case "update":
899
1088
  return await PixPayment.updatePlan(executeFunctions, itemIndex, baseUrl, credentials);
900
1089
  default:
901
1090
  throw new Error(`Operação de plano "${operation}" não é suportada`);
902
1091
  }
903
1092
  }
904
1093
  static async createPlan(executeFunctions, itemIndex, baseUrl, credentials) {
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');
1094
+ // Campos obrigatórios
1095
+ const reason = (0, helpers_1.getNodeParameterSafe)(executeFunctions.getNodeParameter.bind(executeFunctions), "reason", itemIndex, "");
1096
+ const amountRaw = (0, helpers_1.getNodeParameterSafe)(executeFunctions.getNodeParameter.bind(executeFunctions), "amount", itemIndex, 0);
1097
+ const frequencyRaw = (0, helpers_1.getNodeParameterSafe)(executeFunctions.getNodeParameter.bind(executeFunctions), "frequency", itemIndex, 1);
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, []);
909
1109
  // Normaliza valores numéricos (converte vírgula para ponto)
910
1110
  const amount = (0, helpers_1.normalizeNumericValue)(amountRaw);
911
1111
  const frequency = (0, helpers_1.normalizeNumericValue)(frequencyRaw);
912
- if (!reason || reason.trim() === '') {
913
- throw new Error('Nome do plano é obrigatório');
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
1122
+ if (!reason || reason.trim() === "") {
1123
+ throw new Error("Nome do plano é obrigatório");
914
1124
  }
915
1125
  if (amount <= 0) {
916
- throw new Error('Valor do plano deve ser maior que zero');
1126
+ throw new Error("Valor do plano deve ser maior que zero");
917
1127
  }
918
1128
  if (frequency <= 0) {
919
- throw new Error('Frequência deve ser maior que zero');
1129
+ throw new Error("Frequência deve ser maior que zero");
920
1130
  }
921
- if (frequencyType !== 'days' && frequencyType !== 'months') {
1131
+ if (frequencyType !== "days" && frequencyType !== "months") {
922
1132
  throw new Error('Tipo de frequência deve ser "days" ou "months"');
923
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
924
1167
  const body = {
925
1168
  reason,
926
- auto_recurring: {
927
- frequency,
928
- frequency_type: frequencyType,
929
- transaction_amount: (0, helpers_1.normalizeAmount)(amount),
930
- currency_id: 'BRL',
931
- },
932
- payment_methods_allowed: {
933
- payment_types: [
934
- { id: 'credit_card' },
935
- ],
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
- const response = await executeFunctions.helpers.requestWithAuthentication.call(executeFunctions, 'pixPaymentApi', {
940
- method: 'POST',
1173
+ const response = await executeFunctions.helpers.requestWithAuthentication.call(executeFunctions, "pixPaymentApi", {
1174
+ method: "POST",
941
1175
  url: `${baseUrl}/preapproval_plan`,
942
1176
  body,
943
1177
  headers: {
944
1178
  Authorization: `Bearer ${credentials.accessToken}`,
945
- 'Content-Type': 'application/json',
1179
+ "Content-Type": "application/json",
946
1180
  },
947
1181
  json: true,
948
1182
  });
949
1183
  return response;
950
1184
  }
951
1185
  static async getPlan(executeFunctions, itemIndex, baseUrl, credentials) {
952
- const planId = executeFunctions.getNodeParameter('planId', itemIndex);
953
- if (!planId || planId.trim() === '') {
954
- throw new Error('ID do plano é obrigatório');
1186
+ const planId = executeFunctions.getNodeParameter("planId", itemIndex);
1187
+ if (!planId || planId.trim() === "") {
1188
+ throw new Error("ID do plano é obrigatório");
955
1189
  }
956
- const response = await executeFunctions.helpers.requestWithAuthentication.call(executeFunctions, 'pixPaymentApi', {
957
- method: 'GET',
1190
+ const response = await executeFunctions.helpers.requestWithAuthentication.call(executeFunctions, "pixPaymentApi", {
1191
+ method: "GET",
958
1192
  url: `${baseUrl}/preapproval_plan/${planId}`,
959
1193
  headers: {
960
1194
  Authorization: `Bearer ${credentials.accessToken}`,
@@ -964,8 +1198,8 @@ class PixPayment {
964
1198
  return response;
965
1199
  }
966
1200
  static async listPlans(executeFunctions, _itemIndex, baseUrl, credentials) {
967
- const response = await executeFunctions.helpers.requestWithAuthentication.call(executeFunctions, 'pixPaymentApi', {
968
- method: 'GET',
1201
+ const response = await executeFunctions.helpers.requestWithAuthentication.call(executeFunctions, "pixPaymentApi", {
1202
+ method: "GET",
969
1203
  url: `${baseUrl}/preapproval_plan/search`,
970
1204
  headers: {
971
1205
  Authorization: `Bearer ${credentials.accessToken}`,
@@ -975,16 +1209,16 @@ class PixPayment {
975
1209
  return response;
976
1210
  }
977
1211
  static async updatePlan(executeFunctions, itemIndex, baseUrl, credentials) {
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);
981
- if (!planId || planId.trim() === '') {
982
- throw new Error('ID do plano é obrigatório');
1212
+ const planId = (0, helpers_1.getNodeParameterSafe)(executeFunctions.getNodeParameter.bind(executeFunctions), "planId", itemIndex, "");
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);
1215
+ if (!planId || planId.trim() === "") {
1216
+ throw new Error("ID do plano é obrigatório");
983
1217
  }
984
1218
  // Normaliza valor numérico (converte vírgula para ponto)
985
1219
  const amount = (0, helpers_1.normalizeNumericValue)(amountRaw);
986
1220
  const body = {};
987
- if (reason && reason.trim() !== '') {
1221
+ if (reason && reason.trim() !== "") {
988
1222
  body.reason = reason;
989
1223
  }
990
1224
  if (amount && amount > 0) {
@@ -993,15 +1227,15 @@ class PixPayment {
993
1227
  };
994
1228
  }
995
1229
  if (Object.keys(body).length === 0) {
996
- throw new Error('É necessário fornecer pelo menos um campo para atualizar (nome ou valor)');
1230
+ throw new Error("É necessário fornecer pelo menos um campo para atualizar (nome ou valor)");
997
1231
  }
998
- const response = await executeFunctions.helpers.requestWithAuthentication.call(executeFunctions, 'pixPaymentApi', {
999
- method: 'PUT',
1232
+ const response = await executeFunctions.helpers.requestWithAuthentication.call(executeFunctions, "pixPaymentApi", {
1233
+ method: "PUT",
1000
1234
  url: `${baseUrl}/preapproval_plan/${planId}`,
1001
1235
  body,
1002
1236
  headers: {
1003
1237
  Authorization: `Bearer ${credentials.accessToken}`,
1004
- 'Content-Type': 'application/json',
1238
+ "Content-Type": "application/json",
1005
1239
  },
1006
1240
  json: true,
1007
1241
  });
@@ -1009,39 +1243,40 @@ class PixPayment {
1009
1243
  }
1010
1244
  static async handleSubscriptionOperation(executeFunctions, operation, itemIndex, baseUrl, credentials) {
1011
1245
  switch (operation) {
1012
- case 'create':
1246
+ case "create":
1013
1247
  return await PixPayment.createSubscription(executeFunctions, itemIndex, baseUrl, credentials);
1014
- case 'get':
1248
+ case "get":
1015
1249
  return await PixPayment.getSubscription(executeFunctions, itemIndex, baseUrl, credentials);
1016
- case 'pause':
1250
+ case "pause":
1017
1251
  return await PixPayment.pauseSubscription(executeFunctions, itemIndex, baseUrl, credentials);
1018
- case 'resume':
1252
+ case "resume":
1019
1253
  return await PixPayment.resumeSubscription(executeFunctions, itemIndex, baseUrl, credentials);
1020
- case 'cancel':
1254
+ case "cancel":
1021
1255
  return await PixPayment.cancelSubscription(executeFunctions, itemIndex, baseUrl, credentials);
1022
- case 'list':
1256
+ case "list":
1023
1257
  return await PixPayment.listSubscriptions(executeFunctions, itemIndex, baseUrl, credentials);
1024
1258
  default:
1025
1259
  throw new Error(`Operação de assinatura "${operation}" não é suportada`);
1026
1260
  }
1027
1261
  }
1028
1262
  static async createSubscription(executeFunctions, itemIndex, baseUrl, credentials) {
1029
- const planId = executeFunctions.getNodeParameter('planId', itemIndex);
1030
- const payerEmail = executeFunctions.getNodeParameter('payerEmail', itemIndex);
1031
- const payerDocument = executeFunctions.getNodeParameter('payerDocument', itemIndex);
1032
- const startDate = executeFunctions.getNodeParameter('startDate', itemIndex);
1033
- const trialPeriodDays = executeFunctions.getNodeParameter('trialPeriodDays', itemIndex);
1263
+ const planId = executeFunctions.getNodeParameter("planId", itemIndex);
1264
+ const payerEmail = executeFunctions.getNodeParameter("payerEmail", itemIndex);
1265
+ // Usar getNodeParameterSafe para campos opcionais
1266
+ const payerDocument = (0, helpers_1.getNodeParameterSafe)(executeFunctions.getNodeParameter.bind(executeFunctions), "payerDocument", itemIndex, "");
1267
+ const startDate = (0, helpers_1.getNodeParameterSafe)(executeFunctions.getNodeParameter.bind(executeFunctions), "startDate", itemIndex, "");
1268
+ const trialPeriodDays = (0, helpers_1.getNodeParameterSafe)(executeFunctions.getNodeParameter.bind(executeFunctions), "trialPeriodDays", itemIndex, 0);
1034
1269
  if (!(0, helpers_1.validateEmail)(payerEmail)) {
1035
- throw new Error('E-mail do pagador inválido');
1270
+ throw new Error("E-mail do pagador inválido");
1036
1271
  }
1037
1272
  const body = {
1038
1273
  preapproval_plan_id: planId,
1039
1274
  payer_email: payerEmail,
1040
1275
  };
1041
- if (payerDocument) {
1276
+ if (payerDocument && payerDocument.trim() !== "") {
1042
1277
  const docType = (0, helpers_1.getDocumentType)(payerDocument);
1043
1278
  if (!docType) {
1044
- throw new Error('CPF/CNPJ inválido');
1279
+ throw new Error("CPF/CNPJ inválido");
1045
1280
  }
1046
1281
  body.payer = {
1047
1282
  identification: {
@@ -1050,28 +1285,28 @@ class PixPayment {
1050
1285
  },
1051
1286
  };
1052
1287
  }
1053
- if (startDate) {
1288
+ if (startDate && startDate.trim() !== "") {
1054
1289
  body.start_date = new Date(startDate).toISOString();
1055
1290
  }
1056
1291
  if (trialPeriodDays && trialPeriodDays > 0) {
1057
1292
  body.trial_period_days = trialPeriodDays;
1058
1293
  }
1059
- const response = await executeFunctions.helpers.requestWithAuthentication.call(executeFunctions, 'pixPaymentApi', {
1060
- method: 'POST',
1294
+ const response = await executeFunctions.helpers.requestWithAuthentication.call(executeFunctions, "pixPaymentApi", {
1295
+ method: "POST",
1061
1296
  url: `${baseUrl}/preapproval`,
1062
1297
  body,
1063
1298
  headers: {
1064
1299
  Authorization: `Bearer ${credentials.accessToken}`,
1065
- 'Content-Type': 'application/json',
1300
+ "Content-Type": "application/json",
1066
1301
  },
1067
1302
  json: true,
1068
1303
  });
1069
1304
  return response;
1070
1305
  }
1071
1306
  static async getSubscription(executeFunctions, itemIndex, baseUrl, credentials) {
1072
- const subscriptionId = executeFunctions.getNodeParameter('subscriptionId', itemIndex);
1073
- const response = await executeFunctions.helpers.requestWithAuthentication.call(executeFunctions, 'pixPaymentApi', {
1074
- method: 'GET',
1307
+ const subscriptionId = executeFunctions.getNodeParameter("subscriptionId", itemIndex);
1308
+ const response = await executeFunctions.helpers.requestWithAuthentication.call(executeFunctions, "pixPaymentApi", {
1309
+ method: "GET",
1075
1310
  url: `${baseUrl}/preapproval/${subscriptionId}`,
1076
1311
  headers: {
1077
1312
  Authorization: `Bearer ${credentials.accessToken}`,
@@ -1081,56 +1316,56 @@ class PixPayment {
1081
1316
  return response;
1082
1317
  }
1083
1318
  static async pauseSubscription(executeFunctions, itemIndex, baseUrl, credentials) {
1084
- const subscriptionId = executeFunctions.getNodeParameter('subscriptionId', itemIndex);
1085
- const response = await executeFunctions.helpers.requestWithAuthentication.call(executeFunctions, 'pixPaymentApi', {
1086
- method: 'PUT',
1319
+ const subscriptionId = executeFunctions.getNodeParameter("subscriptionId", itemIndex);
1320
+ const response = await executeFunctions.helpers.requestWithAuthentication.call(executeFunctions, "pixPaymentApi", {
1321
+ method: "PUT",
1087
1322
  url: `${baseUrl}/preapproval/${subscriptionId}`,
1088
1323
  body: {
1089
- status: 'paused',
1324
+ status: "paused",
1090
1325
  },
1091
1326
  headers: {
1092
1327
  Authorization: `Bearer ${credentials.accessToken}`,
1093
- 'Content-Type': 'application/json',
1328
+ "Content-Type": "application/json",
1094
1329
  },
1095
1330
  json: true,
1096
1331
  });
1097
1332
  return response;
1098
1333
  }
1099
1334
  static async resumeSubscription(executeFunctions, itemIndex, baseUrl, credentials) {
1100
- const subscriptionId = executeFunctions.getNodeParameter('subscriptionId', itemIndex);
1101
- const response = await executeFunctions.helpers.requestWithAuthentication.call(executeFunctions, 'pixPaymentApi', {
1102
- method: 'PUT',
1335
+ const subscriptionId = executeFunctions.getNodeParameter("subscriptionId", itemIndex);
1336
+ const response = await executeFunctions.helpers.requestWithAuthentication.call(executeFunctions, "pixPaymentApi", {
1337
+ method: "PUT",
1103
1338
  url: `${baseUrl}/preapproval/${subscriptionId}`,
1104
1339
  body: {
1105
- status: 'authorized',
1340
+ status: "authorized",
1106
1341
  },
1107
1342
  headers: {
1108
1343
  Authorization: `Bearer ${credentials.accessToken}`,
1109
- 'Content-Type': 'application/json',
1344
+ "Content-Type": "application/json",
1110
1345
  },
1111
1346
  json: true,
1112
1347
  });
1113
1348
  return response;
1114
1349
  }
1115
1350
  static async cancelSubscription(executeFunctions, itemIndex, baseUrl, credentials) {
1116
- const subscriptionId = executeFunctions.getNodeParameter('subscriptionId', itemIndex);
1117
- const response = await executeFunctions.helpers.requestWithAuthentication.call(executeFunctions, 'pixPaymentApi', {
1118
- method: 'PUT',
1351
+ const subscriptionId = executeFunctions.getNodeParameter("subscriptionId", itemIndex);
1352
+ const response = await executeFunctions.helpers.requestWithAuthentication.call(executeFunctions, "pixPaymentApi", {
1353
+ method: "PUT",
1119
1354
  url: `${baseUrl}/preapproval/${subscriptionId}`,
1120
1355
  body: {
1121
- status: 'cancelled',
1356
+ status: "cancelled",
1122
1357
  },
1123
1358
  headers: {
1124
1359
  Authorization: `Bearer ${credentials.accessToken}`,
1125
- 'Content-Type': 'application/json',
1360
+ "Content-Type": "application/json",
1126
1361
  },
1127
1362
  json: true,
1128
1363
  });
1129
1364
  return response;
1130
1365
  }
1131
1366
  static async listSubscriptions(executeFunctions, _itemIndex, baseUrl, credentials) {
1132
- const response = await executeFunctions.helpers.requestWithAuthentication.call(executeFunctions, 'pixPaymentApi', {
1133
- method: 'GET',
1367
+ const response = await executeFunctions.helpers.requestWithAuthentication.call(executeFunctions, "pixPaymentApi", {
1368
+ method: "GET",
1134
1369
  url: `${baseUrl}/preapproval/search`,
1135
1370
  headers: {
1136
1371
  Authorization: `Bearer ${credentials.accessToken}`,
@@ -1141,24 +1376,24 @@ class PixPayment {
1141
1376
  }
1142
1377
  static async handleRecurringPaymentOperation(executeFunctions, operation, itemIndex, baseUrl, credentials) {
1143
1378
  switch (operation) {
1144
- case 'create':
1379
+ case "create":
1145
1380
  return await PixPayment.createRecurringPayment(executeFunctions, itemIndex, baseUrl, credentials);
1146
- case 'get':
1381
+ case "get":
1147
1382
  return await PixPayment.getRecurringPayment(executeFunctions, itemIndex, baseUrl, credentials);
1148
- case 'list':
1383
+ case "list":
1149
1384
  return await PixPayment.listRecurringPayments(executeFunctions, itemIndex, baseUrl, credentials);
1150
- case 'cancel':
1385
+ case "cancel":
1151
1386
  return await PixPayment.cancelRecurringPayment(executeFunctions, itemIndex, baseUrl, credentials);
1152
1387
  default:
1153
1388
  throw new Error(`Operação de pagamento recorrente "${operation}" não é suportada`);
1154
1389
  }
1155
1390
  }
1156
1391
  static async createRecurringPayment(executeFunctions, itemIndex, baseUrl, credentials) {
1157
- const planId = executeFunctions.getNodeParameter('planId', itemIndex);
1392
+ const planId = executeFunctions.getNodeParameter("planId", itemIndex);
1158
1393
  // Para pagamentos recorrentes, geralmente criamos via assinatura
1159
1394
  // Esta é uma implementação simplificada
1160
- const response = await executeFunctions.helpers.requestWithAuthentication.call(executeFunctions, 'pixPaymentApi', {
1161
- method: 'GET',
1395
+ const response = await executeFunctions.helpers.requestWithAuthentication.call(executeFunctions, "pixPaymentApi", {
1396
+ method: "GET",
1162
1397
  url: `${baseUrl}/preapproval/${planId}`,
1163
1398
  headers: {
1164
1399
  Authorization: `Bearer ${credentials.accessToken}`,
@@ -1168,9 +1403,9 @@ class PixPayment {
1168
1403
  return response;
1169
1404
  }
1170
1405
  static async getRecurringPayment(executeFunctions, itemIndex, baseUrl, credentials) {
1171
- const recurringPaymentId = executeFunctions.getNodeParameter('recurringPaymentId', itemIndex);
1172
- const response = await executeFunctions.helpers.requestWithAuthentication.call(executeFunctions, 'pixPaymentApi', {
1173
- method: 'GET',
1406
+ const recurringPaymentId = executeFunctions.getNodeParameter("recurringPaymentId", itemIndex);
1407
+ const response = await executeFunctions.helpers.requestWithAuthentication.call(executeFunctions, "pixPaymentApi", {
1408
+ method: "GET",
1174
1409
  url: `${baseUrl}/preapproval/${recurringPaymentId}`,
1175
1410
  headers: {
1176
1411
  Authorization: `Bearer ${credentials.accessToken}`,
@@ -1180,13 +1415,14 @@ class PixPayment {
1180
1415
  return response;
1181
1416
  }
1182
1417
  static async listRecurringPayments(executeFunctions, itemIndex, baseUrl, credentials) {
1183
- const customerId = executeFunctions.getNodeParameter('customerId', itemIndex);
1418
+ // Usar getNodeParameterSafe para campo opcional
1419
+ const customerId = (0, helpers_1.getNodeParameterSafe)(executeFunctions.getNodeParameter.bind(executeFunctions), "customerId", itemIndex, "");
1184
1420
  let url = `${baseUrl}/preapproval/search`;
1185
1421
  if (customerId) {
1186
1422
  url += `?payer_id=${customerId}`;
1187
1423
  }
1188
- const response = await executeFunctions.helpers.requestWithAuthentication.call(executeFunctions, 'pixPaymentApi', {
1189
- method: 'GET',
1424
+ const response = await executeFunctions.helpers.requestWithAuthentication.call(executeFunctions, "pixPaymentApi", {
1425
+ method: "GET",
1190
1426
  url,
1191
1427
  headers: {
1192
1428
  Authorization: `Bearer ${credentials.accessToken}`,
@@ -1196,16 +1432,16 @@ class PixPayment {
1196
1432
  return response;
1197
1433
  }
1198
1434
  static async cancelRecurringPayment(executeFunctions, itemIndex, baseUrl, credentials) {
1199
- const recurringPaymentId = executeFunctions.getNodeParameter('recurringPaymentId', itemIndex);
1200
- const response = await executeFunctions.helpers.requestWithAuthentication.call(executeFunctions, 'pixPaymentApi', {
1201
- method: 'PUT',
1435
+ const recurringPaymentId = executeFunctions.getNodeParameter("recurringPaymentId", itemIndex);
1436
+ const response = await executeFunctions.helpers.requestWithAuthentication.call(executeFunctions, "pixPaymentApi", {
1437
+ method: "PUT",
1202
1438
  url: `${baseUrl}/preapproval/${recurringPaymentId}`,
1203
1439
  body: {
1204
- status: 'cancelled',
1440
+ status: "cancelled",
1205
1441
  },
1206
1442
  headers: {
1207
1443
  Authorization: `Bearer ${credentials.accessToken}`,
1208
- 'Content-Type': 'application/json',
1444
+ "Content-Type": "application/json",
1209
1445
  },
1210
1446
  json: true,
1211
1447
  });
@@ -1213,48 +1449,49 @@ class PixPayment {
1213
1449
  }
1214
1450
  static async handleWebhookOperation(executeFunctions, operation, itemIndex, baseUrl, credentials) {
1215
1451
  switch (operation) {
1216
- case 'register':
1452
+ case "register":
1217
1453
  return await PixPayment.registerWebhook(executeFunctions, itemIndex, baseUrl, credentials);
1218
- case 'get':
1454
+ case "get":
1219
1455
  return await PixPayment.getWebhook(executeFunctions, itemIndex, baseUrl, credentials);
1220
- case 'list':
1456
+ case "list":
1221
1457
  return await PixPayment.listWebhooks(executeFunctions, itemIndex, baseUrl, credentials);
1222
- case 'delete':
1458
+ case "delete":
1223
1459
  return await PixPayment.deleteWebhook(executeFunctions, itemIndex, baseUrl, credentials);
1224
1460
  default:
1225
1461
  throw new Error(`Operação de webhook "${operation}" não é suportada`);
1226
1462
  }
1227
1463
  }
1228
1464
  static async registerWebhook(executeFunctions, itemIndex, baseUrl, credentials) {
1229
- const url = executeFunctions.getNodeParameter('url', itemIndex);
1230
- const events = executeFunctions.getNodeParameter('events', itemIndex);
1231
- const description = executeFunctions.getNodeParameter('description', itemIndex);
1232
- if (!url || !url.startsWith('http')) {
1233
- throw new Error('URL do webhook deve ser uma URL válida (http:// ou https://)');
1465
+ const url = executeFunctions.getNodeParameter("url", itemIndex);
1466
+ // Usar getNodeParameterSafe para campos opcionais
1467
+ const events = (0, helpers_1.getNodeParameterSafe)(executeFunctions.getNodeParameter.bind(executeFunctions), "events", itemIndex, []);
1468
+ const description = (0, helpers_1.getNodeParameterSafe)(executeFunctions.getNodeParameter.bind(executeFunctions), "description", itemIndex, "");
1469
+ if (!url || !url.startsWith("http")) {
1470
+ throw new Error("URL do webhook deve ser uma URL válida (http:// ou https://)");
1234
1471
  }
1235
1472
  const body = {
1236
1473
  url,
1237
- events: events.length > 0 ? events : ['payment'],
1474
+ events: events.length > 0 ? events : ["payment"],
1238
1475
  };
1239
1476
  if (description) {
1240
1477
  body.description = description;
1241
1478
  }
1242
- const response = await executeFunctions.helpers.requestWithAuthentication.call(executeFunctions, 'pixPaymentApi', {
1243
- method: 'POST',
1479
+ const response = await executeFunctions.helpers.requestWithAuthentication.call(executeFunctions, "pixPaymentApi", {
1480
+ method: "POST",
1244
1481
  url: `${baseUrl}/v1/webhooks`,
1245
1482
  body,
1246
1483
  headers: {
1247
1484
  Authorization: `Bearer ${credentials.accessToken}`,
1248
- 'Content-Type': 'application/json',
1485
+ "Content-Type": "application/json",
1249
1486
  },
1250
1487
  json: true,
1251
1488
  });
1252
1489
  return response;
1253
1490
  }
1254
1491
  static async getWebhook(executeFunctions, itemIndex, baseUrl, credentials) {
1255
- const webhookId = executeFunctions.getNodeParameter('webhookId', itemIndex);
1256
- const response = await executeFunctions.helpers.requestWithAuthentication.call(executeFunctions, 'pixPaymentApi', {
1257
- method: 'GET',
1492
+ const webhookId = executeFunctions.getNodeParameter("webhookId", itemIndex);
1493
+ const response = await executeFunctions.helpers.requestWithAuthentication.call(executeFunctions, "pixPaymentApi", {
1494
+ method: "GET",
1258
1495
  url: `${baseUrl}/v1/webhooks/${webhookId}`,
1259
1496
  headers: {
1260
1497
  Authorization: `Bearer ${credentials.accessToken}`,
@@ -1264,8 +1501,8 @@ class PixPayment {
1264
1501
  return response;
1265
1502
  }
1266
1503
  static async listWebhooks(executeFunctions, _itemIndex, baseUrl, credentials) {
1267
- const response = await executeFunctions.helpers.requestWithAuthentication.call(executeFunctions, 'pixPaymentApi', {
1268
- method: 'GET',
1504
+ const response = await executeFunctions.helpers.requestWithAuthentication.call(executeFunctions, "pixPaymentApi", {
1505
+ method: "GET",
1269
1506
  url: `${baseUrl}/v1/webhooks`,
1270
1507
  headers: {
1271
1508
  Authorization: `Bearer ${credentials.accessToken}`,
@@ -1275,9 +1512,9 @@ class PixPayment {
1275
1512
  return response;
1276
1513
  }
1277
1514
  static async deleteWebhook(executeFunctions, itemIndex, baseUrl, credentials) {
1278
- const webhookId = executeFunctions.getNodeParameter('webhookId', itemIndex);
1279
- const response = await executeFunctions.helpers.requestWithAuthentication.call(executeFunctions, 'pixPaymentApi', {
1280
- method: 'DELETE',
1515
+ const webhookId = executeFunctions.getNodeParameter("webhookId", itemIndex);
1516
+ const response = await executeFunctions.helpers.requestWithAuthentication.call(executeFunctions, "pixPaymentApi", {
1517
+ method: "DELETE",
1281
1518
  url: `${baseUrl}/v1/webhooks/${webhookId}`,
1282
1519
  headers: {
1283
1520
  Authorization: `Bearer ${credentials.accessToken}`,
@@ -1288,39 +1525,45 @@ class PixPayment {
1288
1525
  }
1289
1526
  static normalizeResponse(data, resource) {
1290
1527
  const normalized = {
1291
- id: data.id || '',
1292
- status: data.status || '',
1528
+ id: data.id || "",
1529
+ status: data.status || "",
1293
1530
  createdAt: data.date_created || data.created_at || new Date().toISOString(),
1294
1531
  raw: data,
1295
1532
  };
1296
1533
  // Normalização específica por recurso
1297
1534
  switch (resource) {
1298
- case 'pix':
1299
- normalized.amount = data.transaction_amount ? data.transaction_amount / 100 : undefined;
1300
- normalized.currency = data.currency_id || 'BRL';
1301
- normalized.qrCode = data.point_of_interaction?.transaction_data?.qr_code;
1302
- normalized.qrCodeBase64 = data.point_of_interaction?.transaction_data?.qr_code_base64;
1535
+ case "pix":
1536
+ normalized.amount = data.transaction_amount
1537
+ ? data.transaction_amount / 100
1538
+ : undefined;
1539
+ normalized.currency = data.currency_id || "BRL";
1540
+ normalized.qrCode =
1541
+ data.point_of_interaction?.transaction_data?.qr_code;
1542
+ normalized.qrCodeBase64 =
1543
+ data.point_of_interaction?.transaction_data?.qr_code_base64;
1303
1544
  normalized.description = data.description;
1304
1545
  normalized.payerEmail = data.payer?.email;
1305
1546
  break;
1306
- case 'plans':
1547
+ case "plans":
1307
1548
  normalized.planId = data.id;
1308
- normalized.amount = data.auto_recurring?.transaction_amount ? data.auto_recurring.transaction_amount / 100 : undefined;
1549
+ normalized.amount = data.auto_recurring?.transaction_amount
1550
+ ? data.auto_recurring.transaction_amount / 100
1551
+ : undefined;
1309
1552
  normalized.description = data.reason;
1310
1553
  break;
1311
- case 'subscriptions':
1554
+ case "subscriptions":
1312
1555
  normalized.planId = data.preapproval_plan_id;
1313
1556
  normalized.payerEmail = data.payer_email;
1314
1557
  normalized.startDate = data.start_date;
1315
1558
  normalized.endDate = data.end_date;
1316
1559
  normalized.statusDetail = data.status_detail;
1317
1560
  break;
1318
- case 'recurringPayments':
1561
+ case "recurringPayments":
1319
1562
  normalized.planId = data.preapproval_plan_id;
1320
1563
  normalized.payerEmail = data.payer_email;
1321
1564
  normalized.nextBillingDate = data.next_billing_date;
1322
1565
  break;
1323
- case 'webhooks':
1566
+ case "webhooks":
1324
1567
  normalized.url = data.url;
1325
1568
  normalized.events = data.events || [];
1326
1569
  normalized.description = data.description;