{
  "name": "School 2 · GetCourse payment → access + welcome sequence + Google Sheets row",
  "nodes": [
    {
      "id": "1afdc50d-8134-492d-aabd-853b2cda8ca8",
      "name": "About",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        -620,
        -200
      ],
      "parameters": {
        "content": "## GetCourse payment → access + welcome sequence + Google Sheets row\nDemo recipe for the portfolio, not a client project.\n\n**RU.** Оплаченный заказ в GetCourse запускает выдачу доступа, приветственную цепочку из трёх писем и строку в таблице. Повторный вызов по тому же заказу ничего не дублирует.\n**EN.** A paid GetCourse order grants access, starts a three-email welcome sequence and adds a sheet row. A repeated call for the same order changes nothing.\n\n**Setup**\n1. GetCourse → Processes → new process for Orders, condition: status \"Completed\". Add the operation \"Call URL\" with:\n`https://YOUR_N8N/webhook/school-payment?order={object.number}&email={object.user.email}&name={object.user.first_name}&phone={object.user.phone}&offer={object.positions}&sum={object.cost_money_value}`\n2. Replace YOUR_ACCOUNT and YOUR_GETCOURSE_API_KEY (Settings → API) in \"Add to GetCourse group\", set the group name.\n3. Replace YOUR_BOT_TOKEN and the private chat ID in \"One-time chat invite\" (the bot must be an admin there).\n4. Connect Google Sheets (columns: date, order, email, name, phone, offer, sum) and SMTP for the emails.\n\nMax Igoshev, igoshevmax@gmail.com, igoshevmax.com",
        "width": 540,
        "height": 560
      }
    },
    {
      "id": "7e368fb2-dbb1-40a0-ab28-980bee108aa8",
      "name": "GetCourse calls URL",
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 2,
      "position": [
        0,
        0
      ],
      "webhookId": "27b26ae2-ef70-46bb-a36c-3c7ed30ec65d",
      "parameters": {
        "httpMethod": "GET",
        "path": "school-payment",
        "responseMode": "onReceived",
        "options": {}
      }
    },
    {
      "id": "9d591a8f-9ce1-475d-ab48-3f7e6d58fa24",
      "name": "Clean order",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        240,
        0
      ],
      "parameters": {
        "jsCode": "const q = $json.query ?? {};\nconst order = String(q.order ?? '').trim();\nif (!order) return [];\nreturn [{ json: {\n  date: new Date().toISOString(),\n  order,\n  email: String(q.email ?? '').trim().toLowerCase(),\n  name: String(q.name ?? '').trim() || 'студент',\n  phone: String(q.phone ?? '').trim(),\n  offer: String(q.offer ?? '').trim(),\n  sum: String(q.sum ?? '').trim(),\n} }];"
      }
    },
    {
      "id": "c2caed29-22e1-4d68-b13e-373f65bee668",
      "name": "Order already saved?",
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 4.5,
      "position": [
        480,
        0
      ],
      "parameters": {
        "operation": "read",
        "documentId": {
          "__rl": true,
          "mode": "list",
          "value": ""
        },
        "sheetName": {
          "__rl": true,
          "mode": "list",
          "value": ""
        },
        "filtersUI": {
          "values": [
            {
              "lookupColumn": "order",
              "lookupValue": "={{ $json.order }}"
            }
          ]
        },
        "options": {}
      },
      "alwaysOutputData": true
    },
    {
      "id": "4508eb82-dbf2-4618-9fcf-6be8677a6cb2",
      "name": "New order?",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2,
      "position": [
        720,
        0
      ],
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "loose"
          },
          "conditions": [
            {
              "id": "20b89ad1-31a2-46b6-a96b-f707cc9a0384",
              "leftValue": "={{ !$json.order }}",
              "rightValue": "",
              "operator": {
                "type": "boolean",
                "operation": "true",
                "singleValue": true
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      }
    },
    {
      "id": "097fa2a2-7fab-41a0-bc82-fce33d6e29d9",
      "name": "Add row to sheet",
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 4.5,
      "position": [
        960,
        -20
      ],
      "parameters": {
        "operation": "append",
        "documentId": {
          "__rl": true,
          "mode": "list",
          "value": ""
        },
        "sheetName": {
          "__rl": true,
          "mode": "list",
          "value": ""
        },
        "columns": {
          "mappingMode": "defineBelow",
          "value": {
            "date": "={{ $('Clean order').first().json.date }}",
            "order": "={{ $('Clean order').first().json.order }}",
            "email": "={{ $('Clean order').first().json.email }}",
            "name": "={{ $('Clean order').first().json.name }}",
            "phone": "={{ $('Clean order').first().json.phone }}",
            "offer": "={{ $('Clean order').first().json.offer }}",
            "sum": "={{ $('Clean order').first().json.sum }}"
          },
          "matchingColumns": []
        },
        "options": {}
      }
    },
    {
      "id": "6c2ff52b-8cf2-4071-9a03-f91f6f84993a",
      "name": "Add to GetCourse group",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        1200,
        -20
      ],
      "parameters": {
        "options": {},
        "method": "POST",
        "url": "https://YOUR_ACCOUNT.getcourse.ru/pl/api/users",
        "sendBody": true,
        "contentType": "form-urlencoded",
        "bodyParameters": {
          "parameters": [
            {
              "name": "action",
              "value": "add"
            },
            {
              "name": "key",
              "value": "YOUR_GETCOURSE_API_KEY"
            },
            {
              "name": "params",
              "value": "={{ Buffer.from(JSON.stringify({ user: { email: $('Clean order').first().json.email, first_name: $('Clean order').first().json.name, phone: $('Clean order').first().json.phone, group_name: ['Оплатили: ' + $('Clean order').first().json.offer] }, system: { refresh_if_exists: 1 } })).toString('base64') }}"
            }
          ]
        }
      }
    },
    {
      "id": "6fc4609f-a375-4004-8273-e7be3289bd0a",
      "name": "One-time chat invite",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        1440,
        -20
      ],
      "parameters": {
        "options": {},
        "method": "POST",
        "url": "https://api.telegram.org/botYOUR_BOT_TOKEN/createChatInviteLink",
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={{ JSON.stringify({ chat_id: 'YOUR_PRIVATE_CHAT_ID', name: 'Заказ ' + $('Clean order').first().json.order, member_limit: 1 }) }}"
      }
    },
    {
      "id": "9e65a427-229b-48a6-8ff8-40e6ae37747a",
      "name": "Welcome email 1",
      "type": "n8n-nodes-base.emailSend",
      "typeVersion": 2.1,
      "position": [
        1680,
        -20
      ],
      "webhookId": "41a18270-94de-4c05-a1c3-d306eb545b20",
      "parameters": {
        "fromEmail": "school@example.com",
        "toEmail": "={{ $('Clean order').first().json.email }}",
        "subject": "=Доступ открыт: {{ $('Clean order').first().json.offer }}",
        "emailFormat": "text",
        "text": "=Здравствуйте, {{ $('Clean order').first().json.name }}.\n\nОплата прошла, доступ к курсу открыт в личном кабинете GetCourse под этой почтой.\nСсылка в закрытый чат курса, она сработает один раз: {{ $json.result.invite_link }}\n\nНачните с первого урока, он короткий.",
        "options": {}
      }
    },
    {
      "id": "2a28d992-5bbe-446a-b6c1-80c60b683f27",
      "name": "Wait 1 day",
      "type": "n8n-nodes-base.wait",
      "typeVersion": 1.1,
      "position": [
        1920,
        -20
      ],
      "webhookId": "8885e3fa-d996-47e7-9b2c-8f034eb31ddf",
      "parameters": {
        "amount": 1,
        "unit": "days"
      }
    },
    {
      "id": "79b74723-10b2-4d9d-8616-60c40b907c0f",
      "name": "Welcome email 2",
      "type": "n8n-nodes-base.emailSend",
      "typeVersion": 2.1,
      "position": [
        2160,
        -20
      ],
      "webhookId": "14f4a523-1116-4a26-a4c7-2c228e3b48b1",
      "parameters": {
        "fromEmail": "school@example.com",
        "toEmail": "={{ $('Clean order').first().json.email }}",
        "subject": "=Как пройти первую неделю",
        "emailFormat": "text",
        "text": "=Здравствуйте, {{ $('Clean order').first().json.name }}.\n\nКак устроен курс: уроки открываются по порядку, домашнее задание сдаётся под уроком, куратор отвечает в кабинете.\nЕсли что-то не открывается, ответьте на это письмо.",
        "options": {}
      }
    },
    {
      "id": "07ae9f90-2c19-4f80-9e43-f0776727c56c",
      "name": "Wait 2 days",
      "type": "n8n-nodes-base.wait",
      "typeVersion": 1.1,
      "position": [
        2400,
        -20
      ],
      "webhookId": "a299488a-3f43-4128-9e79-72cec0559273",
      "parameters": {
        "amount": 2,
        "unit": "days"
      }
    },
    {
      "id": "d8b4cd58-c614-404e-ac95-506060974fb9",
      "name": "Welcome email 3",
      "type": "n8n-nodes-base.emailSend",
      "typeVersion": 2.1,
      "position": [
        2640,
        -20
      ],
      "webhookId": "f623c6c4-0c34-49aa-8e2b-917dce6a95b0",
      "parameters": {
        "fromEmail": "school@example.com",
        "toEmail": "={{ $('Clean order').first().json.email }}",
        "subject": "=Как идут первые уроки?",
        "emailFormat": "text",
        "text": "=Здравствуйте, {{ $('Clean order').first().json.name }}.\n\nПрошло три дня. Если первый урок ещё не открыт, сейчас удобный момент: он займёт немного времени.\nВопросы по программе можно задать в чате курса.",
        "options": {}
      }
    }
  ],
  "connections": {
    "GetCourse calls URL": {
      "main": [
        [
          {
            "node": "Clean order",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Clean order": {
      "main": [
        [
          {
            "node": "Order already saved?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Order already saved?": {
      "main": [
        [
          {
            "node": "New order?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "New order?": {
      "main": [
        [
          {
            "node": "Add row to sheet",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Add row to sheet": {
      "main": [
        [
          {
            "node": "Add to GetCourse group",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Add to GetCourse group": {
      "main": [
        [
          {
            "node": "One-time chat invite",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "One-time chat invite": {
      "main": [
        [
          {
            "node": "Welcome email 1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Welcome email 1": {
      "main": [
        [
          {
            "node": "Wait 1 day",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Wait 1 day": {
      "main": [
        [
          {
            "node": "Welcome email 2",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Welcome email 2": {
      "main": [
        [
          {
            "node": "Wait 2 days",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Wait 2 days": {
      "main": [
        [
          {
            "node": "Welcome email 3",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "pinData": {},
  "settings": {
    "executionOrder": "v1"
  },
  "active": false,
  "tags": []
}
