{
  "id": "O7oE0RWAFdF5sv4q",
  "name": "Billing Automation With Mercado Pago",
  "tags": [],
  "nodes": [
    {
      "id": "ddc6610e-8365-49f9-8117-3cfdbb323a88",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        0,
        0
      ],
      "parameters": {
        "width": 480,
        "height": 992,
        "content": "## Billing Automation With Mercado Pago\n\n### How it works\n\nThis workflow automates billing through three coordinated paths: it watches Google Sheets for pending invoices, creates Mercado Pago payment links, emails them, and records each sent payment. It also listens for Mercado Pago payment webhooks, verifies approved payments, and removes paid invoices from the tracking sheet. A scheduled reminder path periodically emails customers who still have pending invoices.\n\n### Setup steps\n\n- Connect Google Sheets credentials and configure the invoice source sheet, sent-payment record sheet, and pending-invoice lookup/delete operations used by the Google Sheets nodes.\n- Connect Mercado Pago credentials for creating payment links and for the HTTP request that retrieves payment details from Mercado Pago webhook notifications.\n- Configure Gmail credentials and set the email templates, recipients, subject lines, and dynamic invoice/payment-link fields.\n- Set the Google Sheets Trigger to monitor the correct sheet and columns for pending invoices, and configure the Daily Reminder Schedule timing.\n- Register the workflow Webhook URL in Mercado Pago so payment notifications are sent to this workflow.\n\n### Customization\n\nAdjust the invoice status filters, reminder frequency, email copy, and Google Sheets row matching fields to fit your billing process.\n\n## Requirements\n\n* n8n\n* Google Sheets account\n* Gmail account\n* Mercado Pago account\n* **Mercado Pago community node for n8n** \u2014 This workflow uses the community node `n8n-nodes-mercadopago`. Install the node before running the workflow.\n"
      },
      "typeVersion": 1
    },
    {
      "id": "9e633dd6-0c5c-46ca-8412-5219024a1526",
      "name": "Sticky Note1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        560,
        16
      ],
      "parameters": {
        "color": 7,
        "width": 608,
        "height": 304,
        "content": "## Pending invoice intake\n\nStarts when Google Sheets changes, filters rows to pending invoices, and batches them for payment-link processing."
      },
      "typeVersion": 1
    },
    {
      "id": "10aff4ac-5ca9-42d1-b9ba-8c3521dfe6f7",
      "name": "Sticky Note2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1264,
        0
      ],
      "parameters": {
        "color": 7,
        "width": 432,
        "height": 320,
        "content": "## Create and email links\n\nCreates a Mercado Pago payment link for each batched invoice and sends it to the customer through Gmail."
      },
      "typeVersion": 1
    },
    {
      "id": "93c40c38-9b10-4683-bbd6-7adbfd6108de",
      "name": "Sticky Note3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1744,
        32
      ],
      "parameters": {
        "color": 7,
        "width": 608,
        "height": 304,
        "content": "## Record sent invoices\n\nSaves the sent payment record, finds the original invoice row, deletes the processed invoice, and loops back for the next batch item."
      },
      "typeVersion": 1
    },
    {
      "id": "b9e1d069-926a-4597-8950-9f5280a73d69",
      "name": "Sticky Note4",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        576,
        352
      ],
      "parameters": {
        "color": 7,
        "width": 592,
        "height": 304,
        "content": "## Verify payment webhook\n\nReceives Mercado Pago webhook notifications, fetches the payment details, and checks whether the payment was approved."
      },
      "typeVersion": 1
    },
    {
      "id": "371182a8-324f-4b1a-abe6-bb4dcbe7f747",
      "name": "Sticky Note5",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1232,
        352
      ],
      "parameters": {
        "color": 7,
        "width": 400,
        "height": 320,
        "content": "## Remove paid invoices\n\nFinds the matching invoice for an approved payment and deletes it from the Google Sheets tracking list."
      },
      "typeVersion": 1
    },
    {
      "id": "3cc7b8e7-550e-402a-a627-0c07641d6e2c",
      "name": "Sticky Note6",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        576,
        720
      ],
      "parameters": {
        "color": 7,
        "width": 864,
        "height": 320,
        "content": "## Send payment reminders\n\nRuns on a daily schedule, retrieves pending invoices, loops through them, and sends reminder emails until the batch is complete."
      },
      "typeVersion": 1
    },
    {
      "id": "83c557db-83fe-4fd6-a968-510edb94e694",
      "name": "Spreadsheet Update Trigger",
      "type": "n8n-nodes-base.googleSheetsTrigger",
      "position": [
        608,
        144
      ],
      "parameters": {
        "options": {},
        "pollTimes": {
          "item": [
            {
              "mode": "everyMinute"
            }
          ]
        },
        "sheetName": {
          "__rl": true,
          "mode": "list",
          "value": "gid=0",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1IDAUohyPF9Uo5cndu5DjJYeo7SWbQIadHiH2vSfoMlE/edit#gid=0",
          "cachedResultName": "A Enviar"
        },
        "documentId": {
          "__rl": true,
          "mode": "list",
          "value": "1IDAUohyPF9Uo5cndu5DjJYeo7SWbQIadHiH2vSfoMlE",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1IDAUohyPF9Uo5cndu5DjJYeo7SWbQIadHiH2vSfoMlE/edit?usp=drivesdk",
          "cachedResultName": "Contas a Receber"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "c31c4adc-6a66-4253-b419-79ddef00071e",
      "name": "Generate Payment Link",
      "type": "@mercadopago/n8n-nodes-mercadopago.mercadoPago",
      "position": [
        1312,
        160
      ],
      "parameters": {
        "items": {
          "itemsValues": [
            {
              "title": "Pagamento",
              "unit_price": "={{ $json['Pre\u00e7o'] }}",
              "currency_id": "BRL"
            }
          ]
        },
        "additionalFields": {
          "notification_url": "YOUR_N8N_PRODUCTION_WEBHOOK_URL_HERE",
          "expiration_date_to": "={{ $now.plus({ hours: 4380 }).toISO() }}"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "309bac57-0fb3-4d45-b89c-af66deb4d91a",
      "name": "MercadoPago Webhook POST",
      "type": "n8n-nodes-base.webhook",
      "position": [
        624,
        480
      ],
      "parameters": {
        "path": "mercadopago-payment",
        "options": {},
        "httpMethod": "POST"
      },
      "typeVersion": 2.1
    },
    {
      "id": "df421bf9-04b4-45ba-ba26-940ec1f772f6",
      "name": "Fetch Payment Information",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        816,
        480
      ],
      "parameters": {
        "url": "=https://api.mercadopago.com/merchant_orders/{{ $json.query.id }}",
        "options": {},
        "authentication": "predefinedCredentialType",
        "nodeCredentialType": "mercadoPagoApi"
      },
      "typeVersion": 4.3
    },
    {
      "id": "d38335c8-f086-47b0-9ee6-d178eb3f1ede",
      "name": "Batch Process Invoices",
      "type": "n8n-nodes-base.splitInBatches",
      "position": [
        1024,
        144
      ],
      "parameters": {
        "options": {}
      },
      "typeVersion": 3
    },
    {
      "id": "5a53699c-60a8-43e6-a8f3-45dcade188d1",
      "name": "Filter Unpaid Invoices",
      "type": "n8n-nodes-base.filter",
      "position": [
        816,
        144
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 3,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "9f956ad4-35d8-44ed-8adf-9ab5865789b1",
              "operator": {
                "type": "string",
                "operation": "equals"
              },
              "leftValue": "={{ $json.Enviado }}",
              "rightValue": "=Sim"
            }
          ]
        }
      },
      "typeVersion": 2.3
    },
    {
      "id": "165f479b-5243-4f3b-84c6-bd9dbc0d3afe",
      "name": "Email Payment Link",
      "type": "n8n-nodes-base.gmail",
      "position": [
        1552,
        160
      ],
      "parameters": {
        "sendTo": "={{ $('Batch Process Invoices').item.json.Email }}",
        "message": "=Hi, {{ $('Batch Process Invoices').item.json.Nome }}\nPlease find attached the link for the payment of {{ $('Batch Process Invoices').item.json['Pre\u00e7o'] }}:\n{{ $json.init_point }}",
        "options": {},
        "subject": "Link para pagamento",
        "emailType": "text"
      },
      "typeVersion": 2.2
    },
    {
      "id": "87f6289a-0549-450a-a42f-132ceaea6c35",
      "name": "Log Payment Record",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        1792,
        160
      ],
      "parameters": {
        "columns": {
          "value": {
            "Nome": "={{ $('Batch Process Invoices').item.json.Nome }}",
            "Email": "={{ $('Batch Process Invoices').item.json.Email }}",
            "Pre\u00e7o": "={{ $('Batch Process Invoices').item.json['Pre\u00e7o'] }}",
            "Enviado": "={{ $('Generate Payment Link').item.json.init_point }}"
          },
          "schema": [
            {
              "id": "Nome",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Nome",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Email",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Email",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Pre\u00e7o",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Pre\u00e7o",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Enviado",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Enviado",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            }
          ],
          "mappingMode": "defineBelow",
          "matchingColumns": [],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "options": {},
        "operation": "append",
        "sheetName": {
          "__rl": true,
          "mode": "list",
          "value": 997704234,
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1IDAUohyPF9Uo5cndu5DjJYeo7SWbQIadHiH2vSfoMlE/edit#gid=997704234",
          "cachedResultName": "Enviados"
        },
        "documentId": {
          "__rl": true,
          "mode": "list",
          "value": "1IDAUohyPF9Uo5cndu5DjJYeo7SWbQIadHiH2vSfoMlE",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1IDAUohyPF9Uo5cndu5DjJYeo7SWbQIadHiH2vSfoMlE/edit?usp=drivesdk",
          "cachedResultName": "Contas a Receber"
        }
      },
      "typeVersion": 4.7
    },
    {
      "id": "47fcd09b-8845-4ffd-a6b2-9e797a633c82",
      "name": "Locate Sent Invoice",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        2000,
        160
      ],
      "parameters": {
        "options": {},
        "filtersUI": {
          "values": [
            {
              "lookupValue": "={{ $json.Nome }}",
              "lookupColumn": "Nome"
            },
            {
              "lookupValue": "={{ $json.Email }}",
              "lookupColumn": "Email"
            },
            {
              "lookupValue": "={{ $json['Pre\u00e7o'] }}",
              "lookupColumn": "Pre\u00e7o"
            }
          ]
        },
        "sheetName": {
          "__rl": true,
          "mode": "list",
          "value": "gid=0",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1IDAUohyPF9Uo5cndu5DjJYeo7SWbQIadHiH2vSfoMlE/edit#gid=0",
          "cachedResultName": "A Enviar"
        },
        "documentId": {
          "__rl": true,
          "mode": "list",
          "value": "1IDAUohyPF9Uo5cndu5DjJYeo7SWbQIadHiH2vSfoMlE",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1IDAUohyPF9Uo5cndu5DjJYeo7SWbQIadHiH2vSfoMlE/edit?usp=drivesdk",
          "cachedResultName": "Contas a Receber"
        }
      },
      "typeVersion": 4.7
    },
    {
      "id": "3757c0fb-f8d1-4db4-9003-2c7c3d7bf2a0",
      "name": "Remove Processed Invoice",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        2208,
        160
      ],
      "parameters": {
        "operation": "delete",
        "sheetName": {
          "__rl": true,
          "mode": "list",
          "value": "gid=0",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1IDAUohyPF9Uo5cndu5DjJYeo7SWbQIadHiH2vSfoMlE/edit#gid=0",
          "cachedResultName": "A Enviar"
        },
        "documentId": {
          "__rl": true,
          "mode": "list",
          "value": "1IDAUohyPF9Uo5cndu5DjJYeo7SWbQIadHiH2vSfoMlE",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1IDAUohyPF9Uo5cndu5DjJYeo7SWbQIadHiH2vSfoMlE/edit?usp=drivesdk",
          "cachedResultName": "Contas a Receber"
        },
        "startIndex": "={{ $json.row_number }}"
      },
      "typeVersion": 4.7
    },
    {
      "id": "50158a0c-6c7b-405a-a970-35e7b6a34976",
      "name": "Verify Payment Success",
      "type": "n8n-nodes-base.if",
      "position": [
        1024,
        480
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 3,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "7916f50e-c758-4736-98c4-2eacf1822bc6",
              "operator": {
                "type": "boolean",
                "operation": "true",
                "singleValue": true
              },
              "leftValue": "={{ $json.payments.every(payment => payment.status === 'approved') }}",
              "rightValue": "approved"
            },
            {
              "id": "ed4c5986-a457-4ab9-a7f8-d322b652a7cb",
              "operator": {
                "type": "boolean",
                "operation": "true",
                "singleValue": true
              },
              "leftValue": "={{ $json.payments.length > 0 }}",
              "rightValue": ""
            }
          ]
        }
      },
      "typeVersion": 2.3
    },
    {
      "id": "23199f61-bce1-4e5e-ae25-7529d00cc07f",
      "name": "Retrieve Matching Invoice",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        1280,
        512
      ],
      "parameters": {
        "options": {},
        "filtersUI": {
          "values": [
            {
              "lookupValue": "={{ $json.items[0].unit_price }}",
              "lookupColumn": "Pre\u00e7o"
            },
            {
              "lookupValue": "=https://mercadopago.com.br/checkout/v1/redirect?pref_id={{ $json.preference_id }}",
              "lookupColumn": "Enviado"
            }
          ]
        },
        "sheetName": {
          "__rl": true,
          "mode": "list",
          "value": 997704234,
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1IDAUohyPF9Uo5cndu5DjJYeo7SWbQIadHiH2vSfoMlE/edit#gid=997704234",
          "cachedResultName": "Enviados"
        },
        "documentId": {
          "__rl": true,
          "mode": "list",
          "value": "1IDAUohyPF9Uo5cndu5DjJYeo7SWbQIadHiH2vSfoMlE",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1IDAUohyPF9Uo5cndu5DjJYeo7SWbQIadHiH2vSfoMlE/edit?usp=drivesdk",
          "cachedResultName": "Contas a Receber"
        }
      },
      "typeVersion": 4.7
    },
    {
      "id": "766eeee7-3a38-40b6-babf-82f3b92434ae",
      "name": "Erase Paid Invoice",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        1488,
        512
      ],
      "parameters": {
        "operation": "delete",
        "sheetName": {
          "__rl": true,
          "mode": "list",
          "value": 997704234,
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1IDAUohyPF9Uo5cndu5DjJYeo7SWbQIadHiH2vSfoMlE/edit#gid=997704234",
          "cachedResultName": "Enviados"
        },
        "documentId": {
          "__rl": true,
          "mode": "list",
          "value": "1IDAUohyPF9Uo5cndu5DjJYeo7SWbQIadHiH2vSfoMlE",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1IDAUohyPF9Uo5cndu5DjJYeo7SWbQIadHiH2vSfoMlE/edit?usp=drivesdk",
          "cachedResultName": "Contas a Receber"
        },
        "startIndex": "={{ $json.row_number }}"
      },
      "typeVersion": 4.7
    },
    {
      "id": "66e70ae5-99c5-413c-ba5b-93d55ee06974",
      "name": "Daily Noon Reminder",
      "type": "n8n-nodes-base.scheduleTrigger",
      "position": [
        624,
        848
      ],
      "parameters": {
        "rule": {
          "interval": [
            {
              "triggerAtHour": 12
            }
          ]
        }
      },
      "typeVersion": 1.3
    },
    {
      "id": "e0df5212-4d99-43a6-9207-943f67f5ca85",
      "name": "Read Unpaid Invoices List",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        832,
        848
      ],
      "parameters": {
        "options": {},
        "sheetName": {
          "__rl": true,
          "mode": "list",
          "value": 997704234,
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1IDAUohyPF9Uo5cndu5DjJYeo7SWbQIadHiH2vSfoMlE/edit#gid=997704234",
          "cachedResultName": "Enviados"
        },
        "documentId": {
          "__rl": true,
          "mode": "list",
          "value": "1IDAUohyPF9Uo5cndu5DjJYeo7SWbQIadHiH2vSfoMlE",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1IDAUohyPF9Uo5cndu5DjJYeo7SWbQIadHiH2vSfoMlE/edit?usp=drivesdk",
          "cachedResultName": "Contas a Receber"
        }
      },
      "typeVersion": 4.7
    },
    {
      "id": "ed14e129-cd81-4a26-a1ae-0fbff3464008",
      "name": "Iterate Unpaid Invoices",
      "type": "n8n-nodes-base.splitInBatches",
      "position": [
        1040,
        848
      ],
      "parameters": {
        "options": {}
      },
      "typeVersion": 3
    },
    {
      "id": "30cbcd0f-027d-416d-8138-e73dee964e77",
      "name": "Dispatch Payment Reminder",
      "type": "n8n-nodes-base.gmail",
      "position": [
        1296,
        864
      ],
      "parameters": {
        "sendTo": "={{ $json.Email }}",
        "message": "=Hi, {{ $json.Nome }}\nPlease find attached the link for the payment of R$ {{ $json['Pre\u00e7o'] }}:\n{{ $json.Enviado }}",
        "options": {},
        "subject": "Link para Pagamento",
        "emailType": "text"
      },
      "typeVersion": 2.2
    }
  ],
  "active": false,
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "a7e39bcb-eb8e-4d2c-b2af-4f5cde5db34a",
  "connections": {
    "Email Payment Link": {
      "main": [
        [
          {
            "node": "Log Payment Record",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Log Payment Record": {
      "main": [
        [
          {
            "node": "Locate Sent Invoice",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Daily Noon Reminder": {
      "main": [
        [
          {
            "node": "Read Unpaid Invoices List",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Locate Sent Invoice": {
      "main": [
        [
          {
            "node": "Remove Processed Invoice",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Generate Payment Link": {
      "main": [
        [
          {
            "node": "Email Payment Link",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Batch Process Invoices": {
      "main": [
        [],
        [
          {
            "node": "Generate Payment Link",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Filter Unpaid Invoices": {
      "main": [
        [
          {
            "node": "Batch Process Invoices",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Verify Payment Success": {
      "main": [
        [
          {
            "node": "Retrieve Matching Invoice",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Iterate Unpaid Invoices": {
      "main": [
        [],
        [
          {
            "node": "Dispatch Payment Reminder",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "MercadoPago Webhook POST": {
      "main": [
        [
          {
            "node": "Fetch Payment Information",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Remove Processed Invoice": {
      "main": [
        [
          {
            "node": "Batch Process Invoices",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Dispatch Payment Reminder": {
      "main": [
        [
          {
            "node": "Iterate Unpaid Invoices",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Fetch Payment Information": {
      "main": [
        [
          {
            "node": "Verify Payment Success",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Read Unpaid Invoices List": {
      "main": [
        [
          {
            "node": "Iterate Unpaid Invoices",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Retrieve Matching Invoice": {
      "main": [
        [
          {
            "node": "Erase Paid Invoice",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Spreadsheet Update Trigger": {
      "main": [
        [
          {
            "node": "Filter Unpaid Invoices",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}