n8n-nodes-mercadopago-pix-assinatura 1.0.0 → 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
|
|
@@ -81,16 +88,20 @@ docker restart n8n
|
|
|
81
88
|
|
|
82
89
|
## 📖 Uso
|
|
83
90
|
|
|
91
|
+
> 📋 **Guia Completo de Campos**: Para exemplos detalhados de preenchimento de todos os campos de todas as operações, consulte o [Guia de Referência de Campos](./docs/GUIA_CAMPOS.md).
|
|
92
|
+
|
|
84
93
|
### PIX - Criar Pagamento
|
|
85
94
|
|
|
86
95
|
Cria um novo pagamento PIX e retorna o QR Code para pagamento.
|
|
87
96
|
|
|
88
97
|
**Campos obrigatórios:**
|
|
98
|
+
|
|
89
99
|
- Valor (em reais, ex: 10.50)
|
|
90
100
|
- Descrição
|
|
91
101
|
- E-mail do Pagador
|
|
92
102
|
|
|
93
103
|
**Campos opcionais:**
|
|
104
|
+
|
|
94
105
|
- CPF/CNPJ do Pagador
|
|
95
106
|
- Nome do Pagador
|
|
96
107
|
- Data de Expiração
|
|
@@ -98,6 +109,7 @@ Cria um novo pagamento PIX e retorna o QR Code para pagamento.
|
|
|
98
109
|
- Chave de Idempotência
|
|
99
110
|
|
|
100
111
|
**Resposta:**
|
|
112
|
+
|
|
101
113
|
```json
|
|
102
114
|
{
|
|
103
115
|
"id": "123456789",
|
|
@@ -118,9 +130,11 @@ Cria um novo pagamento PIX e retorna o QR Code para pagamento.
|
|
|
118
130
|
Consulta o status de um pagamento PIX existente.
|
|
119
131
|
|
|
120
132
|
**Campos obrigatórios:**
|
|
133
|
+
|
|
121
134
|
- ID do Pagamento
|
|
122
135
|
|
|
123
136
|
**Resposta:**
|
|
137
|
+
|
|
124
138
|
```json
|
|
125
139
|
{
|
|
126
140
|
"id": "123456789",
|
|
@@ -137,9 +151,11 @@ Consulta o status de um pagamento PIX existente.
|
|
|
137
151
|
Reembolsa total ou parcialmente um pagamento PIX.
|
|
138
152
|
|
|
139
153
|
**Campos obrigatórios:**
|
|
154
|
+
|
|
140
155
|
- ID do Pagamento
|
|
141
156
|
|
|
142
157
|
**Campos opcionais:**
|
|
158
|
+
|
|
143
159
|
- Valor do Reembolso (deixe vazio para reembolso total)
|
|
144
160
|
|
|
145
161
|
### Assinaturas - Criar
|
|
@@ -147,10 +163,12 @@ Reembolsa total ou parcialmente um pagamento PIX.
|
|
|
147
163
|
Cria uma nova assinatura baseada em um plano existente.
|
|
148
164
|
|
|
149
165
|
**Campos obrigatórios:**
|
|
166
|
+
|
|
150
167
|
- ID do Plano
|
|
151
168
|
- E-mail do Pagador
|
|
152
169
|
|
|
153
170
|
**Campos opcionais:**
|
|
171
|
+
|
|
154
172
|
- CPF/CNPJ do Pagador
|
|
155
173
|
- Data de Início
|
|
156
174
|
- Período de Trial (dias)
|
|
@@ -160,6 +178,7 @@ Cria uma nova assinatura baseada em um plano existente.
|
|
|
160
178
|
Gerencia o status de uma assinatura existente.
|
|
161
179
|
|
|
162
180
|
**Campos obrigatórios:**
|
|
181
|
+
|
|
163
182
|
- ID da Assinatura
|
|
164
183
|
|
|
165
184
|
### Assinaturas - Consultar/Listar
|
|
@@ -171,6 +190,7 @@ Consulta uma assinatura específica ou lista todas as assinaturas.
|
|
|
171
190
|
Gerencia pagamentos recorrentes com histórico e próxima cobrança.
|
|
172
191
|
|
|
173
192
|
**Operações disponíveis:**
|
|
193
|
+
|
|
174
194
|
- Criar
|
|
175
195
|
- Listar
|
|
176
196
|
- Cancelar
|
|
@@ -181,13 +201,16 @@ Gerencia pagamentos recorrentes com histórico e próxima cobrança.
|
|
|
181
201
|
Registra um novo webhook para receber notificações de eventos.
|
|
182
202
|
|
|
183
203
|
**Campos obrigatórios:**
|
|
204
|
+
|
|
184
205
|
- URL (deve ser acessível publicamente)
|
|
185
206
|
|
|
186
207
|
**Campos opcionais:**
|
|
208
|
+
|
|
187
209
|
- Eventos (payment, subscription)
|
|
188
210
|
- Descrição
|
|
189
211
|
|
|
190
212
|
**Eventos disponíveis:**
|
|
213
|
+
|
|
191
214
|
- `payment` - Notificações de pagamentos
|
|
192
215
|
- `subscription` - Notificações de assinaturas
|
|
193
216
|
|
|
@@ -209,6 +232,7 @@ Para testar localmente:
|
|
|
209
232
|
|
|
210
233
|
1. Configure credenciais sandbox do Mercado Pago
|
|
211
234
|
2. Execute o n8n em modo desenvolvimento:
|
|
235
|
+
|
|
212
236
|
```bash
|
|
213
237
|
npm run dev
|
|
214
238
|
```
|
|
@@ -224,10 +248,12 @@ Todas as respostas seguem um formato padronizado:
|
|
|
224
248
|
{
|
|
225
249
|
"id": "string",
|
|
226
250
|
"status": "string",
|
|
227
|
-
"amount": 0.
|
|
251
|
+
"amount": 0.0,
|
|
228
252
|
"currency": "BRL",
|
|
229
253
|
"createdAt": "ISO8601",
|
|
230
|
-
"raw": {
|
|
254
|
+
"raw": {
|
|
255
|
+
/* Dados completos da API */
|
|
256
|
+
}
|
|
231
257
|
}
|
|
232
258
|
```
|
|
233
259
|
|
|
@@ -236,22 +262,27 @@ O campo `raw` contém a resposta completa da API do Mercado Pago para acesso a t
|
|
|
236
262
|
## 🐛 Troubleshooting
|
|
237
263
|
|
|
238
264
|
### Erro: "Credenciais não encontradas"
|
|
265
|
+
|
|
239
266
|
- Verifique se as credenciais foram configuradas corretamente no n8n
|
|
240
267
|
- Certifique-se de que o Access Token está válido
|
|
241
268
|
|
|
242
269
|
### Erro: "E-mail do pagador inválido"
|
|
270
|
+
|
|
243
271
|
- Verifique o formato do e-mail (deve conter @ e domínio válido)
|
|
244
272
|
|
|
245
273
|
### Erro: "CPF/CNPJ inválido"
|
|
274
|
+
|
|
246
275
|
- CPF deve conter 11 dígitos numéricos
|
|
247
276
|
- CNPJ deve conter 14 dígitos numéricos
|
|
248
277
|
- Caracteres especiais são removidos automaticamente
|
|
249
278
|
|
|
250
279
|
### Erro: "Valor do pagamento deve ser maior que zero"
|
|
280
|
+
|
|
251
281
|
- Verifique se o valor está correto
|
|
252
282
|
- Valores são convertidos automaticamente para centavos
|
|
253
283
|
|
|
254
284
|
### Webhook não recebe notificações
|
|
285
|
+
|
|
255
286
|
- Verifique se a URL é acessível publicamente
|
|
256
287
|
- Certifique-se de que o servidor está rodando e acessível
|
|
257
288
|
- Verifique os logs do Mercado Pago no painel de desenvolvedores
|
|
@@ -288,4 +319,3 @@ Eliveuton Souza - eliveuton3m@hotmail.com
|
|
|
288
319
|
|
|
289
320
|
- Equipe do n8n pela excelente plataforma
|
|
290
321
|
- Mercado Pago pela API robusta e documentação completa
|
|
291
|
-
|
|
@@ -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;
|