8
n8n 中文网amn8n.com

Yookassa支付处理

高级

这是一个Finance, AI领域的自动化工作流,包含 44 个节点。主要使用 If, Set, Code, Sort, Switch 等节点,结合人工智能技术实现智能自动化。 使用YooKassa和Google表格进行支付处理与订单跟踪

前置要求
  • HTTP Webhook 端点(n8n 会自动生成)
  • 可能需要目标 API 的认证凭证
  • Google Sheets API 凭证
工作流预览
可视化展示节点连接关系,支持缩放和平移
导出工作流
复制以下 JSON 配置到 n8n 导入,即可使用此工作流
{
  "id": "HHoQmMSal4U1i65J",
  "meta": {
    "instanceId": "673dd365761c86615255caaaae908ad0f2b40ed6e6f64e1be5631254544e65ca"
  },
  "name": "Yookassa",
  "tags": [],
  "nodes": [
    {
      "id": "0ccb2fd9-139a-4234-9e2b-feabf63563c5",
      "name": "响应产品",
      "type": "n8n-nodes-base.respondToWebhook",
      "position": [
        560,
        40
      ],
      "parameters": {
        "options": {},
        "respondWith": "allIncomingItems"
      },
      "retryOnFail": false,
      "typeVersion": 1.3
    },
    {
      "id": "cabb25e6-9683-4a4f-9832-7a7630a011bf",
      "name": "便签5",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -180,
        -40
      ],
      "parameters": {
        "color": 5,
        "width": 1040,
        "height": 400,
        "content": "# 获取产品"
      },
      "typeVersion": 1
    },
    {
      "id": "88b5245c-bce9-44e7-beb7-172137d63d61",
      "name": "获取产品",
      "type": "n8n-nodes-base.webhook",
      "position": [
        -120,
        80
      ],
      "webhookId": "05a39af8-d82c-4807-a156-0f2631886199",
      "parameters": {
        "path": "products",
        "options": {},
        "responseMode": "responseNode"
      },
      "typeVersion": 2
    },
    {
      "id": "5a218b21-d7a7-4f4f-9883-6db1a994513b",
      "name": "按价格排序",
      "type": "n8n-nodes-base.sort",
      "position": [
        340,
        40
      ],
      "parameters": {
        "options": {},
        "sortFieldsUi": {
          "sortField": [
            {
              "fieldName": "price"
            }
          ]
        }
      },
      "typeVersion": 1
    },
    {
      "id": "d3265cbe-dc41-49ee-9cdd-d265efefaa0c",
      "name": "错误处理(获取产品)",
      "type": "n8n-nodes-base.respondToWebhook",
      "position": [
        560,
        200
      ],
      "parameters": {
        "options": {
          "responseCode": 400
        },
        "respondWith": "noData"
      },
      "typeVersion": 1.3
    },
    {
      "id": "14fad20c-566a-4ce3-a4c3-a28922f2ceb1",
      "name": "获取产品",
      "type": "n8n-nodes-base.googleSheets",
      "onError": "continueErrorOutput",
      "maxTries": 2,
      "position": [
        680,
        500
      ],
      "parameters": {
        "options": {},
        "filtersUI": {
          "values": [
            {
              "lookupValue": "={{ $json.product_id }}",
              "lookupColumn": "product_id"
            }
          ]
        },
        "sheetName": {
          "__rl": true,
          "mode": "list",
          "value": "gid=0",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1OkaZTGWiTvX_qiQbRcMJKxUjXv0t6-IQtGm5crY0CXE/edit#gid=0",
          "cachedResultName": "products"
        },
        "documentId": {
          "__rl": true,
          "mode": "list",
          "value": "1OkaZTGWiTvX_qiQbRcMJKxUjXv0t6-IQtGm5crY0CXE",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1OkaZTGWiTvX_qiQbRcMJKxUjXv0t6-IQtGm5crY0CXE/edit?usp=drivesdk",
          "cachedResultName": "Yookassa"
        }
      },
      "credentials": {
        "googleSheetsOAuth2Api": {
          "id": "Yh4hxJEg7r5FU0cs",
          "name": "Google Sheets account"
        }
      },
      "retryOnFail": true,
      "typeVersion": 4.6
    },
    {
      "id": "5b619423-3a66-4ea8-bdc4-da49c5c55295",
      "name": "YooKassa 请求",
      "type": "n8n-nodes-base.httpRequest",
      "onError": "continueErrorOutput",
      "position": [
        1280,
        500
      ],
      "parameters": {
        "url": "https://api.yookassa.ru/v3/payments",
        "method": "POST",
        "options": {},
        "jsonBody": "={\n    \"amount\": {\n        \"value\": \"{{ $('Get Product').item.json.price }}.00\",\n        \"currency\": \"RUB\"\n    },\n    \"capture\": true,\n    \"metadata\": {\"email\": \"{{ $('Payment').item.json.body.email }}\"},\n    \"confirmation\": {\n        \"type\": \"redirect\",\n        \"locale\": \"ru_RU\",\n        \"return_url\": \"{{ $('Payment').item.json.body.return_url }}\"\n    },\n    \"description\": \"{{ $('Get Product').item.json.title.replace(/\"/g, '\\\\\"') }}\",\n    \"receipt\": {\n        \"email\": \"{{ $('Payment').item.json.body.email }}\",\n        \"items\": [\n            {\n                \"description\": \"{{ $('Get Product').item.json.title.replace(/\"/g, '\\\\\"') }}\",\n                \"quantity\": \"1\",\n                \"amount\": {\n                    \"value\": \"{{ $('Get Product').item.json.price }}.00\",\n                    \"currency\": \"RUB\"\n                },\n                \"vat_code\": 1\n            }\n        ]\n    }\n} ",
        "sendBody": true,
        "sendHeaders": true,
        "specifyBody": "json",
        "authentication": "genericCredentialType",
        "genericAuthType": "httpBasicAuth",
        "headerParameters": {
          "parameters": [
            {
              "name": "Idempotence-Key",
              "value": "={{ $json.data }}"
            },
            {
              "name": "Content-Type",
              "value": "application/json"
            }
          ]
        }
      },
      "credentials": {
        "httpBasicAuth": {
          "id": "iQsXBuezh0M2AbDr",
          "name": "Yookassa credential"
        }
      },
      "typeVersion": 4.2
    },
    {
      "id": "a56d477f-af9b-40a1-ba6c-5d28d11b4f8d",
      "name": "保存订单",
      "type": "n8n-nodes-base.googleSheets",
      "onError": "continueErrorOutput",
      "maxTries": 2,
      "position": [
        1480,
        500
      ],
      "parameters": {
        "columns": {
          "value": {
            "id": "={{ $json.id }}",
            "email": "={{ $json.metadata.email }}",
            "product_id": "={{ $('Get product_id').item.json.product_id }}",
            "order_datetime": "={{ $json.created_at }}"
          },
          "schema": [
            {
              "id": "id",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "id",
              "defaultMatch": true,
              "canBeUsedToMatch": true
            },
            {
              "id": "email",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "email",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "product_id",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "product_id",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "order_datetime",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "order_datetime",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            }
          ],
          "mappingMode": "defineBelow",
          "matchingColumns": [
            "id"
          ],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "options": {},
        "operation": "append",
        "sheetName": {
          "__rl": true,
          "mode": "list",
          "value": 1924940864,
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1OkaZTGWiTvX_qiQbRcMJKxUjXv0t6-IQtGm5crY0CXE/edit#gid=1924940864",
          "cachedResultName": "orders"
        },
        "documentId": {
          "__rl": true,
          "mode": "list",
          "value": "1OkaZTGWiTvX_qiQbRcMJKxUjXv0t6-IQtGm5crY0CXE",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1OkaZTGWiTvX_qiQbRcMJKxUjXv0t6-IQtGm5crY0CXE/edit?usp=drivesdk",
          "cachedResultName": "Yookassa"
        }
      },
      "credentials": {
        "googleSheetsOAuth2Api": {
          "id": "Yh4hxJEg7r5FU0cs",
          "name": "Google Sheets account"
        }
      },
      "retryOnFail": true,
      "typeVersion": 4.6
    },
    {
      "id": "241307e3-9536-404c-aa27-6e21bb5424c0",
      "name": "便签",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -180,
        400
      ],
      "parameters": {
        "color": 5,
        "width": 2140,
        "height": 480,
        "content": "# 支付"
      },
      "typeVersion": 1
    },
    {
      "id": "830a9d53-1e6a-4293-8440-7aa73edbd2f8",
      "name": "支付",
      "type": "n8n-nodes-base.webhook",
      "position": [
        -120,
        600
      ],
      "webhookId": "2b502106-9efc-4991-b9f7-32adc790370a",
      "parameters": {
        "path": "payment",
        "options": {
          "rawBody": true
        },
        "httpMethod": "POST",
        "responseMode": "responseNode"
      },
      "typeVersion": 2
    },
    {
      "id": "7dedf78b-414f-421f-97af-6e5ab87fdec4",
      "name": "检查请求值",
      "type": "n8n-nodes-base.if",
      "position": [
        80,
        600
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 2,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "2728d695-e20d-41f0-9357-14e027c756ce",
              "operator": {
                "type": "string",
                "operation": "exists",
                "singleValue": true
              },
              "leftValue": "={{ $json.body.product_id }}",
              "rightValue": ""
            },
            {
              "id": "00a85085-1715-44d6-84ec-7cc10c16c046",
              "operator": {
                "type": "string",
                "operation": "exists",
                "singleValue": true
              },
              "leftValue": "={{ $json.body.email }}",
              "rightValue": ""
            },
            {
              "id": "8fa8951d-d1df-46f1-88da-cfe0680af42c",
              "operator": {
                "type": "string",
                "operation": "exists",
                "singleValue": true
              },
              "leftValue": "={{ $json.body.return_url }}",
              "rightValue": ""
            }
          ]
        }
      },
      "typeVersion": 2.2
    },
    {
      "id": "84c0764f-6496-4047-bd34-593b722560f1",
      "name": "邮箱验证",
      "type": "n8n-nodes-base.if",
      "position": [
        280,
        520
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 2,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "d70fb2cf-7e73-4853-bbeb-e310eb656c64",
              "operator": {
                "type": "string",
                "operation": "regex"
              },
              "leftValue": "={{ $json.body.email }}",
              "rightValue": "^[^\\s@]+@[^\\s@]+\\.[^\\s@]+$"
            }
          ]
        }
      },
      "typeVersion": 2.2
    },
    {
      "id": "9090fbcf-96c9-4f53-b13a-0fa471435052",
      "name": "获取产品ID",
      "type": "n8n-nodes-base.set",
      "position": [
        480,
        500
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "b8ecf70e-20c0-4513-a168-6cd1f2d5f3a6",
              "name": "product_id",
              "type": "string",
              "value": "={{ $json.body.product_id }}"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "ad49466c-6ad4-411c-9c67-8a3e066d5359",
      "name": "检查产品ID",
      "type": "n8n-nodes-base.if",
      "position": [
        880,
        500
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 2,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "a8274ea7-f8e8-4ed5-9f40-5e3cc18ed852",
              "operator": {
                "type": "object",
                "operation": "exists",
                "singleValue": true
              },
              "leftValue": "={{ $input.item.json }}",
              "rightValue": ""
            }
          ]
        }
      },
      "typeVersion": 2.2
    },
    {
      "id": "b1bca082-6fbe-42e8-9602-4a31c86a82c6",
      "name": "错误处理(产品ID)",
      "type": "n8n-nodes-base.respondToWebhook",
      "position": [
        1080,
        680
      ],
      "parameters": {
        "options": {
          "responseCode": 404
        },
        "respondWith": "text",
        "responseBody": "product_id not found"
      },
      "typeVersion": 1.3
    },
    {
      "id": "913b424e-fceb-4435-820b-59efe11083a3",
      "name": "幂等密钥生成",
      "type": "n8n-nodes-base.code",
      "position": [
        1080,
        500
      ],
      "parameters": {
        "jsCode": "const template = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx';\n  let uuid = '';\n\n  for (let i = 0; i < template.length; i++) {\n    const char = template[i];\n\n    if (char === 'x' || char === 'y') {\n      const rand = Math.floor(Math.random() * 16);\n      let value;\n\n      if (char === 'x') {\n        value = rand;\n      } else {\n        value = (rand & 0x3) | 0x8;\n      }\n\n      uuid += value.toString(16);\n    } else {\n      uuid += char;\n    }\n  }\n\n  return {\n    data: uuid\n  }"
      },
      "typeVersion": 2
    },
    {
      "id": "f5bc3ad6-8599-4ed1-a501-bc2c1507fa73",
      "name": "错误处理",
      "type": "n8n-nodes-base.respondToWebhook",
      "position": [
        480,
        680
      ],
      "parameters": {
        "options": {
          "responseCode": 400
        },
        "respondWith": "text",
        "responseBody": "Bad request"
      },
      "typeVersion": 1.3
    },
    {
      "id": "4b6d62b9-3ac3-4cc8-944a-64372a8aaa80",
      "name": "错误处理(yookassa)",
      "type": "n8n-nodes-base.respondToWebhook",
      "position": [
        1480,
        680
      ],
      "parameters": {
        "options": {
          "responseCode": 400
        },
        "respondWith": "text",
        "responseBody": "Bad request"
      },
      "typeVersion": 1.3
    },
    {
      "id": "12568776-4885-46ac-a831-35d56207bb95",
      "name": "错误处理(保存订单)",
      "type": "n8n-nodes-base.respondToWebhook",
      "position": [
        1700,
        680
      ],
      "parameters": {
        "options": {
          "responseCode": 400
        },
        "respondWith": "noData"
      },
      "typeVersion": 1.3
    },
    {
      "id": "d1032cdb-c456-45b0-a534-14ed920228b6",
      "name": "响应支付",
      "type": "n8n-nodes-base.respondToWebhook",
      "position": [
        1700,
        500
      ],
      "parameters": {
        "options": {
          "responseCode": 200
        },
        "respondWith": "json",
        "responseBody": "={{ {confirmation_url:$('YooKassa Request').item.json.confirmation.confirmation_url} }}"
      },
      "typeVersion": 1.3
    },
    {
      "id": "52b428e6-521c-4b22-b41e-ed96971f5ecf",
      "name": "错误处理(获取产品)_1",
      "type": "n8n-nodes-base.respondToWebhook",
      "position": [
        880,
        680
      ],
      "parameters": {
        "options": {
          "responseCode": 400
        },
        "respondWith": "noData"
      },
      "typeVersion": 1.3
    },
    {
      "id": "46193f6f-577b-4872-a11c-22b7e2f1ff61",
      "name": "获取订单",
      "type": "n8n-nodes-base.googleSheets",
      "onError": "continueErrorOutput",
      "maxTries": 2,
      "position": [
        480,
        1000
      ],
      "parameters": {
        "options": {},
        "filtersUI": {
          "values": [
            {
              "lookupValue": "={{ $json.body.object.id }}",
              "lookupColumn": "id"
            }
          ]
        },
        "sheetName": {
          "__rl": true,
          "mode": "list",
          "value": 1924940864,
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1OkaZTGWiTvX_qiQbRcMJKxUjXv0t6-IQtGm5crY0CXE/edit#gid=1924940864",
          "cachedResultName": "orders"
        },
        "documentId": {
          "__rl": true,
          "mode": "list",
          "value": "1OkaZTGWiTvX_qiQbRcMJKxUjXv0t6-IQtGm5crY0CXE",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1OkaZTGWiTvX_qiQbRcMJKxUjXv0t6-IQtGm5crY0CXE/edit?usp=drivesdk",
          "cachedResultName": "Yookassa"
        }
      },
      "credentials": {
        "googleSheetsOAuth2Api": {
          "id": "Yh4hxJEg7r5FU0cs",
          "name": "Google Sheets account"
        }
      },
      "executeOnce": false,
      "retryOnFail": true,
      "typeVersion": 4.6
    },
    {
      "id": "d5abfe86-2462-4299-a84f-18006879ba81",
      "name": "保存交易",
      "type": "n8n-nodes-base.googleSheets",
      "onError": "continueRegularOutput",
      "maxTries": 2,
      "position": [
        880,
        1000
      ],
      "parameters": {
        "columns": {
          "value": {
            "id": "={{ $('Handle YooKassa webhook').item.json.body.object.id }}",
            "email": "={{ $('Handle YooKassa webhook').item.json.body.object.metadata.email }}",
            "product_id": "={{ $json.product_id }}",
            "transaction_status": "succeeded",
            "transaction_datetime": "={{ $('Handle YooKassa webhook').item.json.body.object.captured_at }}"
          },
          "schema": [
            {
              "id": "id",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "id",
              "defaultMatch": true,
              "canBeUsedToMatch": true
            },
            {
              "id": "email",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "email",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "product_id",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "product_id",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "transaction_datetime",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "transaction_datetime",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "transaction_status",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "transaction_status",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            }
          ],
          "mappingMode": "defineBelow",
          "matchingColumns": [
            "id"
          ],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "options": {},
        "operation": "append",
        "sheetName": {
          "__rl": true,
          "mode": "list",
          "value": 1976749998,
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1OkaZTGWiTvX_qiQbRcMJKxUjXv0t6-IQtGm5crY0CXE/edit#gid=1976749998",
          "cachedResultName": "transactions"
        },
        "documentId": {
          "__rl": true,
          "mode": "list",
          "value": "1OkaZTGWiTvX_qiQbRcMJKxUjXv0t6-IQtGm5crY0CXE",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1OkaZTGWiTvX_qiQbRcMJKxUjXv0t6-IQtGm5crY0CXE/edit?usp=drivesdk",
          "cachedResultName": "Yookassa"
        }
      },
      "credentials": {
        "googleSheetsOAuth2Api": {
          "id": "Yh4hxJEg7r5FU0cs",
          "name": "Google Sheets account"
        }
      },
      "retryOnFail": true,
      "typeVersion": 4.6
    },
    {
      "id": "081a8ec1-01ba-4ce6-811d-d527060e73f6",
      "name": "便签1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -180,
        920
      ],
      "parameters": {
        "color": 5,
        "width": 1520,
        "height": 620,
        "content": "# Webhook"
      },
      "typeVersion": 1
    },
    {
      "id": "4c7ad01d-314e-463a-b499-e05a4628f8d9",
      "name": "处理事件",
      "type": "n8n-nodes-base.switch",
      "position": [
        80,
        1180
      ],
      "parameters": {
        "rules": {
          "values": [
            {
              "outputKey": "payment.succeeded",
              "conditions": {
                "options": {
                  "version": 2,
                  "leftValue": "",
                  "caseSensitive": false,
                  "typeValidation": "strict"
                },
                "combinator": "and",
                "conditions": [
                  {
                    "id": "71f1d0c7-e46c-40e5-8d49-2bf17c5a8582",
                    "operator": {
                      "type": "string",
                      "operation": "equals"
                    },
                    "leftValue": "={{ $json.body.event }}",
                    "rightValue": "payment.succeeded"
                  }
                ]
              },
              "renameOutput": true
            },
            {
              "outputKey": "refund.succeeded",
              "conditions": {
                "options": {
                  "version": 2,
                  "leftValue": "",
                  "caseSensitive": false,
                  "typeValidation": "strict"
                },
                "combinator": "and",
                "conditions": [
                  {
                    "id": "bec8e08e-83fd-49f0-968a-ada7772e3a46",
                    "operator": {
                      "name": "filter.operator.equals",
                      "type": "string",
                      "operation": "equals"
                    },
                    "leftValue": "={{ $json.body.event }}",
                    "rightValue": "refund.succeeded"
                  }
                ]
              },
              "renameOutput": true
            }
          ]
        },
        "options": {
          "ignoreCase": true
        }
      },
      "typeVersion": 3.2
    },
    {
      "id": "5eb6b856-c62b-4781-a7cd-728f9e43b0aa",
      "name": "验证元数据",
      "type": "n8n-nodes-base.if",
      "position": [
        280,
        1000
      ],
      "parameters": {
        "options": {
          "ignoreCase": true
        },
        "conditions": {
          "options": {
            "version": 2,
            "leftValue": "",
            "caseSensitive": false,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "a8f8592e-683e-463b-9bd4-9d15eb685e46",
              "operator": {
                "type": "string",
                "operation": "exists",
                "singleValue": true
              },
              "leftValue": "={{ $json.body.object.id }}",
              "rightValue": ""
            },
            {
              "id": "3115f67e-c0ea-4ef7-9eb7-67a1e628b038",
              "operator": {
                "type": "string",
                "operation": "exists",
                "singleValue": true
              },
              "leftValue": "={{ $json.body.object.metadata.email }}",
              "rightValue": ""
            }
          ]
        }
      },
      "typeVersion": 2.2
    },
    {
      "id": "e0670c19-ac44-4d10-ae8f-8f324f209b0c",
      "name": "检查订单",
      "type": "n8n-nodes-base.if",
      "position": [
        680,
        1000
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 2,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "9c2238c4-c3ec-4d0c-8892-86169bc8fdef",
              "operator": {
                "type": "object",
                "operation": "exists",
                "singleValue": true
              },
              "leftValue": "={{ $input.item.json }}",
              "rightValue": ""
            }
          ]
        }
      },
      "typeVersion": 2.2
    },
    {
      "id": "f5436549-a2c8-4b1c-bc09-1a7902afe8be",
      "name": "验证元数据_",
      "type": "n8n-nodes-base.if",
      "position": [
        280,
        1360
      ],
      "parameters": {
        "options": {
          "ignoreCase": true
        },
        "conditions": {
          "options": {
            "version": 2,
            "leftValue": "",
            "caseSensitive": false,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "a8f8592e-683e-463b-9bd4-9d15eb685e46",
              "operator": {
                "type": "string",
                "operation": "exists",
                "singleValue": true
              },
              "leftValue": "={{ $json.body.object.id }}",
              "rightValue": ""
            }
          ]
        }
      },
      "typeVersion": 2.2
    },
    {
      "id": "e2f00535-bf29-43b5-9eac-a8e5ee6c3ab9",
      "name": "获取交易",
      "type": "n8n-nodes-base.googleSheets",
      "onError": "continueErrorOutput",
      "maxTries": 2,
      "position": [
        480,
        1360
      ],
      "parameters": {
        "options": {},
        "filtersUI": {
          "values": [
            {
              "lookupValue": "={{ $json.body.object.id }}",
              "lookupColumn": "id"
            }
          ]
        },
        "sheetName": {
          "__rl": true,
          "mode": "list",
          "value": 1976749998,
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1OkaZTGWiTvX_qiQbRcMJKxUjXv0t6-IQtGm5crY0CXE/edit#gid=1976749998",
          "cachedResultName": "transactions"
        },
        "documentId": {
          "__rl": true,
          "mode": "list",
          "value": "1OkaZTGWiTvX_qiQbRcMJKxUjXv0t6-IQtGm5crY0CXE",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1OkaZTGWiTvX_qiQbRcMJKxUjXv0t6-IQtGm5crY0CXE/edit?usp=drivesdk",
          "cachedResultName": "Yookassa"
        }
      },
      "credentials": {
        "googleSheetsOAuth2Api": {
          "id": "Yh4hxJEg7r5FU0cs",
          "name": "Google Sheets account"
        }
      },
      "retryOnFail": true,
      "typeVersion": 4.6
    },
    {
      "id": "24016b43-795b-4c7b-ad9b-9d9d220cdeef",
      "name": "响应支付事件",
      "type": "n8n-nodes-base.respondToWebhook",
      "position": [
        1080,
        1000
      ],
      "parameters": {
        "options": {
          "responseCode": 200
        },
        "respondWith": "noData"
      },
      "typeVersion": 1.3
    },
    {
      "id": "64aa9833-522e-41b0-bb78-454d1122eb71",
      "name": "响应退款事件",
      "type": "n8n-nodes-base.respondToWebhook",
      "position": [
        1080,
        1360
      ],
      "parameters": {
        "options": {
          "responseCode": 200
        },
        "respondWith": "noData"
      },
      "typeVersion": 1.3
    },
    {
      "id": "984ac85d-5cae-4b57-8ce7-c61c6a12ceef",
      "name": "Webhook 错误处理",
      "type": "n8n-nodes-base.respondToWebhook",
      "position": [
        880,
        1180
      ],
      "parameters": {
        "options": {
          "responseCode": 200
        },
        "respondWith": "noData"
      },
      "typeVersion": 1.3
    },
    {
      "id": "cf3937fa-e0ee-4d5c-b9b9-4a575f895122",
      "name": "状态",
      "type": "n8n-nodes-base.webhook",
      "position": [
        -120,
        1720
      ],
      "webhookId": "d2cf1d05-671c-4308-8e08-3d054fc4944a",
      "parameters": {
        "path": "status/:id",
        "options": {},
        "responseMode": "responseNode"
      },
      "typeVersion": 2
    },
    {
      "id": "100e8560-78b2-40a8-ac20-82f8bb16138e",
      "name": "状态错误处理",
      "type": "n8n-nodes-base.respondToWebhook",
      "position": [
        480,
        1900
      ],
      "parameters": {
        "options": {
          "responseCode": "={{ $json.error.status }}"
        },
        "respondWith": "text",
        "responseBody": "={{ $json.error.message }}"
      },
      "typeVersion": 1.3
    },
    {
      "id": "e943aec6-962f-444d-811c-7975e12fad20",
      "name": "错误处理(检查请求)",
      "type": "n8n-nodes-base.respondToWebhook",
      "position": [
        280,
        1900
      ],
      "parameters": {
        "options": {
          "responseCode": 400
        },
        "respondWith": "noData"
      },
      "typeVersion": 1.3
    },
    {
      "id": "eb076097-abc8-46b3-b983-31918d96e284",
      "name": "检查请求值_1",
      "type": "n8n-nodes-base.if",
      "position": [
        80,
        1720
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 2,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "8fa8951d-d1df-46f1-88da-cfe0680af42c",
              "operator": {
                "type": "string",
                "operation": "exists",
                "singleValue": true
              },
              "leftValue": "={{ $json.params.id }}",
              "rightValue": ""
            }
          ]
        }
      },
      "typeVersion": 2.2
    },
    {
      "id": "4d1b91e0-0b28-4fea-a5ad-ee10a2f7c238",
      "name": "YooKassa 请求状态",
      "type": "n8n-nodes-base.httpRequest",
      "onError": "continueErrorOutput",
      "position": [
        280,
        1720
      ],
      "parameters": {
        "url": "=https://api.yookassa.ru/v3/payments/{{ $('Status').item.json.params.id }}",
        "options": {},
        "authentication": "genericCredentialType",
        "genericAuthType": "httpBasicAuth"
      },
      "credentials": {
        "httpBasicAuth": {
          "id": "iQsXBuezh0M2AbDr",
          "name": "Yookassa credential"
        }
      },
      "typeVersion": 4.2
    },
    {
      "id": "bf520270-5b44-48f7-a891-cf1394df64ad",
      "name": "响应状态",
      "type": "n8n-nodes-base.respondToWebhook",
      "position": [
        480,
        1720
      ],
      "parameters": {
        "options": {
          "responseCode": 200
        },
        "respondWith": "json",
        "responseBody": "={\n  \"id\": \"{{ $json.id }}\",\n  \"status\": \"{{ $json.status }}\",\n  \"description\": {{ $json.description }}\n} "
      },
      "typeVersion": 1.3
    },
    {
      "id": "b0f5195c-ffb7-4af6-8fbf-04eeeca5eafd",
      "name": "便签3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -180,
        1580
      ],
      "parameters": {
        "color": 5,
        "width": 960,
        "height": 500,
        "content": "# 状态"
      },
      "typeVersion": 1
    },
    {
      "id": "b3821373-2948-412e-b9e5-f52c5c707512",
      "name": "便签2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -920,
        -40
      ],
      "parameters": {
        "color": 5,
        "width": 700,
        "height": 2460,
        "content": "# 接受 YooKassa 支付并在 Google Sheets 中记录交易"
      },
      "typeVersion": 1
    },
    {
      "id": "966a7de7-af56-4780-afba-e55f1ac10375",
      "name": "获取产品_1",
      "type": "n8n-nodes-base.googleSheets",
      "onError": "continueErrorOutput",
      "maxTries": 2,
      "position": [
        100,
        80
      ],
      "parameters": {
        "options": {},
        "sheetName": {
          "__rl": true,
          "mode": "list",
          "value": "gid=0",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1OkaZTGWiTvX_qiQbRcMJKxUjXv0t6-IQtGm5crY0CXE/edit#gid=0",
          "cachedResultName": "products"
        },
        "documentId": {
          "__rl": true,
          "mode": "list",
          "value": "1OkaZTGWiTvX_qiQbRcMJKxUjXv0t6-IQtGm5crY0CXE",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1OkaZTGWiTvX_qiQbRcMJKxUjXv0t6-IQtGm5crY0CXE/edit?usp=drivesdk",
          "cachedResultName": "Yookassa"
        }
      },
      "credentials": {
        "googleSheetsOAuth2Api": {
          "id": "Yh4hxJEg7r5FU0cs",
          "name": "Google Sheets account"
        }
      },
      "retryOnFail": true,
      "typeVersion": 4.6
    },
    {
      "id": "f26e5f4f-39f8-4345-b2b3-bbae0740c9a7",
      "name": "处理 YooKassa webhook",
      "type": "n8n-nodes-base.webhook",
      "position": [
        -120,
        1180
      ],
      "webhookId": "d2cf1d05-671c-4308-8e08-3d054fc4944a",
      "parameters": {
        "path": "yoomoney",
        "options": {
          "rawBody": true
        },
        "httpMethod": "POST",
        "responseMode": "responseNode"
      },
      "typeVersion": 2
    },
    {
      "id": "d7c1eebc-3a26-49bf-ac98-ebe60a8127ca",
      "name": "更新退款状态",
      "type": "n8n-nodes-base.googleSheets",
      "onError": "continueRegularOutput",
      "maxTries": 2,
      "position": [
        880,
        1360
      ],
      "parameters": {
        "columns": {
          "value": {
            "id": "{{ $json.body.object.id }}",
            "transaction_status": "refund"
          },
          "schema": [
            {
              "id": "id",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "id",
              "defaultMatch": true,
              "canBeUsedToMatch": true
            },
            {
              "id": "email",
              "type": "string",
              "display": true,
              "removed": true,
              "required": false,
              "displayName": "email",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "product_id",
              "type": "string",
              "display": true,
              "removed": true,
              "required": false,
              "displayName": "product_id",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "transaction_datetime",
              "type": "string",
              "display": true,
              "removed": true,
              "required": false,
              "displayName": "transaction_datetime",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "transaction_status",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "transaction_status",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "row_number",
              "type": "string",
              "display": true,
              "removed": true,
              "readOnly": true,
              "required": false,
              "displayName": "row_number",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            }
          ],
          "mappingMode": "defineBelow",
          "matchingColumns": [
            "id"
          ],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "options": {},
        "operation": "update",
        "sheetName": {
          "__rl": true,
          "mode": "list",
          "value": 1976749998,
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1OkaZTGWiTvX_qiQbRcMJKxUjXv0t6-IQtGm5crY0CXE/edit#gid=1976749998",
          "cachedResultName": "transactions"
        },
        "documentId": {
          "__rl": true,
          "mode": "list",
          "value": "1OkaZTGWiTvX_qiQbRcMJKxUjXv0t6-IQtGm5crY0CXE",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1OkaZTGWiTvX_qiQbRcMJKxUjXv0t6-IQtGm5crY0CXE/edit?usp=drivesdk",
          "cachedResultName": "Yookassa"
        }
      },
      "credentials": {
        "googleSheetsOAuth2Api": {
          "id": "Yh4hxJEg7r5FU0cs",
          "name": "Google Sheets account"
        }
      },
      "retryOnFail": true,
      "typeVersion": 4.6
    },
    {
      "id": "2bf0aa18-1542-44d8-a198-7b0e024a1717",
      "name": "检查交易是否存在",
      "type": "n8n-nodes-base.if",
      "position": [
        680,
        1360
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 2,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "63373f12-84c3-4d9a-8356-09cc8b449361",
              "operator": {
                "type": "object",
                "operation": "exists",
                "singleValue": true
              },
              "leftValue": "={{ $input.item.json }}",
              "rightValue": ""
            }
          ]
        }
      },
      "typeVersion": 2.2
    }
  ],
  "active": false,
  "pinData": {},
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "b8225bd6-2191-48d1-8e9b-7c11681bf6a0",
  "connections": {
    "Status": {
      "main": [
        [
          {
            "node": "Check request values_1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Payment": {
      "main": [
        [
          {
            "node": "Check request values",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get Order": {
      "main": [
        [
          {
            "node": "Check Order",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Handle Error webhook",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Save Order": {
      "main": [
        [
          {
            "node": "Respond Payment",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Handle Error (save order)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Check Order": {
      "main": [
        [
          {
            "node": "Save Transaction",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Handle Error webhook",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get Product": {
      "main": [
        [
          {
            "node": "Check product_id",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Handle Error (get product)_1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get products": {
      "main": [
        [
          {
            "node": "Get products_1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Handle Events": {
      "main": [
        [
          {
            "node": "Validation metadata",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Validation metadata_",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get product_id": {
      "main": [
        [
          {
            "node": "Get Product",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get products_1": {
      "main": [
        [
          {
            "node": "Sorting  by price",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Handle Error (get product)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get transaction": {
      "main": [
        [
          {
            "node": "Check if transaction exists",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Handle Error webhook",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Check product_id": {
      "main": [
        [
          {
            "node": "Idempotence Key Generation",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Handle Error (product_id)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Email validation": {
      "main": [
        [
          {
            "node": "Get product_id",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Handle Error",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Save Transaction": {
      "main": [
        [
          {
            "node": "Respond payment event",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "YooKassa Request": {
      "main": [
        [
          {
            "node": "Save Order",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Handle Error (yookassa)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Sorting  by price": {
      "main": [
        [
          {
            "node": "Respond Products",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Validation metadata": {
      "main": [
        [
          {
            "node": "Get Order",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Handle Error webhook",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Check request values": {
      "main": [
        [
          {
            "node": "Email validation",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Handle Error",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Update refund status": {
      "main": [
        [
          {
            "node": "Respond refund event",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Validation metadata_": {
      "main": [
        [
          {
            "node": "Get transaction",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Handle Error webhook",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Check request values_1": {
      "main": [
        [
          {
            "node": "YooKassa Request Status",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Handle Error (check request)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Handle YooKassa webhook": {
      "main": [
        [
          {
            "node": "Handle Events",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "YooKassa Request Status": {
      "main": [
        [
          {
            "node": "Respond status",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Handle Error status",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Idempotence Key Generation": {
      "main": [
        [
          {
            "node": "YooKassa Request",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Check if transaction exists": {
      "main": [
        [
          {
            "node": "Update refund status",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Handle Error webhook",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}
常见问题

如何使用这个工作流?

复制上方的 JSON 配置代码,在您的 n8n 实例中创建新工作流并选择「从 JSON 导入」,粘贴配置后根据需要修改凭证设置即可。

这个工作流适合什么场景?

高级 - 财务, 人工智能

需要付费吗?

本工作流完全免费,您可以直接导入使用。但请注意,工作流中使用的第三方服务(如 OpenAI API)可能需要您自行付费。

工作流信息
难度等级
高级
节点数量44
分类2
节点类型10
难度说明

适合高级用户,包含 16+ 个节点的复杂工作流

作者
外部链接
在 n8n.io 查看

分享此工作流