{
  "name": "Nodbot - ЮKassa → n8n → CRM: обработать оплату и обновить сделку",
  "nodes": [
    {
      "parameters": {
        "content": "Шаблон Nodbot: ЮKassa → n8n → CRM: обработать оплату и обновить сделку\n\n1) Импортируйте JSON в n8n.\n2) Замените placeholders на свои credentials/URL из env или n8n credentials.\n3) Отправьте тестовый payload из статьи.\n4) Перед запуском проверьте повторный запуск, обработку ошибок и отсутствие секретов в execution data.\n\nВажно: Платёжные webhooks могут приходить повторно. Храните payment_id и не выполняйте бизнес-действие дважды.",
        "height": 240,
        "width": 460
      },
      "id": "58cb3eb4-2b76-47ed-a6a3-b1282776ed5b",
      "name": "Как использовать шаблон",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        -540,
        -260
      ]
    },
    {
      "parameters": {
        "httpMethod": "POST",
        "path": "yookassa-payment-to-crm",
        "responseMode": "responseNode",
        "options": {}
      },
      "id": "8de7f9fd-3ea4-4fa3-b9ae-c1f2ff396872",
      "name": "Webhook input",
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 2,
      "position": [
        -520,
        40
      ],
      "webhookId": "yookassa-payment-to-crm"
    },
    {
      "parameters": {
        "jsCode": "const input = $json.body || $json;\nconst required = [\"event\", \"object_id\", \"status\"];\nconst missing = required.filter((field) => {\n  const value = input[field] ?? input[field.toLowerCase()] ?? input[field.toUpperCase()];\n  return value === undefined || value === null || value === '';\n});\nconst normalized = {\n  \"event\": input[\"event\"] ?? input[\"Event\"] ?? input[\"EVENT\"] ?? '',\n  \"object_id\": input[\"object_id\"] ?? input[\"Object_Id\"] ?? input[\"OBJECT_ID\"] ?? '',\n  \"status\": input[\"status\"] ?? input[\"Status\"] ?? input[\"STATUS\"] ?? '',\n  \"paid\": input[\"paid\"] ?? input[\"Paid\"] ?? input[\"PAID\"] ?? '',\n  \"amount\": input[\"amount\"] ?? input[\"Amount\"] ?? input[\"AMOUNT\"] ?? '',\n  \"currency\": input[\"currency\"] ?? input[\"Currency\"] ?? input[\"CURRENCY\"] ?? '',\n  \"order_id\": input[\"order_id\"] ?? input[\"Order_Id\"] ?? input[\"ORDER_ID\"] ?? '',\n  \"customer_email\": input[\"customer_email\"] ?? input[\"Customer_Email\"] ?? input[\"CUSTOMER_EMAIL\"] ?? '',\n};\nreturn [{\n  json: {\n    ok: missing.length === 0,\n    template: \"yookassa-payment-to-crm\",\n    source: \"ЮKassa webhook\",\n    target: \"CRM deal\",\n    event_id: input.event_id || input.lead_id || input.object_id || input.order_id || input.id || `${Date.now()}-${Math.random().toString(16).slice(2)}`,\n    received_at: new Date().toISOString(),\n    required_missing: missing,\n    normalized,\n    original: input\n  }\n}];"
      },
      "id": "c2d2041a-3125-4462-bb4e-b3500d5b3eef",
      "name": "Normalize payload and validate",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        -220,
        40
      ]
    },
    {
      "parameters": {
        "method": "POST",
        "url": "={{ $env.CRM_PAYMENT_WEBHOOK_URL || \"https://YOUR_CRM_WEBHOOK_URL/payments/update\" }}",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "Authorization",
              "value": "=Bearer {{$env.CRM_API_TOKEN || \"REPLACE_CRM_TOKEN\"}}"
            },
            {
              "name": "Content-Type",
              "value": "application/json"
            }
          ]
        },
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={{ JSON.stringify({payment_id:$json.normalized.object_id,status:$json.normalized.status,paid:$json.normalized.paid,amount:$json.normalized.amount,currency:$json.normalized.currency,order_id:$json.normalized.order_id,customer_email:$json.normalized.customer_email,received_at:$json.received_at}) }}",
        "options": {
          "timeout": 15000
        }
      },
      "id": "643fba46-bb28-445f-93d2-30628628bcb3",
      "name": "Call external API - fill credentials",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        100,
        40
      ],
      "continueOnFail": true
    },
    {
      "parameters": {
        "jsCode": "return [{ json: {\n  ok: true,\n  template: $json.template || 'nodbot-template',\n  message: 'Шаблон выполнился. Проверьте ответ внешнего сервиса и добавьте обработку ошибок перед запуском.',\n  received_at: new Date().toISOString(),\n  result: $json\n}}];"
      },
      "id": "6b68e882-c796-47d2-bf26-89a9e3bfdf70",
      "name": "Build safe response",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        420,
        40
      ]
    },
    {
      "parameters": {
        "respondWith": "json",
        "responseBody": "={{ $json }}",
        "options": {}
      },
      "id": "7ef72793-f40f-408a-a065-efeb2ffc4ebc",
      "name": "Respond to Webhook",
      "type": "n8n-nodes-base.respondToWebhook",
      "typeVersion": 1.1,
      "position": [
        720,
        40
      ]
    }
  ],
  "connections": {
    "Webhook input": {
      "main": [
        [
          {
            "node": "Normalize payload and validate",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Normalize payload and validate": {
      "main": [
        [
          {
            "node": "Call external API - fill credentials",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Call external API - fill credentials": {
      "main": [
        [
          {
            "node": "Build safe response",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Build safe response": {
      "main": [
        [
          {
            "node": "Respond to Webhook",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "pinData": {
    "Webhook input": [
      {
        "json": {
          "body": {
            "event": "payment.succeeded",
            "object": {
              "id": "2f37a1",
              "status": "succeeded",
              "paid": true,
              "amount": {
                "value": "4900.00",
                "currency": "RUB"
              },
              "metadata": {
                "order_id": "ORD-1001"
              },
              "receipt": {
                "customer": {
                  "email": "buyer@example.ru"
                }
              }
            }
          }
        }
      }
    ]
  },
  "settings": {
    "executionOrder": "v1"
  },
  "staticData": null,
  "tags": [
    {
      "name": "nodbot"
    },
    {
      "name": "russia"
    },
    {
      "name": "template"
    }
  ],
  "triggerCount": 1,
  "updatedAt": "2026-05-30T00:00:00.000Z",
  "versionId": "8371504d-6e0d-4e82-a6cd-43757ef778ce",
  "meta": {
    "nodbot_phase13_note": "Платёжные webhooks могут приходить повторно. Храните payment_id и не выполняйте бизнес-действие дважды.",
    "nodbot_phase13_generic_placeholder_cleaned": true
  },
  "notes": "Problem/Solution-мануал по обработке платежей ЮKassa через n8n: webhook payment.succeeded, подтверждение 200 OK, проверка статуса платежа, идемпотентность, обновление CRM и защита от повторных событий. Replace credentials, endpoints, IDs and business rules before production."
}