{
  "name": "07 Payment received: mark invoice paid and say thanks",
  "nodes": [
    {
      "id": "88e75666-8d90-4a3e-97b6-57d54cc25e1e",
      "name": "Payment notification",
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 2,
      "position": [
        0,
        300
      ],
      "parameters": {
        "httpMethod": "POST",
        "path": "payment-received",
        "authentication": "headerAuth",
        "responseMode": "responseNode",
        "options": {}
      },
      "notes": "Header x-secret must match, otherwise n8n refuses with 403",
      "notesInFlow": true,
      "webhookId": "f0e5a556-b922-5c97-9c74-dbc8e073a2f1"
    },
    {
      "id": "b1758347-8493-4055-b9d6-e455a39615e4",
      "name": "Find invoice",
      "type": "n8n-nodes-base.dataTable",
      "typeVersion": 1,
      "position": [
        240,
        300
      ],
      "parameters": {
        "resource": "row",
        "operation": "get",
        "dataTableId": {
          "__rl": true,
          "mode": "list",
          "value": "",
          "cachedResultName": "invoices"
        },
        "matchType": "allConditions",
        "filters": {
          "conditions": [
            {
              "keyName": "invoice_number",
              "condition": "eq",
              "keyValue": "={{ $json.body.invoice_number }}"
            },
            {
              "keyName": "status",
              "condition": "eq",
              "keyValue": "open"
            }
          ]
        },
        "returnAll": true
      }
    },
    {
      "id": "1304d764-80ef-413e-ae4c-1b2e3f8fedb2",
      "name": "Mark as paid",
      "type": "n8n-nodes-base.dataTable",
      "typeVersion": 1,
      "position": [
        480,
        300
      ],
      "parameters": {
        "resource": "row",
        "operation": "update",
        "dataTableId": {
          "__rl": true,
          "mode": "list",
          "value": "",
          "cachedResultName": "invoices"
        },
        "matchType": "allConditions",
        "filters": {
          "conditions": [
            {
              "keyName": "id",
              "condition": "eq",
              "keyValue": "={{ $json.id }}"
            }
          ]
        },
        "columns": {
          "mappingMode": "defineBelow",
          "value": {
            "status": "paid"
          },
          "matchingColumns": [],
          "schema": [
            {
              "id": "status",
              "displayName": "status",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            }
          ]
        },
        "options": {}
      }
    },
    {
      "id": "5545823e-5f0d-452b-b2ec-7bbd2d552fb2",
      "name": "Thank-you email",
      "type": "n8n-nodes-base.emailSend",
      "typeVersion": 2.1,
      "position": [
        720,
        300
      ],
      "parameters": {
        "fromEmail": "info@example.com",
        "toEmail": "={{ $('Find invoice').item.json.client_email }}",
        "subject": "=Payment received for invoice {{ $('Find invoice').item.json.invoice_number }}",
        "emailFormat": "text",
        "text": "=Hi {{ $('Find invoice').item.json.client }},\n\nWe received your payment for invoice {{ $('Find invoice').item.json.invoice_number }}. Thank you!\n\nBest regards",
        "options": {
          "appendAttribution": false
        }
      }
    },
    {
      "id": "f5ae1074-b53a-4ae0-adea-bb38c27ec9a5",
      "name": "Response",
      "type": "n8n-nodes-base.respondToWebhook",
      "typeVersion": 1.1,
      "position": [
        960,
        300
      ],
      "parameters": {
        "respondWith": "json",
        "responseBody": "={\"ok\": true}",
        "options": {}
      }
    },
    {
      "id": "b8ad6cc8-2e1d-4682-b95b-e83e2a37ad5e",
      "name": "Read me",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        -40,
        -160
      ],
      "parameters": {
        "content": "## Payment received via webhook\nTested on November 11, 2026, with n8n 2.47.3.\n\n**Fill in:** a Header Auth credential (name x-secret, value: a long random secret), an SMTP account, and the *invoices* table.\n\nWithout the right secret, n8n answers 403.",
        "height": 220,
        "width": 520,
        "color": 7
      }
    }
  ],
  "connections": {
    "Payment notification": {
      "main": [
        [
          {
            "node": "Find invoice",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Find invoice": {
      "main": [
        [
          {
            "node": "Mark as paid",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Mark as paid": {
      "main": [
        [
          {
            "node": "Thank-you email",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Thank-you email": {
      "main": [
        [
          {
            "node": "Response",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "meta": {
    "templateCredsSetupCompleted": false
  },
  "pinData": {},
  "settings": {
    "executionOrder": "v1"
  }
}