{
  "name": "SPEICEP - Validar pago SPEI",
  "nodes": [
    {
      "parameters": {
        "content": "## SPEICEP - Validar pago SPEI\n\n**Que hace:** recibe los datos de un comprobante por webhook, los valida contra el CEP de Banxico con la API de SPEICEP y responde el resultado.\n\n**Configura antes de usar:**\n1. En el nodo **Validar en SPEICEP**, reemplaza `sk_live_TU_API_KEY` por tu API key (Dashboard - Llaves de API).\n2. Activa el workflow (toggle arriba a la derecha).\n\n**Como probarlo (POST al webhook):**\n```\n{\n  \"operationDate\": \"03-09-2026\",\n  \"trackingKey\": \"167-03/09/2026/03-300W573012\",\n  \"senderBank\": \"Hey Banco\",\n  \"amount\": 1\n}\n```\nRespuesta: `status` = valid / not_found / failed, mas el CEP completo.",
        "height": 360,
        "width": 420
      },
      "id": "a1b2c3d4-0001-4a00-8000-000000000001",
      "name": "Guia",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [-40, 60]
    },
    {
      "parameters": {
        "httpMethod": "POST",
        "path": "validar-pago-spei",
        "responseMode": "responseNode",
        "options": {}
      },
      "id": "a1b2c3d4-0002-4a00-8000-000000000002",
      "name": "Entra un pago",
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 2,
      "position": [460, 300],
      "webhookId": "speicep-validar-pago-spei"
    },
    {
      "parameters": {
        "method": "POST",
        "url": "https://speicep.com/api/v1/validate/manual",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            { "name": "Authorization", "value": "Bearer sk_live_TU_API_KEY" }
          ]
        },
        "sendBody": true,
        "bodyParameters": {
          "parameters": [
            { "name": "operationDate", "value": "={{ $json.body.operationDate }}" },
            { "name": "trackingKey", "value": "={{ $json.body.trackingKey }}" },
            { "name": "senderBank", "value": "={{ $json.body.senderBank }}" },
            { "name": "amount", "value": "={{ Number($json.body.amount) }}" }
          ]
        },
        "options": {}
      },
      "id": "a1b2c3d4-0003-4a00-8000-000000000003",
      "name": "Validar en SPEICEP",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [700, 300]
    },
    {
      "parameters": {
        "rules": {
          "values": [
            {
              "conditions": {
                "options": { "caseSensitive": true, "typeValidation": "loose" },
                "conditions": [
                  {
                    "leftValue": "={{ $json.status }}",
                    "rightValue": "valid",
                    "operator": { "type": "string", "operation": "equals" }
                  }
                ],
                "combinator": "and"
              },
              "renameOutput": true,
              "outputKey": "valido"
            },
            {
              "conditions": {
                "options": { "caseSensitive": true, "typeValidation": "loose" },
                "conditions": [
                  {
                    "leftValue": "={{ $json.status }}",
                    "rightValue": "not_found",
                    "operator": { "type": "string", "operation": "equals" }
                  }
                ],
                "combinator": "and"
              },
              "renameOutput": true,
              "outputKey": "no_encontrado"
            }
          ]
        },
        "options": { "fallbackOutput": "extra", "renameFallbackOutput": "fallo" }
      },
      "id": "a1b2c3d4-0004-4a00-8000-000000000004",
      "name": "Segun resultado",
      "type": "n8n-nodes-base.switch",
      "typeVersion": 3,
      "position": [940, 300]
    },
    {
      "parameters": {
        "respondWith": "json",
        "responseBody": "={{ $json }}",
        "options": {}
      },
      "id": "a1b2c3d4-0005-4a00-8000-000000000005",
      "name": "Responder",
      "type": "n8n-nodes-base.respondToWebhook",
      "typeVersion": 1.1,
      "position": [1200, 300]
    }
  ],
  "connections": {
    "Entra un pago": {
      "main": [[ { "node": "Validar en SPEICEP", "type": "main", "index": 0 } ]]
    },
    "Validar en SPEICEP": {
      "main": [[ { "node": "Segun resultado", "type": "main", "index": 0 } ]]
    },
    "Segun resultado": {
      "main": [
        [ { "node": "Responder", "type": "main", "index": 0 } ],
        [ { "node": "Responder", "type": "main", "index": 0 } ],
        [ { "node": "Responder", "type": "main", "index": 0 } ]
      ]
    }
  },
  "settings": { "executionOrder": "v1" },
  "active": false
}
