n8n-nodes-mercadopago-pix-assinatura 1.0.0
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.
- package/README.md +291 -0
- package/dist/credentials/PixPaymentApi.credentials.d.ts +7 -0
- package/dist/credentials/PixPaymentApi.credentials.js +58 -0
- package/dist/nodes/PixPayment/PixPayment.node.d.ts +27 -0
- package/dist/nodes/PixPayment/PixPayment.node.js +1041 -0
- package/dist/nodes/PixPayment/helpers.d.ts +38 -0
- package/dist/nodes/PixPayment/helpers.js +107 -0
- package/dist/nodes/PixPayment/mercadopago.svg +1 -0
- package/dist/nodes/PixPayment/types.d.ts +118 -0
- package/dist/nodes/PixPayment/types.js +2 -0
- package/package.json +75 -0
|
@@ -0,0 +1,1041 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PixPayment = void 0;
|
|
4
|
+
const helpers_1 = require("./helpers");
|
|
5
|
+
class PixPayment {
|
|
6
|
+
constructor() {
|
|
7
|
+
this.description = {
|
|
8
|
+
displayName: 'Mercado Pago PIX e Assinaturas',
|
|
9
|
+
name: 'pixPayment',
|
|
10
|
+
icon: 'file:mercadopago.svg',
|
|
11
|
+
group: ['transform'],
|
|
12
|
+
version: 1,
|
|
13
|
+
subtitle: '={{$parameter["resource"] + ": " + $parameter["operation"]}}',
|
|
14
|
+
description: 'Processamento de pagamentos PIX, assinaturas e webhooks via Mercado Pago',
|
|
15
|
+
defaults: {
|
|
16
|
+
name: 'Mercado Pago',
|
|
17
|
+
},
|
|
18
|
+
inputs: ['main'],
|
|
19
|
+
outputs: ['main'],
|
|
20
|
+
credentials: [
|
|
21
|
+
{
|
|
22
|
+
name: 'pixPaymentApi',
|
|
23
|
+
required: true,
|
|
24
|
+
},
|
|
25
|
+
],
|
|
26
|
+
properties: [
|
|
27
|
+
{
|
|
28
|
+
displayName: 'Resource',
|
|
29
|
+
name: 'resource',
|
|
30
|
+
type: 'options',
|
|
31
|
+
noDataExpression: true,
|
|
32
|
+
options: [
|
|
33
|
+
{
|
|
34
|
+
name: 'PIX',
|
|
35
|
+
value: 'pix',
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
name: 'Assinatura',
|
|
39
|
+
value: 'subscriptions',
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
name: 'Pagamento Recorrente',
|
|
43
|
+
value: 'recurringPayments',
|
|
44
|
+
},
|
|
45
|
+
{
|
|
46
|
+
name: 'Webhook',
|
|
47
|
+
value: 'webhooks',
|
|
48
|
+
},
|
|
49
|
+
],
|
|
50
|
+
default: 'pix',
|
|
51
|
+
},
|
|
52
|
+
// PIX Operations
|
|
53
|
+
{
|
|
54
|
+
displayName: 'Operation',
|
|
55
|
+
name: 'operation',
|
|
56
|
+
type: 'options',
|
|
57
|
+
noDataExpression: true,
|
|
58
|
+
displayOptions: {
|
|
59
|
+
show: {
|
|
60
|
+
resource: ['pix'],
|
|
61
|
+
},
|
|
62
|
+
},
|
|
63
|
+
options: [
|
|
64
|
+
{
|
|
65
|
+
name: 'Criar',
|
|
66
|
+
value: 'create',
|
|
67
|
+
description: 'Criar um pagamento PIX',
|
|
68
|
+
action: 'Criar pagamento PIX',
|
|
69
|
+
},
|
|
70
|
+
{
|
|
71
|
+
name: 'Consultar',
|
|
72
|
+
value: 'get',
|
|
73
|
+
description: 'Consultar um pagamento PIX',
|
|
74
|
+
action: 'Consultar pagamento PIX',
|
|
75
|
+
},
|
|
76
|
+
{
|
|
77
|
+
name: 'Reembolsar',
|
|
78
|
+
value: 'refund',
|
|
79
|
+
description: 'Reembolsar um pagamento PIX',
|
|
80
|
+
action: 'Reembolsar pagamento PIX',
|
|
81
|
+
},
|
|
82
|
+
],
|
|
83
|
+
default: 'create',
|
|
84
|
+
},
|
|
85
|
+
// PIX Create Fields
|
|
86
|
+
{
|
|
87
|
+
displayName: 'Valor',
|
|
88
|
+
name: 'amount',
|
|
89
|
+
type: 'number',
|
|
90
|
+
required: true,
|
|
91
|
+
displayOptions: {
|
|
92
|
+
show: {
|
|
93
|
+
resource: ['pix'],
|
|
94
|
+
operation: ['create'],
|
|
95
|
+
},
|
|
96
|
+
},
|
|
97
|
+
default: 0,
|
|
98
|
+
description: 'Valor do pagamento em reais (ex: 10.50)',
|
|
99
|
+
},
|
|
100
|
+
{
|
|
101
|
+
displayName: 'Descrição',
|
|
102
|
+
name: 'description',
|
|
103
|
+
type: 'string',
|
|
104
|
+
required: true,
|
|
105
|
+
displayOptions: {
|
|
106
|
+
show: {
|
|
107
|
+
resource: ['pix'],
|
|
108
|
+
operation: ['create'],
|
|
109
|
+
},
|
|
110
|
+
},
|
|
111
|
+
default: '',
|
|
112
|
+
description: 'Descrição do pagamento',
|
|
113
|
+
},
|
|
114
|
+
{
|
|
115
|
+
displayName: 'E-mail do Pagador',
|
|
116
|
+
name: 'payerEmail',
|
|
117
|
+
type: 'string',
|
|
118
|
+
required: true,
|
|
119
|
+
displayOptions: {
|
|
120
|
+
show: {
|
|
121
|
+
resource: ['pix'],
|
|
122
|
+
operation: ['create'],
|
|
123
|
+
},
|
|
124
|
+
},
|
|
125
|
+
default: '',
|
|
126
|
+
description: 'E-mail do pagador',
|
|
127
|
+
},
|
|
128
|
+
{
|
|
129
|
+
displayName: 'CPF/CNPJ do Pagador',
|
|
130
|
+
name: 'payerDocument',
|
|
131
|
+
type: 'string',
|
|
132
|
+
displayOptions: {
|
|
133
|
+
show: {
|
|
134
|
+
resource: ['pix'],
|
|
135
|
+
operation: ['create'],
|
|
136
|
+
},
|
|
137
|
+
},
|
|
138
|
+
default: '',
|
|
139
|
+
description: 'CPF ou CNPJ do pagador (apenas números)',
|
|
140
|
+
},
|
|
141
|
+
{
|
|
142
|
+
displayName: 'Nome do Pagador',
|
|
143
|
+
name: 'payerName',
|
|
144
|
+
type: 'string',
|
|
145
|
+
displayOptions: {
|
|
146
|
+
show: {
|
|
147
|
+
resource: ['pix'],
|
|
148
|
+
operation: ['create'],
|
|
149
|
+
},
|
|
150
|
+
},
|
|
151
|
+
default: '',
|
|
152
|
+
description: 'Nome completo do pagador',
|
|
153
|
+
},
|
|
154
|
+
{
|
|
155
|
+
displayName: 'Data de Expiração',
|
|
156
|
+
name: 'expirationDate',
|
|
157
|
+
type: 'dateTime',
|
|
158
|
+
displayOptions: {
|
|
159
|
+
show: {
|
|
160
|
+
resource: ['pix'],
|
|
161
|
+
operation: ['create'],
|
|
162
|
+
},
|
|
163
|
+
},
|
|
164
|
+
default: '',
|
|
165
|
+
description: 'Data e hora de expiração do QR Code PIX',
|
|
166
|
+
},
|
|
167
|
+
{
|
|
168
|
+
displayName: 'Referência Externa',
|
|
169
|
+
name: 'externalReference',
|
|
170
|
+
type: 'string',
|
|
171
|
+
displayOptions: {
|
|
172
|
+
show: {
|
|
173
|
+
resource: ['pix'],
|
|
174
|
+
operation: ['create'],
|
|
175
|
+
},
|
|
176
|
+
},
|
|
177
|
+
default: '',
|
|
178
|
+
description: 'Referência externa para identificar o pagamento',
|
|
179
|
+
},
|
|
180
|
+
{
|
|
181
|
+
displayName: 'Chave de Idempotência',
|
|
182
|
+
name: 'idempotencyKey',
|
|
183
|
+
type: 'string',
|
|
184
|
+
displayOptions: {
|
|
185
|
+
show: {
|
|
186
|
+
resource: ['pix'],
|
|
187
|
+
operation: ['create'],
|
|
188
|
+
},
|
|
189
|
+
},
|
|
190
|
+
default: '',
|
|
191
|
+
description: 'Chave única para garantir idempotência da requisição',
|
|
192
|
+
},
|
|
193
|
+
// PIX Get Fields
|
|
194
|
+
{
|
|
195
|
+
displayName: 'ID do Pagamento',
|
|
196
|
+
name: 'paymentId',
|
|
197
|
+
type: 'string',
|
|
198
|
+
required: true,
|
|
199
|
+
displayOptions: {
|
|
200
|
+
show: {
|
|
201
|
+
resource: ['pix'],
|
|
202
|
+
operation: ['get'],
|
|
203
|
+
},
|
|
204
|
+
},
|
|
205
|
+
default: '',
|
|
206
|
+
description: 'ID do pagamento a ser consultado',
|
|
207
|
+
},
|
|
208
|
+
// PIX Refund Fields
|
|
209
|
+
{
|
|
210
|
+
displayName: 'ID do Pagamento',
|
|
211
|
+
name: 'paymentId',
|
|
212
|
+
type: 'string',
|
|
213
|
+
required: true,
|
|
214
|
+
displayOptions: {
|
|
215
|
+
show: {
|
|
216
|
+
resource: ['pix'],
|
|
217
|
+
operation: ['refund'],
|
|
218
|
+
},
|
|
219
|
+
},
|
|
220
|
+
default: '',
|
|
221
|
+
description: 'ID do pagamento a ser reembolsado',
|
|
222
|
+
},
|
|
223
|
+
{
|
|
224
|
+
displayName: 'Valor do Reembolso',
|
|
225
|
+
name: 'refundAmount',
|
|
226
|
+
type: 'number',
|
|
227
|
+
displayOptions: {
|
|
228
|
+
show: {
|
|
229
|
+
resource: ['pix'],
|
|
230
|
+
operation: ['refund'],
|
|
231
|
+
},
|
|
232
|
+
},
|
|
233
|
+
default: 0,
|
|
234
|
+
description: 'Valor do reembolso em reais (deixe vazio para reembolso total)',
|
|
235
|
+
},
|
|
236
|
+
// Subscription Operations
|
|
237
|
+
{
|
|
238
|
+
displayName: 'Operation',
|
|
239
|
+
name: 'operation',
|
|
240
|
+
type: 'options',
|
|
241
|
+
noDataExpression: true,
|
|
242
|
+
displayOptions: {
|
|
243
|
+
show: {
|
|
244
|
+
resource: ['subscriptions'],
|
|
245
|
+
},
|
|
246
|
+
},
|
|
247
|
+
options: [
|
|
248
|
+
{
|
|
249
|
+
name: 'Criar',
|
|
250
|
+
value: 'create',
|
|
251
|
+
description: 'Criar uma assinatura',
|
|
252
|
+
action: 'Criar assinatura',
|
|
253
|
+
},
|
|
254
|
+
{
|
|
255
|
+
name: 'Pausar',
|
|
256
|
+
value: 'pause',
|
|
257
|
+
description: 'Pausar uma assinatura',
|
|
258
|
+
action: 'Pausar assinatura',
|
|
259
|
+
},
|
|
260
|
+
{
|
|
261
|
+
name: 'Retomar',
|
|
262
|
+
value: 'resume',
|
|
263
|
+
description: 'Retomar uma assinatura pausada',
|
|
264
|
+
action: 'Retomar assinatura',
|
|
265
|
+
},
|
|
266
|
+
{
|
|
267
|
+
name: 'Cancelar',
|
|
268
|
+
value: 'cancel',
|
|
269
|
+
description: 'Cancelar uma assinatura',
|
|
270
|
+
action: 'Cancelar assinatura',
|
|
271
|
+
},
|
|
272
|
+
{
|
|
273
|
+
name: 'Consultar',
|
|
274
|
+
value: 'get',
|
|
275
|
+
description: 'Consultar uma assinatura',
|
|
276
|
+
action: 'Consultar assinatura',
|
|
277
|
+
},
|
|
278
|
+
{
|
|
279
|
+
name: 'Listar',
|
|
280
|
+
value: 'list',
|
|
281
|
+
description: 'Listar assinaturas',
|
|
282
|
+
action: 'Listar assinaturas',
|
|
283
|
+
},
|
|
284
|
+
],
|
|
285
|
+
default: 'create',
|
|
286
|
+
},
|
|
287
|
+
// Subscription Create Fields
|
|
288
|
+
{
|
|
289
|
+
displayName: 'ID do Plano',
|
|
290
|
+
name: 'planId',
|
|
291
|
+
type: 'string',
|
|
292
|
+
required: true,
|
|
293
|
+
displayOptions: {
|
|
294
|
+
show: {
|
|
295
|
+
resource: ['subscriptions'],
|
|
296
|
+
operation: ['create'],
|
|
297
|
+
},
|
|
298
|
+
},
|
|
299
|
+
default: '',
|
|
300
|
+
description: 'ID do plano de assinatura',
|
|
301
|
+
},
|
|
302
|
+
{
|
|
303
|
+
displayName: 'E-mail do Pagador',
|
|
304
|
+
name: 'payerEmail',
|
|
305
|
+
type: 'string',
|
|
306
|
+
required: true,
|
|
307
|
+
displayOptions: {
|
|
308
|
+
show: {
|
|
309
|
+
resource: ['subscriptions'],
|
|
310
|
+
operation: ['create'],
|
|
311
|
+
},
|
|
312
|
+
},
|
|
313
|
+
default: '',
|
|
314
|
+
description: 'E-mail do pagador',
|
|
315
|
+
},
|
|
316
|
+
{
|
|
317
|
+
displayName: 'CPF/CNPJ do Pagador',
|
|
318
|
+
name: 'payerDocument',
|
|
319
|
+
type: 'string',
|
|
320
|
+
displayOptions: {
|
|
321
|
+
show: {
|
|
322
|
+
resource: ['subscriptions'],
|
|
323
|
+
operation: ['create'],
|
|
324
|
+
},
|
|
325
|
+
},
|
|
326
|
+
default: '',
|
|
327
|
+
description: 'CPF ou CNPJ do pagador',
|
|
328
|
+
},
|
|
329
|
+
{
|
|
330
|
+
displayName: 'Data de Início',
|
|
331
|
+
name: 'startDate',
|
|
332
|
+
type: 'dateTime',
|
|
333
|
+
displayOptions: {
|
|
334
|
+
show: {
|
|
335
|
+
resource: ['subscriptions'],
|
|
336
|
+
operation: ['create'],
|
|
337
|
+
},
|
|
338
|
+
},
|
|
339
|
+
default: '',
|
|
340
|
+
description: 'Data de início da assinatura',
|
|
341
|
+
},
|
|
342
|
+
{
|
|
343
|
+
displayName: 'Período de Trial (dias)',
|
|
344
|
+
name: 'trialPeriodDays',
|
|
345
|
+
type: 'number',
|
|
346
|
+
displayOptions: {
|
|
347
|
+
show: {
|
|
348
|
+
resource: ['subscriptions'],
|
|
349
|
+
operation: ['create'],
|
|
350
|
+
},
|
|
351
|
+
},
|
|
352
|
+
default: 0,
|
|
353
|
+
description: 'Número de dias de período de trial',
|
|
354
|
+
},
|
|
355
|
+
// Subscription Get/Cancel/Pause/Resume Fields
|
|
356
|
+
{
|
|
357
|
+
displayName: 'ID da Assinatura',
|
|
358
|
+
name: 'subscriptionId',
|
|
359
|
+
type: 'string',
|
|
360
|
+
required: true,
|
|
361
|
+
displayOptions: {
|
|
362
|
+
show: {
|
|
363
|
+
resource: ['subscriptions'],
|
|
364
|
+
operation: ['get', 'cancel', 'pause', 'resume'],
|
|
365
|
+
},
|
|
366
|
+
},
|
|
367
|
+
default: '',
|
|
368
|
+
description: 'ID da assinatura',
|
|
369
|
+
},
|
|
370
|
+
// Recurring Payment Operations
|
|
371
|
+
{
|
|
372
|
+
displayName: 'Operation',
|
|
373
|
+
name: 'operation',
|
|
374
|
+
type: 'options',
|
|
375
|
+
noDataExpression: true,
|
|
376
|
+
displayOptions: {
|
|
377
|
+
show: {
|
|
378
|
+
resource: ['recurringPayments'],
|
|
379
|
+
},
|
|
380
|
+
},
|
|
381
|
+
options: [
|
|
382
|
+
{
|
|
383
|
+
name: 'Criar',
|
|
384
|
+
value: 'create',
|
|
385
|
+
description: 'Criar um pagamento recorrente',
|
|
386
|
+
action: 'Criar pagamento recorrente',
|
|
387
|
+
},
|
|
388
|
+
{
|
|
389
|
+
name: 'Listar',
|
|
390
|
+
value: 'list',
|
|
391
|
+
description: 'Listar pagamentos recorrentes',
|
|
392
|
+
action: 'Listar pagamentos recorrentes',
|
|
393
|
+
},
|
|
394
|
+
{
|
|
395
|
+
name: 'Cancelar',
|
|
396
|
+
value: 'cancel',
|
|
397
|
+
description: 'Cancelar um pagamento recorrente',
|
|
398
|
+
action: 'Cancelar pagamento recorrente',
|
|
399
|
+
},
|
|
400
|
+
{
|
|
401
|
+
name: 'Consultar',
|
|
402
|
+
value: 'get',
|
|
403
|
+
description: 'Consultar um pagamento recorrente',
|
|
404
|
+
action: 'Consultar pagamento recorrente',
|
|
405
|
+
},
|
|
406
|
+
],
|
|
407
|
+
default: 'create',
|
|
408
|
+
},
|
|
409
|
+
// Recurring Payment Fields
|
|
410
|
+
{
|
|
411
|
+
displayName: 'ID do Plano',
|
|
412
|
+
name: 'planId',
|
|
413
|
+
type: 'string',
|
|
414
|
+
required: true,
|
|
415
|
+
displayOptions: {
|
|
416
|
+
show: {
|
|
417
|
+
resource: ['recurringPayments'],
|
|
418
|
+
operation: ['create'],
|
|
419
|
+
},
|
|
420
|
+
},
|
|
421
|
+
default: '',
|
|
422
|
+
description: 'ID do plano de pagamento recorrente',
|
|
423
|
+
},
|
|
424
|
+
{
|
|
425
|
+
displayName: 'ID do Cliente',
|
|
426
|
+
name: 'customerId',
|
|
427
|
+
type: 'string',
|
|
428
|
+
displayOptions: {
|
|
429
|
+
show: {
|
|
430
|
+
resource: ['recurringPayments'],
|
|
431
|
+
operation: ['create', 'list', 'get'],
|
|
432
|
+
},
|
|
433
|
+
},
|
|
434
|
+
default: '',
|
|
435
|
+
description: 'ID do cliente (filtro opcional)',
|
|
436
|
+
},
|
|
437
|
+
{
|
|
438
|
+
displayName: 'ID do Pagamento Recorrente',
|
|
439
|
+
name: 'recurringPaymentId',
|
|
440
|
+
type: 'string',
|
|
441
|
+
required: true,
|
|
442
|
+
displayOptions: {
|
|
443
|
+
show: {
|
|
444
|
+
resource: ['recurringPayments'],
|
|
445
|
+
operation: ['get', 'cancel'],
|
|
446
|
+
},
|
|
447
|
+
},
|
|
448
|
+
default: '',
|
|
449
|
+
description: 'ID do pagamento recorrente',
|
|
450
|
+
},
|
|
451
|
+
// Webhook Operations
|
|
452
|
+
{
|
|
453
|
+
displayName: 'Operation',
|
|
454
|
+
name: 'operation',
|
|
455
|
+
type: 'options',
|
|
456
|
+
noDataExpression: true,
|
|
457
|
+
displayOptions: {
|
|
458
|
+
show: {
|
|
459
|
+
resource: ['webhooks'],
|
|
460
|
+
},
|
|
461
|
+
},
|
|
462
|
+
options: [
|
|
463
|
+
{
|
|
464
|
+
name: 'Registrar',
|
|
465
|
+
value: 'register',
|
|
466
|
+
description: 'Registrar um novo webhook',
|
|
467
|
+
action: 'Registrar webhook',
|
|
468
|
+
},
|
|
469
|
+
{
|
|
470
|
+
name: 'Listar',
|
|
471
|
+
value: 'list',
|
|
472
|
+
description: 'Listar webhooks',
|
|
473
|
+
action: 'Listar webhooks',
|
|
474
|
+
},
|
|
475
|
+
{
|
|
476
|
+
name: 'Excluir',
|
|
477
|
+
value: 'delete',
|
|
478
|
+
description: 'Excluir um webhook',
|
|
479
|
+
action: 'Excluir webhook',
|
|
480
|
+
},
|
|
481
|
+
{
|
|
482
|
+
name: 'Consultar',
|
|
483
|
+
value: 'get',
|
|
484
|
+
description: 'Consultar um webhook',
|
|
485
|
+
action: 'Consultar webhook',
|
|
486
|
+
},
|
|
487
|
+
],
|
|
488
|
+
default: 'register',
|
|
489
|
+
},
|
|
490
|
+
// Webhook Fields
|
|
491
|
+
{
|
|
492
|
+
displayName: 'URL',
|
|
493
|
+
name: 'url',
|
|
494
|
+
type: 'string',
|
|
495
|
+
required: true,
|
|
496
|
+
displayOptions: {
|
|
497
|
+
show: {
|
|
498
|
+
resource: ['webhooks'],
|
|
499
|
+
operation: ['register'],
|
|
500
|
+
},
|
|
501
|
+
},
|
|
502
|
+
default: '',
|
|
503
|
+
description: 'URL que receberá as notificações do webhook',
|
|
504
|
+
},
|
|
505
|
+
{
|
|
506
|
+
displayName: 'Eventos',
|
|
507
|
+
name: 'events',
|
|
508
|
+
type: 'multiOptions',
|
|
509
|
+
displayOptions: {
|
|
510
|
+
show: {
|
|
511
|
+
resource: ['webhooks'],
|
|
512
|
+
operation: ['register'],
|
|
513
|
+
},
|
|
514
|
+
},
|
|
515
|
+
options: [
|
|
516
|
+
{
|
|
517
|
+
name: 'payment.created',
|
|
518
|
+
value: 'payment',
|
|
519
|
+
},
|
|
520
|
+
{
|
|
521
|
+
name: 'payment.updated',
|
|
522
|
+
value: 'payment',
|
|
523
|
+
},
|
|
524
|
+
{
|
|
525
|
+
name: 'subscription.created',
|
|
526
|
+
value: 'subscription',
|
|
527
|
+
},
|
|
528
|
+
{
|
|
529
|
+
name: 'subscription.updated',
|
|
530
|
+
value: 'subscription',
|
|
531
|
+
},
|
|
532
|
+
],
|
|
533
|
+
default: ['payment'],
|
|
534
|
+
description: 'Eventos para os quais o webhook será notificado',
|
|
535
|
+
},
|
|
536
|
+
{
|
|
537
|
+
displayName: 'Descrição',
|
|
538
|
+
name: 'description',
|
|
539
|
+
type: 'string',
|
|
540
|
+
displayOptions: {
|
|
541
|
+
show: {
|
|
542
|
+
resource: ['webhooks'],
|
|
543
|
+
operation: ['register'],
|
|
544
|
+
},
|
|
545
|
+
},
|
|
546
|
+
default: '',
|
|
547
|
+
description: 'Descrição do webhook',
|
|
548
|
+
},
|
|
549
|
+
{
|
|
550
|
+
displayName: 'ID do Webhook',
|
|
551
|
+
name: 'webhookId',
|
|
552
|
+
type: 'string',
|
|
553
|
+
required: true,
|
|
554
|
+
displayOptions: {
|
|
555
|
+
show: {
|
|
556
|
+
resource: ['webhooks'],
|
|
557
|
+
operation: ['get', 'delete'],
|
|
558
|
+
},
|
|
559
|
+
},
|
|
560
|
+
default: '',
|
|
561
|
+
description: 'ID do webhook',
|
|
562
|
+
},
|
|
563
|
+
],
|
|
564
|
+
};
|
|
565
|
+
}
|
|
566
|
+
async execute() {
|
|
567
|
+
const items = this.getInputData();
|
|
568
|
+
const returnData = [];
|
|
569
|
+
const credentials = (await this.getCredentials('pixPaymentApi'));
|
|
570
|
+
const baseUrl = (0, helpers_1.getBaseUrl)(credentials.environment);
|
|
571
|
+
for (let i = 0; i < items.length; i++) {
|
|
572
|
+
try {
|
|
573
|
+
const resource = this.getNodeParameter('resource', i);
|
|
574
|
+
const operation = this.getNodeParameter('operation', i);
|
|
575
|
+
let responseData;
|
|
576
|
+
switch (resource) {
|
|
577
|
+
case 'pix':
|
|
578
|
+
responseData = await PixPayment.handlePixOperation(this, operation, i, baseUrl, credentials);
|
|
579
|
+
break;
|
|
580
|
+
case 'subscriptions':
|
|
581
|
+
responseData = await PixPayment.handleSubscriptionOperation(this, operation, i, baseUrl, credentials);
|
|
582
|
+
break;
|
|
583
|
+
case 'recurringPayments':
|
|
584
|
+
responseData = await PixPayment.handleRecurringPaymentOperation(this, operation, i, baseUrl, credentials);
|
|
585
|
+
break;
|
|
586
|
+
case 'webhooks':
|
|
587
|
+
responseData = await PixPayment.handleWebhookOperation(this, operation, i, baseUrl, credentials);
|
|
588
|
+
break;
|
|
589
|
+
default:
|
|
590
|
+
throw new Error(`Resource "${resource}" não é suportado`);
|
|
591
|
+
}
|
|
592
|
+
returnData.push({
|
|
593
|
+
json: PixPayment.normalizeResponse(responseData, resource),
|
|
594
|
+
});
|
|
595
|
+
}
|
|
596
|
+
catch (error) {
|
|
597
|
+
const errorData = (0, helpers_1.handleMercadoPagoError)(error);
|
|
598
|
+
if (this.continueOnFail()) {
|
|
599
|
+
returnData.push({
|
|
600
|
+
json: {
|
|
601
|
+
error: errorData.message,
|
|
602
|
+
status: errorData.status,
|
|
603
|
+
details: errorData,
|
|
604
|
+
},
|
|
605
|
+
});
|
|
606
|
+
}
|
|
607
|
+
else {
|
|
608
|
+
throw new Error(errorData.message);
|
|
609
|
+
}
|
|
610
|
+
}
|
|
611
|
+
}
|
|
612
|
+
return [returnData];
|
|
613
|
+
}
|
|
614
|
+
static async handlePixOperation(executeFunctions, operation, itemIndex, baseUrl, credentials) {
|
|
615
|
+
switch (operation) {
|
|
616
|
+
case 'create':
|
|
617
|
+
return await PixPayment.createPixPayment(executeFunctions, itemIndex, baseUrl, credentials);
|
|
618
|
+
case 'get':
|
|
619
|
+
return await PixPayment.getPixPayment(executeFunctions, itemIndex, baseUrl, credentials);
|
|
620
|
+
case 'refund':
|
|
621
|
+
return await PixPayment.refundPixPayment(executeFunctions, itemIndex, baseUrl, credentials);
|
|
622
|
+
default:
|
|
623
|
+
throw new Error(`Operação PIX "${operation}" não é suportada`);
|
|
624
|
+
}
|
|
625
|
+
}
|
|
626
|
+
static async createPixPayment(executeFunctions, itemIndex, baseUrl, credentials) {
|
|
627
|
+
const amount = executeFunctions.getNodeParameter('amount', itemIndex);
|
|
628
|
+
const description = executeFunctions.getNodeParameter('description', itemIndex);
|
|
629
|
+
const payerEmail = executeFunctions.getNodeParameter('payerEmail', itemIndex);
|
|
630
|
+
const payerDocument = executeFunctions.getNodeParameter('payerDocument', itemIndex);
|
|
631
|
+
const payerName = executeFunctions.getNodeParameter('payerName', itemIndex);
|
|
632
|
+
const expirationDate = executeFunctions.getNodeParameter('expirationDate', itemIndex);
|
|
633
|
+
const externalReference = executeFunctions.getNodeParameter('externalReference', itemIndex);
|
|
634
|
+
const idempotencyKey = executeFunctions.getNodeParameter('idempotencyKey', itemIndex);
|
|
635
|
+
// Validações
|
|
636
|
+
if (!(0, helpers_1.validateEmail)(payerEmail)) {
|
|
637
|
+
throw new Error('E-mail do pagador inválido');
|
|
638
|
+
}
|
|
639
|
+
if (amount <= 0) {
|
|
640
|
+
throw new Error('Valor do pagamento deve ser maior que zero');
|
|
641
|
+
}
|
|
642
|
+
const body = {
|
|
643
|
+
transaction_amount: (0, helpers_1.normalizeAmount)(amount),
|
|
644
|
+
description,
|
|
645
|
+
payment_method_id: 'pix',
|
|
646
|
+
payer: {
|
|
647
|
+
email: payerEmail,
|
|
648
|
+
},
|
|
649
|
+
};
|
|
650
|
+
if (payerDocument) {
|
|
651
|
+
const docType = (0, helpers_1.getDocumentType)(payerDocument);
|
|
652
|
+
if (!docType) {
|
|
653
|
+
throw new Error('CPF/CNPJ inválido. Deve conter 11 ou 14 dígitos numéricos');
|
|
654
|
+
}
|
|
655
|
+
body.payer.identification = {
|
|
656
|
+
type: docType,
|
|
657
|
+
number: (0, helpers_1.cleanDocument)(payerDocument),
|
|
658
|
+
};
|
|
659
|
+
}
|
|
660
|
+
if (payerName) {
|
|
661
|
+
const nameParts = payerName.trim().split(' ');
|
|
662
|
+
body.payer.first_name = nameParts[0] || '';
|
|
663
|
+
body.payer.last_name = nameParts.slice(1).join(' ') || '';
|
|
664
|
+
}
|
|
665
|
+
if (expirationDate) {
|
|
666
|
+
body.date_of_expiration = new Date(expirationDate).toISOString();
|
|
667
|
+
}
|
|
668
|
+
if (externalReference) {
|
|
669
|
+
body.external_reference = externalReference;
|
|
670
|
+
}
|
|
671
|
+
const headers = {
|
|
672
|
+
Authorization: `Bearer ${credentials.accessToken}`,
|
|
673
|
+
'Content-Type': 'application/json',
|
|
674
|
+
};
|
|
675
|
+
if (idempotencyKey) {
|
|
676
|
+
headers['X-Idempotency-Key'] = idempotencyKey;
|
|
677
|
+
}
|
|
678
|
+
const response = await executeFunctions.helpers.requestWithAuthentication.call(executeFunctions, 'pixPaymentApi', {
|
|
679
|
+
method: 'POST',
|
|
680
|
+
url: `${baseUrl}/v1/payments`,
|
|
681
|
+
body,
|
|
682
|
+
headers,
|
|
683
|
+
json: true,
|
|
684
|
+
});
|
|
685
|
+
return response;
|
|
686
|
+
}
|
|
687
|
+
static async getPixPayment(executeFunctions, itemIndex, baseUrl, credentials) {
|
|
688
|
+
const paymentId = executeFunctions.getNodeParameter('paymentId', itemIndex);
|
|
689
|
+
if (!paymentId) {
|
|
690
|
+
throw new Error('ID do pagamento é obrigatório');
|
|
691
|
+
}
|
|
692
|
+
const response = await executeFunctions.helpers.requestWithAuthentication.call(executeFunctions, 'pixPaymentApi', {
|
|
693
|
+
method: 'GET',
|
|
694
|
+
url: `${baseUrl}/v1/payments/${paymentId}`,
|
|
695
|
+
headers: {
|
|
696
|
+
Authorization: `Bearer ${credentials.accessToken}`,
|
|
697
|
+
},
|
|
698
|
+
json: true,
|
|
699
|
+
});
|
|
700
|
+
return response;
|
|
701
|
+
}
|
|
702
|
+
static async refundPixPayment(executeFunctions, itemIndex, baseUrl, credentials) {
|
|
703
|
+
const paymentId = executeFunctions.getNodeParameter('paymentId', itemIndex);
|
|
704
|
+
const refundAmount = executeFunctions.getNodeParameter('refundAmount', itemIndex);
|
|
705
|
+
if (!paymentId) {
|
|
706
|
+
throw new Error('ID do pagamento é obrigatório');
|
|
707
|
+
}
|
|
708
|
+
const body = {};
|
|
709
|
+
if (refundAmount && refundAmount > 0) {
|
|
710
|
+
body.amount = (0, helpers_1.normalizeAmount)(refundAmount);
|
|
711
|
+
}
|
|
712
|
+
const response = await executeFunctions.helpers.requestWithAuthentication.call(executeFunctions, 'pixPaymentApi', {
|
|
713
|
+
method: 'POST',
|
|
714
|
+
url: `${baseUrl}/v1/payments/${paymentId}/refunds`,
|
|
715
|
+
body: Object.keys(body).length > 0 ? body : undefined,
|
|
716
|
+
headers: {
|
|
717
|
+
Authorization: `Bearer ${credentials.accessToken}`,
|
|
718
|
+
'Content-Type': 'application/json',
|
|
719
|
+
},
|
|
720
|
+
json: true,
|
|
721
|
+
});
|
|
722
|
+
return response;
|
|
723
|
+
}
|
|
724
|
+
static async handleSubscriptionOperation(executeFunctions, operation, itemIndex, baseUrl, credentials) {
|
|
725
|
+
switch (operation) {
|
|
726
|
+
case 'create':
|
|
727
|
+
return await PixPayment.createSubscription(executeFunctions, itemIndex, baseUrl, credentials);
|
|
728
|
+
case 'get':
|
|
729
|
+
return await PixPayment.getSubscription(executeFunctions, itemIndex, baseUrl, credentials);
|
|
730
|
+
case 'pause':
|
|
731
|
+
return await PixPayment.pauseSubscription(executeFunctions, itemIndex, baseUrl, credentials);
|
|
732
|
+
case 'resume':
|
|
733
|
+
return await PixPayment.resumeSubscription(executeFunctions, itemIndex, baseUrl, credentials);
|
|
734
|
+
case 'cancel':
|
|
735
|
+
return await PixPayment.cancelSubscription(executeFunctions, itemIndex, baseUrl, credentials);
|
|
736
|
+
case 'list':
|
|
737
|
+
return await PixPayment.listSubscriptions(executeFunctions, itemIndex, baseUrl, credentials);
|
|
738
|
+
default:
|
|
739
|
+
throw new Error(`Operação de assinatura "${operation}" não é suportada`);
|
|
740
|
+
}
|
|
741
|
+
}
|
|
742
|
+
static async createSubscription(executeFunctions, itemIndex, baseUrl, credentials) {
|
|
743
|
+
const planId = executeFunctions.getNodeParameter('planId', itemIndex);
|
|
744
|
+
const payerEmail = executeFunctions.getNodeParameter('payerEmail', itemIndex);
|
|
745
|
+
const payerDocument = executeFunctions.getNodeParameter('payerDocument', itemIndex);
|
|
746
|
+
const startDate = executeFunctions.getNodeParameter('startDate', itemIndex);
|
|
747
|
+
const trialPeriodDays = executeFunctions.getNodeParameter('trialPeriodDays', itemIndex);
|
|
748
|
+
if (!(0, helpers_1.validateEmail)(payerEmail)) {
|
|
749
|
+
throw new Error('E-mail do pagador inválido');
|
|
750
|
+
}
|
|
751
|
+
const body = {
|
|
752
|
+
preapproval_plan_id: planId,
|
|
753
|
+
payer_email: payerEmail,
|
|
754
|
+
};
|
|
755
|
+
if (payerDocument) {
|
|
756
|
+
const docType = (0, helpers_1.getDocumentType)(payerDocument);
|
|
757
|
+
if (!docType) {
|
|
758
|
+
throw new Error('CPF/CNPJ inválido');
|
|
759
|
+
}
|
|
760
|
+
body.payer = {
|
|
761
|
+
identification: {
|
|
762
|
+
type: docType,
|
|
763
|
+
number: (0, helpers_1.cleanDocument)(payerDocument),
|
|
764
|
+
},
|
|
765
|
+
};
|
|
766
|
+
}
|
|
767
|
+
if (startDate) {
|
|
768
|
+
body.start_date = new Date(startDate).toISOString();
|
|
769
|
+
}
|
|
770
|
+
if (trialPeriodDays && trialPeriodDays > 0) {
|
|
771
|
+
body.trial_period_days = trialPeriodDays;
|
|
772
|
+
}
|
|
773
|
+
const response = await executeFunctions.helpers.requestWithAuthentication.call(executeFunctions, 'pixPaymentApi', {
|
|
774
|
+
method: 'POST',
|
|
775
|
+
url: `${baseUrl}/preapproval`,
|
|
776
|
+
body,
|
|
777
|
+
headers: {
|
|
778
|
+
Authorization: `Bearer ${credentials.accessToken}`,
|
|
779
|
+
'Content-Type': 'application/json',
|
|
780
|
+
},
|
|
781
|
+
json: true,
|
|
782
|
+
});
|
|
783
|
+
return response;
|
|
784
|
+
}
|
|
785
|
+
static async getSubscription(executeFunctions, itemIndex, baseUrl, credentials) {
|
|
786
|
+
const subscriptionId = executeFunctions.getNodeParameter('subscriptionId', itemIndex);
|
|
787
|
+
const response = await executeFunctions.helpers.requestWithAuthentication.call(executeFunctions, 'pixPaymentApi', {
|
|
788
|
+
method: 'GET',
|
|
789
|
+
url: `${baseUrl}/preapproval/${subscriptionId}`,
|
|
790
|
+
headers: {
|
|
791
|
+
Authorization: `Bearer ${credentials.accessToken}`,
|
|
792
|
+
},
|
|
793
|
+
json: true,
|
|
794
|
+
});
|
|
795
|
+
return response;
|
|
796
|
+
}
|
|
797
|
+
static async pauseSubscription(executeFunctions, itemIndex, baseUrl, credentials) {
|
|
798
|
+
const subscriptionId = executeFunctions.getNodeParameter('subscriptionId', itemIndex);
|
|
799
|
+
const response = await executeFunctions.helpers.requestWithAuthentication.call(executeFunctions, 'pixPaymentApi', {
|
|
800
|
+
method: 'PUT',
|
|
801
|
+
url: `${baseUrl}/preapproval/${subscriptionId}`,
|
|
802
|
+
body: {
|
|
803
|
+
status: 'paused',
|
|
804
|
+
},
|
|
805
|
+
headers: {
|
|
806
|
+
Authorization: `Bearer ${credentials.accessToken}`,
|
|
807
|
+
'Content-Type': 'application/json',
|
|
808
|
+
},
|
|
809
|
+
json: true,
|
|
810
|
+
});
|
|
811
|
+
return response;
|
|
812
|
+
}
|
|
813
|
+
static async resumeSubscription(executeFunctions, itemIndex, baseUrl, credentials) {
|
|
814
|
+
const subscriptionId = executeFunctions.getNodeParameter('subscriptionId', itemIndex);
|
|
815
|
+
const response = await executeFunctions.helpers.requestWithAuthentication.call(executeFunctions, 'pixPaymentApi', {
|
|
816
|
+
method: 'PUT',
|
|
817
|
+
url: `${baseUrl}/preapproval/${subscriptionId}`,
|
|
818
|
+
body: {
|
|
819
|
+
status: 'authorized',
|
|
820
|
+
},
|
|
821
|
+
headers: {
|
|
822
|
+
Authorization: `Bearer ${credentials.accessToken}`,
|
|
823
|
+
'Content-Type': 'application/json',
|
|
824
|
+
},
|
|
825
|
+
json: true,
|
|
826
|
+
});
|
|
827
|
+
return response;
|
|
828
|
+
}
|
|
829
|
+
static async cancelSubscription(executeFunctions, itemIndex, baseUrl, credentials) {
|
|
830
|
+
const subscriptionId = executeFunctions.getNodeParameter('subscriptionId', itemIndex);
|
|
831
|
+
const response = await executeFunctions.helpers.requestWithAuthentication.call(executeFunctions, 'pixPaymentApi', {
|
|
832
|
+
method: 'PUT',
|
|
833
|
+
url: `${baseUrl}/preapproval/${subscriptionId}`,
|
|
834
|
+
body: {
|
|
835
|
+
status: 'cancelled',
|
|
836
|
+
},
|
|
837
|
+
headers: {
|
|
838
|
+
Authorization: `Bearer ${credentials.accessToken}`,
|
|
839
|
+
'Content-Type': 'application/json',
|
|
840
|
+
},
|
|
841
|
+
json: true,
|
|
842
|
+
});
|
|
843
|
+
return response;
|
|
844
|
+
}
|
|
845
|
+
static async listSubscriptions(executeFunctions, _itemIndex, baseUrl, credentials) {
|
|
846
|
+
const response = await executeFunctions.helpers.requestWithAuthentication.call(executeFunctions, 'pixPaymentApi', {
|
|
847
|
+
method: 'GET',
|
|
848
|
+
url: `${baseUrl}/preapproval/search`,
|
|
849
|
+
headers: {
|
|
850
|
+
Authorization: `Bearer ${credentials.accessToken}`,
|
|
851
|
+
},
|
|
852
|
+
json: true,
|
|
853
|
+
});
|
|
854
|
+
return response;
|
|
855
|
+
}
|
|
856
|
+
static async handleRecurringPaymentOperation(executeFunctions, operation, itemIndex, baseUrl, credentials) {
|
|
857
|
+
switch (operation) {
|
|
858
|
+
case 'create':
|
|
859
|
+
return await PixPayment.createRecurringPayment(executeFunctions, itemIndex, baseUrl, credentials);
|
|
860
|
+
case 'get':
|
|
861
|
+
return await PixPayment.getRecurringPayment(executeFunctions, itemIndex, baseUrl, credentials);
|
|
862
|
+
case 'list':
|
|
863
|
+
return await PixPayment.listRecurringPayments(executeFunctions, itemIndex, baseUrl, credentials);
|
|
864
|
+
case 'cancel':
|
|
865
|
+
return await PixPayment.cancelRecurringPayment(executeFunctions, itemIndex, baseUrl, credentials);
|
|
866
|
+
default:
|
|
867
|
+
throw new Error(`Operação de pagamento recorrente "${operation}" não é suportada`);
|
|
868
|
+
}
|
|
869
|
+
}
|
|
870
|
+
static async createRecurringPayment(executeFunctions, itemIndex, baseUrl, credentials) {
|
|
871
|
+
const planId = executeFunctions.getNodeParameter('planId', itemIndex);
|
|
872
|
+
// Para pagamentos recorrentes, geralmente criamos via assinatura
|
|
873
|
+
// Esta é uma implementação simplificada
|
|
874
|
+
const response = await executeFunctions.helpers.requestWithAuthentication.call(executeFunctions, 'pixPaymentApi', {
|
|
875
|
+
method: 'GET',
|
|
876
|
+
url: `${baseUrl}/preapproval/${planId}`,
|
|
877
|
+
headers: {
|
|
878
|
+
Authorization: `Bearer ${credentials.accessToken}`,
|
|
879
|
+
},
|
|
880
|
+
json: true,
|
|
881
|
+
});
|
|
882
|
+
return response;
|
|
883
|
+
}
|
|
884
|
+
static async getRecurringPayment(executeFunctions, itemIndex, baseUrl, credentials) {
|
|
885
|
+
const recurringPaymentId = executeFunctions.getNodeParameter('recurringPaymentId', itemIndex);
|
|
886
|
+
const response = await executeFunctions.helpers.requestWithAuthentication.call(executeFunctions, 'pixPaymentApi', {
|
|
887
|
+
method: 'GET',
|
|
888
|
+
url: `${baseUrl}/preapproval/${recurringPaymentId}`,
|
|
889
|
+
headers: {
|
|
890
|
+
Authorization: `Bearer ${credentials.accessToken}`,
|
|
891
|
+
},
|
|
892
|
+
json: true,
|
|
893
|
+
});
|
|
894
|
+
return response;
|
|
895
|
+
}
|
|
896
|
+
static async listRecurringPayments(executeFunctions, itemIndex, baseUrl, credentials) {
|
|
897
|
+
const customerId = executeFunctions.getNodeParameter('customerId', itemIndex);
|
|
898
|
+
let url = `${baseUrl}/preapproval/search`;
|
|
899
|
+
if (customerId) {
|
|
900
|
+
url += `?payer_id=${customerId}`;
|
|
901
|
+
}
|
|
902
|
+
const response = await executeFunctions.helpers.requestWithAuthentication.call(executeFunctions, 'pixPaymentApi', {
|
|
903
|
+
method: 'GET',
|
|
904
|
+
url,
|
|
905
|
+
headers: {
|
|
906
|
+
Authorization: `Bearer ${credentials.accessToken}`,
|
|
907
|
+
},
|
|
908
|
+
json: true,
|
|
909
|
+
});
|
|
910
|
+
return response;
|
|
911
|
+
}
|
|
912
|
+
static async cancelRecurringPayment(executeFunctions, itemIndex, baseUrl, credentials) {
|
|
913
|
+
const recurringPaymentId = executeFunctions.getNodeParameter('recurringPaymentId', itemIndex);
|
|
914
|
+
const response = await executeFunctions.helpers.requestWithAuthentication.call(executeFunctions, 'pixPaymentApi', {
|
|
915
|
+
method: 'PUT',
|
|
916
|
+
url: `${baseUrl}/preapproval/${recurringPaymentId}`,
|
|
917
|
+
body: {
|
|
918
|
+
status: 'cancelled',
|
|
919
|
+
},
|
|
920
|
+
headers: {
|
|
921
|
+
Authorization: `Bearer ${credentials.accessToken}`,
|
|
922
|
+
'Content-Type': 'application/json',
|
|
923
|
+
},
|
|
924
|
+
json: true,
|
|
925
|
+
});
|
|
926
|
+
return response;
|
|
927
|
+
}
|
|
928
|
+
static async handleWebhookOperation(executeFunctions, operation, itemIndex, baseUrl, credentials) {
|
|
929
|
+
switch (operation) {
|
|
930
|
+
case 'register':
|
|
931
|
+
return await PixPayment.registerWebhook(executeFunctions, itemIndex, baseUrl, credentials);
|
|
932
|
+
case 'get':
|
|
933
|
+
return await PixPayment.getWebhook(executeFunctions, itemIndex, baseUrl, credentials);
|
|
934
|
+
case 'list':
|
|
935
|
+
return await PixPayment.listWebhooks(executeFunctions, itemIndex, baseUrl, credentials);
|
|
936
|
+
case 'delete':
|
|
937
|
+
return await PixPayment.deleteWebhook(executeFunctions, itemIndex, baseUrl, credentials);
|
|
938
|
+
default:
|
|
939
|
+
throw new Error(`Operação de webhook "${operation}" não é suportada`);
|
|
940
|
+
}
|
|
941
|
+
}
|
|
942
|
+
static async registerWebhook(executeFunctions, itemIndex, baseUrl, credentials) {
|
|
943
|
+
const url = executeFunctions.getNodeParameter('url', itemIndex);
|
|
944
|
+
const events = executeFunctions.getNodeParameter('events', itemIndex);
|
|
945
|
+
const description = executeFunctions.getNodeParameter('description', itemIndex);
|
|
946
|
+
if (!url || !url.startsWith('http')) {
|
|
947
|
+
throw new Error('URL do webhook deve ser uma URL válida (http:// ou https://)');
|
|
948
|
+
}
|
|
949
|
+
const body = {
|
|
950
|
+
url,
|
|
951
|
+
events: events.length > 0 ? events : ['payment'],
|
|
952
|
+
};
|
|
953
|
+
if (description) {
|
|
954
|
+
body.description = description;
|
|
955
|
+
}
|
|
956
|
+
const response = await executeFunctions.helpers.requestWithAuthentication.call(executeFunctions, 'pixPaymentApi', {
|
|
957
|
+
method: 'POST',
|
|
958
|
+
url: `${baseUrl}/v1/webhooks`,
|
|
959
|
+
body,
|
|
960
|
+
headers: {
|
|
961
|
+
Authorization: `Bearer ${credentials.accessToken}`,
|
|
962
|
+
'Content-Type': 'application/json',
|
|
963
|
+
},
|
|
964
|
+
json: true,
|
|
965
|
+
});
|
|
966
|
+
return response;
|
|
967
|
+
}
|
|
968
|
+
static async getWebhook(executeFunctions, itemIndex, baseUrl, credentials) {
|
|
969
|
+
const webhookId = executeFunctions.getNodeParameter('webhookId', itemIndex);
|
|
970
|
+
const response = await executeFunctions.helpers.requestWithAuthentication.call(executeFunctions, 'pixPaymentApi', {
|
|
971
|
+
method: 'GET',
|
|
972
|
+
url: `${baseUrl}/v1/webhooks/${webhookId}`,
|
|
973
|
+
headers: {
|
|
974
|
+
Authorization: `Bearer ${credentials.accessToken}`,
|
|
975
|
+
},
|
|
976
|
+
json: true,
|
|
977
|
+
});
|
|
978
|
+
return response;
|
|
979
|
+
}
|
|
980
|
+
static async listWebhooks(executeFunctions, _itemIndex, baseUrl, credentials) {
|
|
981
|
+
const response = await executeFunctions.helpers.requestWithAuthentication.call(executeFunctions, 'pixPaymentApi', {
|
|
982
|
+
method: 'GET',
|
|
983
|
+
url: `${baseUrl}/v1/webhooks`,
|
|
984
|
+
headers: {
|
|
985
|
+
Authorization: `Bearer ${credentials.accessToken}`,
|
|
986
|
+
},
|
|
987
|
+
json: true,
|
|
988
|
+
});
|
|
989
|
+
return response;
|
|
990
|
+
}
|
|
991
|
+
static async deleteWebhook(executeFunctions, itemIndex, baseUrl, credentials) {
|
|
992
|
+
const webhookId = executeFunctions.getNodeParameter('webhookId', itemIndex);
|
|
993
|
+
const response = await executeFunctions.helpers.requestWithAuthentication.call(executeFunctions, 'pixPaymentApi', {
|
|
994
|
+
method: 'DELETE',
|
|
995
|
+
url: `${baseUrl}/v1/webhooks/${webhookId}`,
|
|
996
|
+
headers: {
|
|
997
|
+
Authorization: `Bearer ${credentials.accessToken}`,
|
|
998
|
+
},
|
|
999
|
+
json: true,
|
|
1000
|
+
});
|
|
1001
|
+
return response;
|
|
1002
|
+
}
|
|
1003
|
+
static normalizeResponse(data, resource) {
|
|
1004
|
+
const normalized = {
|
|
1005
|
+
id: data.id || '',
|
|
1006
|
+
status: data.status || '',
|
|
1007
|
+
createdAt: data.date_created || data.created_at || new Date().toISOString(),
|
|
1008
|
+
raw: data,
|
|
1009
|
+
};
|
|
1010
|
+
// Normalização específica por recurso
|
|
1011
|
+
switch (resource) {
|
|
1012
|
+
case 'pix':
|
|
1013
|
+
normalized.amount = data.transaction_amount ? data.transaction_amount / 100 : undefined;
|
|
1014
|
+
normalized.currency = data.currency_id || 'BRL';
|
|
1015
|
+
normalized.qrCode = data.point_of_interaction?.transaction_data?.qr_code;
|
|
1016
|
+
normalized.qrCodeBase64 = data.point_of_interaction?.transaction_data?.qr_code_base64;
|
|
1017
|
+
normalized.description = data.description;
|
|
1018
|
+
normalized.payerEmail = data.payer?.email;
|
|
1019
|
+
break;
|
|
1020
|
+
case 'subscriptions':
|
|
1021
|
+
normalized.planId = data.preapproval_plan_id;
|
|
1022
|
+
normalized.payerEmail = data.payer_email;
|
|
1023
|
+
normalized.startDate = data.start_date;
|
|
1024
|
+
normalized.endDate = data.end_date;
|
|
1025
|
+
normalized.statusDetail = data.status_detail;
|
|
1026
|
+
break;
|
|
1027
|
+
case 'recurringPayments':
|
|
1028
|
+
normalized.planId = data.preapproval_plan_id;
|
|
1029
|
+
normalized.payerEmail = data.payer_email;
|
|
1030
|
+
normalized.nextBillingDate = data.next_billing_date;
|
|
1031
|
+
break;
|
|
1032
|
+
case 'webhooks':
|
|
1033
|
+
normalized.url = data.url;
|
|
1034
|
+
normalized.events = data.events || [];
|
|
1035
|
+
normalized.description = data.description;
|
|
1036
|
+
break;
|
|
1037
|
+
}
|
|
1038
|
+
return normalized;
|
|
1039
|
+
}
|
|
1040
|
+
}
|
|
1041
|
+
exports.PixPayment = PixPayment;
|