{
  "name": "Detect and score refund risk with Webhook, OpenAI and Google Sheets",
  "nodes": [
    {
      "id": "2d5f7114-7492-4cdb-8ebd-1f87e28a5004",
      "name": "Normalize Data",
      "type": "n8n-nodes-base.code",
      "position": [
        2544,
        3184
      ]
    },
    {
      "id": "24c94632-0ff1-4dbb-9016-8cb3a443a08b",
      "name": "Parse AI Output",
      "type": "n8n-nodes-base.code",
      "position": [
        3296,
        3184
      ]
    },
    {
      "id": "9e86dafa-f911-471d-aceb-4bc771583208",
      "name": "IF High Risk",
      "type": "n8n-nodes-base.if",
      "position": [
        4032,
        3168
      ]
    },
    {
      "id": "11299f52-3b08-4dfd-914d-8f1b66aab0f9",
      "name": "Email Finance",
      "type": "n8n-nodes-base.gmail",
      "position": [
        4464,
        3072
      ]
    },
    {
      "id": "346181e4-83cf-4298-a52b-2d0a059ab2b6",
      "name": "Log Result",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        3664,
        3056
      ]
    },
    {
      "id": "7c520ebd-ec1f-4a68-8b78-d1244b2167f2",
      "name": "Update row in sheet",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        4864,
        3184
      ]
    },
    {
      "id": "9e40a771-ab28-46d8-aceb-b85631594d85",
      "name": "DEDUPE CHECK",
      "type": "n8n-nodes-base.if",
      "position": [
        2240,
        3184
      ]
    },
    {
      "id": "34cb1516-8de5-458d-9e12-09857222a2e3",
      "name": "Loop Over Items",
      "type": "n8n-nodes-base.splitInBatches",
      "position": [
        1936,
        3168
      ]
    },
    {
      "id": "2849660f-3a62-4b38-89f5-0448132a87ab",
      "name": "Split Out",
      "type": "n8n-nodes-base.splitOut",
      "position": [
        1616,
        3168
      ]
    },
    {
      "id": "e7d38b40-569b-4adf-b6f0-87747e7823ea",
      "name": "Sticky Note9",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        3168,
        2768
      ],
      "parameters": {
        "width": 304,
        "height": 928,
        "content": "### Step 5 – Parse AI Output\n\nCleans and parses the AI response.\n"
      }
    },
    {
      "id": "e833e245-eb25-4978-b201-b8344158e4b8",
      "name": "Sticky Note10",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        2752,
        2768
      ],
      "parameters": {
        "width": 384,
        "height": 928,
        "content": "### Step 4 – Message a model (OpenAI)\n\nSends normalized transaction data to OpenAI.\n\n"
      }
    },
    {
      "id": "e25bb684-034f-449e-8fb5-b4cc03fd3a47",
      "name": "Sticky Note12",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1248,
        2768
      ],
      "parameters": {
        "width": 864,
        "height": 928,
        "content": "### Step 1 - Ingest & Prepare Data\n\n**Webhook + Split Out + Loop Over Items**\nReceives order data (single or bulk), splits arrays, and processes each transaction individually."
      }
    },
    {
      "id": "144840ed-0076-4485-8a46-89da035116d2",
      "name": "Sticky Note15",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        2176,
        2768
      ],
      "parameters": {
        "width": null,
        "height": 928,
        "content": "### Step 2 – DEDUPE CHECK\n\nChecks whether the transaction has already been processed.\nOrders marked as `risk_processed = TRUE` are skipped."
      }
    },
    {
      "id": "8fba03a3-3e9d-4709-865b-04669818ddaf",
      "name": "Sticky Note17",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        4688,
        2768
      ],
      "parameters": {
        "width": 320,
        "height": 944,
        "content": "### Step 8 – Mark as Processed\n\nUpdates the source row to ensure the transaction is not reprocessed."
      }
    },
    {
      "id": "8ae1d958-892c-409c-9d93-5f27351f1876",
      "name": "Message a model2",
      "type": "@n8n/n8n-nodes-langchain.openAi",
      "position": [
        2832,
        3184
      ]
    },
    {
      "id": "25df1e67-074a-45ac-ae71-2ab7e9a9402d",
      "name": "Discord1",
      "type": "n8n-nodes-base.discord",
      "position": [
        4256,
        3072
      ]
    },
    {
      "id": "2f882148-e21e-4bf1-9b80-a2afc9f0b412",
      "name": "Webhook1",
      "type": "n8n-nodes-base.webhook",
      "position": [
        1296,
        3168
      ]
    },
    {
      "id": "b06fc2b7-7cc2-4934-b0fb-43c476f4acc3",
      "name": "Sticky Note11",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        3936,
        2768
      ],
      "parameters": {
        "width": 720,
        "height": 944,
        "content": "### Step 7 - Risk Decision & Alerts\n\nTriggers alerts only when risk level is HIGH and notifies relevant teams.\n\n"
      }
    },
    {
      "id": "dc13b34f-b522-4eb9-b93d-6f0a4616bb58",
      "name": "Sticky Note13",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        480,
        2768
      ],
      "parameters": {
        "width": 736,
        "height": 928,
        "content": "## Smart Refund Risk Detector\n\n### How it works\nThis workflow automatically evaluates refund and chargeback risk for incoming e-commerce orders. Orders are received via webhook, processed individually"
      }
    },
    {
      "id": "9140beeb-7e4f-4f06-8aa7-0296aa8a930b",
      "name": "Sticky Note14",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        3520,
        2768
      ],
      "parameters": {
        "width": 384,
        "height": 944,
        "content": "### Step 6 – Log Result (Google Sheets)\n\nAppends the evaluation result to a logging sheet.\nIncludes timestamp, order details, risk level, drivers, and recommended action."
      }
    },
    {
      "id": "80819930-db40-4f30-8b78-13f4613e1720",
      "name": "Sticky Note16",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        2464,
        2768
      ],
      "parameters": {
        "width": null,
        "height": 928,
        "content": "\n### Step 3 – Normalize Data\n\nValidates required fields and normalizes incoming data:\n\n"
      }
    }
  ],
  "connections": {
    "Discord1": {
      "main": [
        [
          {
            "node": "Email Finance",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Webhook1": {
      "main": [
        [
          {
            "node": "Split Out",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Split Out": {
      "main": [
        [
          {
            "node": "Loop Over Items",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Log Result": {
      "main": [
        [
          {
            "node": "IF High Risk",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "DEDUPE CHECK": {
      "main": [
        [
          {
            "node": "Normalize Data",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "IF High Risk": {
      "main": [
        [
          {
            "node": "Discord1",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Update row in sheet",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Email Finance": {
      "main": [
        [
          {
            "node": "Update row in sheet",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Normalize Data": {
      "main": [
        [
          {
            "node": "Message a model2",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Loop Over Items": {
      "main": [
        [],
        [
          {
            "node": "DEDUPE CHECK",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Parse AI Output": {
      "main": [
        [
          {
            "node": "Log Result",
            "type": "main",
            "index": 0
          },
          {
            "node": "IF High Risk",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Message a model2": {
      "main": [
        [
          {
            "node": "Parse AI Output",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Update row in sheet": {
      "main": [
        [
          {
            "node": "Loop Over Items",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}