{
  "name": "SP \u00b7 25 \u00b7 Factura Email tras Pago",
  "nodes": [
    {
      "parameters": {
        "httpMethod": "POST",
        "path": "pago-registrado",
        "responseMode": "lastNode",
        "options": {}
      },
      "id": "sp25inv-0001",
      "name": "Webhook \u00b7 Pago registrado",
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 2,
      "position": [
        240,
        300
      ]
    },
    {
      "parameters": {
        "respondWith": "json",
        "responseBody": "={ \"ok\": true }"
      },
      "id": "sp25inv-0002",
      "name": "Responder OK",
      "type": "n8n-nodes-base.respondToWebhook",
      "typeVersion": 1,
      "position": [
        460,
        500
      ]
    },
    {
      "parameters": {
        "conditions": {
          "conditions": [
            {
              "leftValue": "={{ $json.email }}",
              "rightValue": "",
              "operator": {
                "type": "string",
                "operation": "notEquals"
              }
            }
          ]
        }
      },
      "id": "sp25inv-0003",
      "name": "\u00bfTiene email?",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2,
      "position": [
        460,
        300
      ]
    },
    {
      "parameters": {
        "jsCode": "const d=$input.first().json;\nconst imp=parseFloat(d.importe||0).toFixed(2);\nreturn [{ json: { ...d,\n  asunto: `Factura ${d.numFactura||''} \u2014 ${$vars.CLINICA_NOMBRE}`,\n  cuerpo: `Estimado/a ${d.nombre},\\n\\nFactura por los servicios recibidos:\\n\\nN\u00ba Factura: ${d.numFactura||'Ver adjunto'}\\nConcepto: ${d.tratamiento||'Servicios dentales'}\\nImporte: ${imp}\u20ac\\nFecha: ${d.fechaStr||new Date().toLocaleDateString('es-ES')}\\nForma de pago: ${d.formaPago||'\u2014'}\\n\\nGracias por su confianza.\\n${$vars.CLINICA_NOMBRE}\\n${$vars.CLINICA_TELEFONO}`\n} }];"
      },
      "id": "sp25inv-0004",
      "name": "Preparar email factura",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        680,
        220
      ]
    },
    {
      "parameters": {
        "fromEmail": "={{ $vars.SMTP_USER }}",
        "toEmail": "={{ $json.email }}",
        "subject": "={{ $json.asunto }}",
        "emailType": "text",
        "message": "={{ $json.cuerpo }}",
        "options": {}
      },
      "id": "sp25inv-0005",
      "name": "Email \u00b7 Factura",
      "type": "n8n-nodes-base.emailSend",
      "typeVersion": 2.1,
      "position": [
        900,
        220
      ],
      "credentials": {
        "smtp": {
          "name": "<your credential>"
        }
      }
    }
  ],
  "connections": {
    "Webhook \u00b7 Pago registrado": {
      "main": [
        [
          {
            "node": "\u00bfTiene email?",
            "type": "main",
            "index": 0
          },
          {
            "node": "Responder OK",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "\u00bfTiene email?": {
      "main": [
        [
          {
            "node": "Preparar email factura",
            "type": "main",
            "index": 0
          }
        ],
        []
      ]
    },
    "Preparar email factura": {
      "main": [
        [
          {
            "node": "Email \u00b7 Factura",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": false,
  "settings": {
    "executionOrder": "v1"
  },
  "id": "sp-invoice-doctor-025"
}