n8n-nodes-mercadopago-pix-assinatura 1.0.1 → 1.0.2
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
CHANGED
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
Node customizado do n8n para processamento de pagamentos via Mercado Pago, com suporte completo a:
|
|
7
7
|
|
|
8
8
|
- 💰 **Pagamentos PIX** (criação, consulta, reembolso)
|
|
9
|
+
- 📋 **Planos** (criar, consultar, listar, atualizar)
|
|
9
10
|
- 🔄 **Assinaturas** (criar, pausar, retomar, cancelar, consultar, listar)
|
|
10
11
|
- 📅 **Pagamentos Recorrentes** (gerenciamento completo)
|
|
11
12
|
- 🔔 **Webhooks** (registro, listagem, exclusão, consulta)
|
|
@@ -21,22 +22,26 @@ Node customizado do n8n para processamento de pagamentos via Mercado Pago, com s
|
|
|
21
22
|
### Instalação Local (Desenvolvimento)
|
|
22
23
|
|
|
23
24
|
1. Clone o repositório:
|
|
25
|
+
|
|
24
26
|
```bash
|
|
25
27
|
git clone https://github.com/eliveutonsouza/n8n-nodes-mercadopago-pix-assinatura.git
|
|
26
28
|
cd n8n-nodes-mercadopago-pix-assinatura
|
|
27
29
|
```
|
|
28
30
|
|
|
29
31
|
2. Instale as dependências:
|
|
32
|
+
|
|
30
33
|
```bash
|
|
31
34
|
npm install
|
|
32
35
|
```
|
|
33
36
|
|
|
34
37
|
3. Compile o projeto:
|
|
38
|
+
|
|
35
39
|
```bash
|
|
36
40
|
npm run build
|
|
37
41
|
```
|
|
38
42
|
|
|
39
43
|
4. Para desenvolvimento com watch mode:
|
|
44
|
+
|
|
40
45
|
```bash
|
|
41
46
|
npm run dev
|
|
42
47
|
```
|
|
@@ -46,11 +51,13 @@ npm run dev
|
|
|
46
51
|
**Recomendado**: Instale via npm para facilitar atualizações.
|
|
47
52
|
|
|
48
53
|
1. No diretório do seu n8n self-hosted, instale o pacote:
|
|
54
|
+
|
|
49
55
|
```bash
|
|
50
56
|
npm install n8n-nodes-mercadopago-pix-assinatura
|
|
51
57
|
```
|
|
52
58
|
|
|
53
59
|
2. Reinicie o n8n:
|
|
60
|
+
|
|
54
61
|
```bash
|
|
55
62
|
# Se estiver usando Docker
|
|
56
63
|
docker restart n8n
|
|
@@ -88,11 +95,13 @@ docker restart n8n
|
|
|
88
95
|
Cria um novo pagamento PIX e retorna o QR Code para pagamento.
|
|
89
96
|
|
|
90
97
|
**Campos obrigatórios:**
|
|
98
|
+
|
|
91
99
|
- Valor (em reais, ex: 10.50)
|
|
92
100
|
- Descrição
|
|
93
101
|
- E-mail do Pagador
|
|
94
102
|
|
|
95
103
|
**Campos opcionais:**
|
|
104
|
+
|
|
96
105
|
- CPF/CNPJ do Pagador
|
|
97
106
|
- Nome do Pagador
|
|
98
107
|
- Data de Expiração
|
|
@@ -100,6 +109,7 @@ Cria um novo pagamento PIX e retorna o QR Code para pagamento.
|
|
|
100
109
|
- Chave de Idempotência
|
|
101
110
|
|
|
102
111
|
**Resposta:**
|
|
112
|
+
|
|
103
113
|
```json
|
|
104
114
|
{
|
|
105
115
|
"id": "123456789",
|
|
@@ -120,9 +130,11 @@ Cria um novo pagamento PIX e retorna o QR Code para pagamento.
|
|
|
120
130
|
Consulta o status de um pagamento PIX existente.
|
|
121
131
|
|
|
122
132
|
**Campos obrigatórios:**
|
|
133
|
+
|
|
123
134
|
- ID do Pagamento
|
|
124
135
|
|
|
125
136
|
**Resposta:**
|
|
137
|
+
|
|
126
138
|
```json
|
|
127
139
|
{
|
|
128
140
|
"id": "123456789",
|
|
@@ -139,9 +151,11 @@ Consulta o status de um pagamento PIX existente.
|
|
|
139
151
|
Reembolsa total ou parcialmente um pagamento PIX.
|
|
140
152
|
|
|
141
153
|
**Campos obrigatórios:**
|
|
154
|
+
|
|
142
155
|
- ID do Pagamento
|
|
143
156
|
|
|
144
157
|
**Campos opcionais:**
|
|
158
|
+
|
|
145
159
|
- Valor do Reembolso (deixe vazio para reembolso total)
|
|
146
160
|
|
|
147
161
|
### Assinaturas - Criar
|
|
@@ -149,10 +163,12 @@ Reembolsa total ou parcialmente um pagamento PIX.
|
|
|
149
163
|
Cria uma nova assinatura baseada em um plano existente.
|
|
150
164
|
|
|
151
165
|
**Campos obrigatórios:**
|
|
166
|
+
|
|
152
167
|
- ID do Plano
|
|
153
168
|
- E-mail do Pagador
|
|
154
169
|
|
|
155
170
|
**Campos opcionais:**
|
|
171
|
+
|
|
156
172
|
- CPF/CNPJ do Pagador
|
|
157
173
|
- Data de Início
|
|
158
174
|
- Período de Trial (dias)
|
|
@@ -162,6 +178,7 @@ Cria uma nova assinatura baseada em um plano existente.
|
|
|
162
178
|
Gerencia o status de uma assinatura existente.
|
|
163
179
|
|
|
164
180
|
**Campos obrigatórios:**
|
|
181
|
+
|
|
165
182
|
- ID da Assinatura
|
|
166
183
|
|
|
167
184
|
### Assinaturas - Consultar/Listar
|
|
@@ -173,6 +190,7 @@ Consulta uma assinatura específica ou lista todas as assinaturas.
|
|
|
173
190
|
Gerencia pagamentos recorrentes com histórico e próxima cobrança.
|
|
174
191
|
|
|
175
192
|
**Operações disponíveis:**
|
|
193
|
+
|
|
176
194
|
- Criar
|
|
177
195
|
- Listar
|
|
178
196
|
- Cancelar
|
|
@@ -183,13 +201,16 @@ Gerencia pagamentos recorrentes com histórico e próxima cobrança.
|
|
|
183
201
|
Registra um novo webhook para receber notificações de eventos.
|
|
184
202
|
|
|
185
203
|
**Campos obrigatórios:**
|
|
204
|
+
|
|
186
205
|
- URL (deve ser acessível publicamente)
|
|
187
206
|
|
|
188
207
|
**Campos opcionais:**
|
|
208
|
+
|
|
189
209
|
- Eventos (payment, subscription)
|
|
190
210
|
- Descrição
|
|
191
211
|
|
|
192
212
|
**Eventos disponíveis:**
|
|
213
|
+
|
|
193
214
|
- `payment` - Notificações de pagamentos
|
|
194
215
|
- `subscription` - Notificações de assinaturas
|
|
195
216
|
|
|
@@ -211,6 +232,7 @@ Para testar localmente:
|
|
|
211
232
|
|
|
212
233
|
1. Configure credenciais sandbox do Mercado Pago
|
|
213
234
|
2. Execute o n8n em modo desenvolvimento:
|
|
235
|
+
|
|
214
236
|
```bash
|
|
215
237
|
npm run dev
|
|
216
238
|
```
|
|
@@ -226,10 +248,12 @@ Todas as respostas seguem um formato padronizado:
|
|
|
226
248
|
{
|
|
227
249
|
"id": "string",
|
|
228
250
|
"status": "string",
|
|
229
|
-
"amount": 0.
|
|
251
|
+
"amount": 0.0,
|
|
230
252
|
"currency": "BRL",
|
|
231
253
|
"createdAt": "ISO8601",
|
|
232
|
-
"raw": {
|
|
254
|
+
"raw": {
|
|
255
|
+
/* Dados completos da API */
|
|
256
|
+
}
|
|
233
257
|
}
|
|
234
258
|
```
|
|
235
259
|
|
|
@@ -238,22 +262,27 @@ O campo `raw` contém a resposta completa da API do Mercado Pago para acesso a t
|
|
|
238
262
|
## 🐛 Troubleshooting
|
|
239
263
|
|
|
240
264
|
### Erro: "Credenciais não encontradas"
|
|
265
|
+
|
|
241
266
|
- Verifique se as credenciais foram configuradas corretamente no n8n
|
|
242
267
|
- Certifique-se de que o Access Token está válido
|
|
243
268
|
|
|
244
269
|
### Erro: "E-mail do pagador inválido"
|
|
270
|
+
|
|
245
271
|
- Verifique o formato do e-mail (deve conter @ e domínio válido)
|
|
246
272
|
|
|
247
273
|
### Erro: "CPF/CNPJ inválido"
|
|
274
|
+
|
|
248
275
|
- CPF deve conter 11 dígitos numéricos
|
|
249
276
|
- CNPJ deve conter 14 dígitos numéricos
|
|
250
277
|
- Caracteres especiais são removidos automaticamente
|
|
251
278
|
|
|
252
279
|
### Erro: "Valor do pagamento deve ser maior que zero"
|
|
280
|
+
|
|
253
281
|
- Verifique se o valor está correto
|
|
254
282
|
- Valores são convertidos automaticamente para centavos
|
|
255
283
|
|
|
256
284
|
### Webhook não recebe notificações
|
|
285
|
+
|
|
257
286
|
- Verifique se a URL é acessível publicamente
|
|
258
287
|
- Certifique-se de que o servidor está rodando e acessível
|
|
259
288
|
- Verifique os logs do Mercado Pago no painel de desenvolvedores
|
|
@@ -290,4 +319,3 @@ Eliveuton Souza - eliveuton3m@hotmail.com
|
|
|
290
319
|
|
|
291
320
|
- Equipe do n8n pela excelente plataforma
|
|
292
321
|
- Mercado Pago pela API robusta e documentação completa
|
|
293
|
-
|
|
@@ -6,6 +6,11 @@ export declare class PixPayment implements INodeType {
|
|
|
6
6
|
private static createPixPayment;
|
|
7
7
|
private static getPixPayment;
|
|
8
8
|
private static refundPixPayment;
|
|
9
|
+
private static handlePlanOperation;
|
|
10
|
+
private static createPlan;
|
|
11
|
+
private static getPlan;
|
|
12
|
+
private static listPlans;
|
|
13
|
+
private static updatePlan;
|
|
9
14
|
private static handleSubscriptionOperation;
|
|
10
15
|
private static createSubscription;
|
|
11
16
|
private static getSubscription;
|
|
@@ -34,6 +34,10 @@ class PixPayment {
|
|
|
34
34
|
name: 'PIX',
|
|
35
35
|
value: 'pix',
|
|
36
36
|
},
|
|
37
|
+
{
|
|
38
|
+
name: 'Plano',
|
|
39
|
+
value: 'plans',
|
|
40
|
+
},
|
|
37
41
|
{
|
|
38
42
|
name: 'Assinatura',
|
|
39
43
|
value: 'subscriptions',
|
|
@@ -577,6 +581,9 @@ class PixPayment {
|
|
|
577
581
|
case 'pix':
|
|
578
582
|
responseData = await PixPayment.handlePixOperation(this, operation, i, baseUrl, credentials);
|
|
579
583
|
break;
|
|
584
|
+
case 'plans':
|
|
585
|
+
responseData = await PixPayment.handlePlanOperation(this, operation, i, baseUrl, credentials);
|
|
586
|
+
break;
|
|
580
587
|
case 'subscriptions':
|
|
581
588
|
responseData = await PixPayment.handleSubscriptionOperation(this, operation, i, baseUrl, credentials);
|
|
582
589
|
break;
|
|
@@ -721,6 +728,120 @@ class PixPayment {
|
|
|
721
728
|
});
|
|
722
729
|
return response;
|
|
723
730
|
}
|
|
731
|
+
static async handlePlanOperation(executeFunctions, operation, itemIndex, baseUrl, credentials) {
|
|
732
|
+
switch (operation) {
|
|
733
|
+
case 'create':
|
|
734
|
+
return await PixPayment.createPlan(executeFunctions, itemIndex, baseUrl, credentials);
|
|
735
|
+
case 'get':
|
|
736
|
+
return await PixPayment.getPlan(executeFunctions, itemIndex, baseUrl, credentials);
|
|
737
|
+
case 'list':
|
|
738
|
+
return await PixPayment.listPlans(executeFunctions, itemIndex, baseUrl, credentials);
|
|
739
|
+
case 'update':
|
|
740
|
+
return await PixPayment.updatePlan(executeFunctions, itemIndex, baseUrl, credentials);
|
|
741
|
+
default:
|
|
742
|
+
throw new Error(`Operação de plano "${operation}" não é suportada`);
|
|
743
|
+
}
|
|
744
|
+
}
|
|
745
|
+
static async createPlan(executeFunctions, itemIndex, baseUrl, credentials) {
|
|
746
|
+
const reason = executeFunctions.getNodeParameter('reason', itemIndex);
|
|
747
|
+
const amount = executeFunctions.getNodeParameter('amount', itemIndex);
|
|
748
|
+
const frequency = executeFunctions.getNodeParameter('frequency', itemIndex);
|
|
749
|
+
const frequencyType = executeFunctions.getNodeParameter('frequencyType', itemIndex);
|
|
750
|
+
if (!reason || reason.trim() === '') {
|
|
751
|
+
throw new Error('Nome do plano é obrigatório');
|
|
752
|
+
}
|
|
753
|
+
if (amount <= 0) {
|
|
754
|
+
throw new Error('Valor do plano deve ser maior que zero');
|
|
755
|
+
}
|
|
756
|
+
if (frequency <= 0) {
|
|
757
|
+
throw new Error('Frequência deve ser maior que zero');
|
|
758
|
+
}
|
|
759
|
+
if (frequencyType !== 'days' && frequencyType !== 'months') {
|
|
760
|
+
throw new Error('Tipo de frequência deve ser "days" ou "months"');
|
|
761
|
+
}
|
|
762
|
+
const body = {
|
|
763
|
+
reason,
|
|
764
|
+
auto_recurring: {
|
|
765
|
+
frequency,
|
|
766
|
+
frequency_type: frequencyType,
|
|
767
|
+
transaction_amount: (0, helpers_1.normalizeAmount)(amount),
|
|
768
|
+
currency_id: 'BRL',
|
|
769
|
+
},
|
|
770
|
+
payment_methods_allowed: {
|
|
771
|
+
payment_types: [
|
|
772
|
+
{ id: 'credit_card' },
|
|
773
|
+
],
|
|
774
|
+
},
|
|
775
|
+
};
|
|
776
|
+
const response = await executeFunctions.helpers.requestWithAuthentication.call(executeFunctions, 'pixPaymentApi', {
|
|
777
|
+
method: 'POST',
|
|
778
|
+
url: `${baseUrl}/preapproval_plan`,
|
|
779
|
+
body,
|
|
780
|
+
headers: {
|
|
781
|
+
Authorization: `Bearer ${credentials.accessToken}`,
|
|
782
|
+
'Content-Type': 'application/json',
|
|
783
|
+
},
|
|
784
|
+
json: true,
|
|
785
|
+
});
|
|
786
|
+
return response;
|
|
787
|
+
}
|
|
788
|
+
static async getPlan(executeFunctions, itemIndex, baseUrl, credentials) {
|
|
789
|
+
const planId = executeFunctions.getNodeParameter('planId', itemIndex);
|
|
790
|
+
if (!planId || planId.trim() === '') {
|
|
791
|
+
throw new Error('ID do plano é obrigatório');
|
|
792
|
+
}
|
|
793
|
+
const response = await executeFunctions.helpers.requestWithAuthentication.call(executeFunctions, 'pixPaymentApi', {
|
|
794
|
+
method: 'GET',
|
|
795
|
+
url: `${baseUrl}/preapproval_plan/${planId}`,
|
|
796
|
+
headers: {
|
|
797
|
+
Authorization: `Bearer ${credentials.accessToken}`,
|
|
798
|
+
},
|
|
799
|
+
json: true,
|
|
800
|
+
});
|
|
801
|
+
return response;
|
|
802
|
+
}
|
|
803
|
+
static async listPlans(executeFunctions, _itemIndex, baseUrl, credentials) {
|
|
804
|
+
const response = await executeFunctions.helpers.requestWithAuthentication.call(executeFunctions, 'pixPaymentApi', {
|
|
805
|
+
method: 'GET',
|
|
806
|
+
url: `${baseUrl}/preapproval_plan/search`,
|
|
807
|
+
headers: {
|
|
808
|
+
Authorization: `Bearer ${credentials.accessToken}`,
|
|
809
|
+
},
|
|
810
|
+
json: true,
|
|
811
|
+
});
|
|
812
|
+
return response;
|
|
813
|
+
}
|
|
814
|
+
static async updatePlan(executeFunctions, itemIndex, baseUrl, credentials) {
|
|
815
|
+
const planId = executeFunctions.getNodeParameter('planId', itemIndex);
|
|
816
|
+
const reason = executeFunctions.getNodeParameter('reason', itemIndex);
|
|
817
|
+
const amount = executeFunctions.getNodeParameter('amount', itemIndex);
|
|
818
|
+
if (!planId || planId.trim() === '') {
|
|
819
|
+
throw new Error('ID do plano é obrigatório');
|
|
820
|
+
}
|
|
821
|
+
const body = {};
|
|
822
|
+
if (reason && reason.trim() !== '') {
|
|
823
|
+
body.reason = reason;
|
|
824
|
+
}
|
|
825
|
+
if (amount && amount > 0) {
|
|
826
|
+
body.auto_recurring = {
|
|
827
|
+
transaction_amount: (0, helpers_1.normalizeAmount)(amount),
|
|
828
|
+
};
|
|
829
|
+
}
|
|
830
|
+
if (Object.keys(body).length === 0) {
|
|
831
|
+
throw new Error('É necessário fornecer pelo menos um campo para atualizar (nome ou valor)');
|
|
832
|
+
}
|
|
833
|
+
const response = await executeFunctions.helpers.requestWithAuthentication.call(executeFunctions, 'pixPaymentApi', {
|
|
834
|
+
method: 'PUT',
|
|
835
|
+
url: `${baseUrl}/preapproval_plan/${planId}`,
|
|
836
|
+
body,
|
|
837
|
+
headers: {
|
|
838
|
+
Authorization: `Bearer ${credentials.accessToken}`,
|
|
839
|
+
'Content-Type': 'application/json',
|
|
840
|
+
},
|
|
841
|
+
json: true,
|
|
842
|
+
});
|
|
843
|
+
return response;
|
|
844
|
+
}
|
|
724
845
|
static async handleSubscriptionOperation(executeFunctions, operation, itemIndex, baseUrl, credentials) {
|
|
725
846
|
switch (operation) {
|
|
726
847
|
case 'create':
|
|
@@ -1017,6 +1138,11 @@ class PixPayment {
|
|
|
1017
1138
|
normalized.description = data.description;
|
|
1018
1139
|
normalized.payerEmail = data.payer?.email;
|
|
1019
1140
|
break;
|
|
1141
|
+
case 'plans':
|
|
1142
|
+
normalized.planId = data.id;
|
|
1143
|
+
normalized.amount = data.auto_recurring?.transaction_amount ? data.auto_recurring.transaction_amount / 100 : undefined;
|
|
1144
|
+
normalized.description = data.reason;
|
|
1145
|
+
break;
|
|
1020
1146
|
case 'subscriptions':
|
|
1021
1147
|
normalized.planId = data.preapproval_plan_id;
|
|
1022
1148
|
normalized.payerEmail = data.payer_email;
|
|
@@ -58,6 +58,27 @@ export interface Subscription {
|
|
|
58
58
|
recurring_application_id?: number;
|
|
59
59
|
operation_type?: string;
|
|
60
60
|
}
|
|
61
|
+
export interface Plan {
|
|
62
|
+
id: string;
|
|
63
|
+
status: string;
|
|
64
|
+
reason: string;
|
|
65
|
+
auto_recurring: {
|
|
66
|
+
frequency: number;
|
|
67
|
+
frequency_type: string;
|
|
68
|
+
transaction_amount: number;
|
|
69
|
+
currency_id: string;
|
|
70
|
+
};
|
|
71
|
+
payment_methods_allowed?: {
|
|
72
|
+
payment_types?: Array<{
|
|
73
|
+
id: string;
|
|
74
|
+
}>;
|
|
75
|
+
payment_methods?: Array<{
|
|
76
|
+
id: string;
|
|
77
|
+
}>;
|
|
78
|
+
};
|
|
79
|
+
date_created?: string;
|
|
80
|
+
last_modified?: string;
|
|
81
|
+
}
|
|
61
82
|
export interface RecurringPayment {
|
|
62
83
|
id: string;
|
|
63
84
|
status: string;
|