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