{
  "name": "03 - E-Commerce Order Processing & Inventory Sync",
  "nodes": [
    {
      "id": "node-1",
      "name": "Webhook - Shopify New Order",
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 2,
      "position": [240, 300],
      "parameters": { "httpMethod": "POST", "path": "shopify-order", "responseMode": "responseNode" }
    },
    {
      "id": "node-2",
      "name": "Code - Extract Order Data",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [480, 300],
      "parameters": {
        "jsCode": "const o = $input.first().json;\nreturn [{ json: {\n  order_id: o.id,\n  order_number: o.order_number,\n  customer_name: `${o.customer?.first_name||''} ${o.customer?.last_name||''}`.trim(),\n  customer_email: o.customer?.email || o.email,\n  total_price: parseFloat(o.total_price),\n  currency: o.currency,\n  line_items: o.line_items || [],\n  shipping_address: o.shipping_address || {},\n  financial_status: o.financial_status,\n  created_at: o.created_at\n} }];"
      }
    },
    {
      "id": "node-3",
      "name": "IF - Payment Confirmed",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2,
      "position": [720, 300],
      "parameters": {
        "conditions": {
          "conditions": [{ "id": "c1", "leftValue": "={{ $json.financial_status }}", "rightValue": "paid", "operator": { "type": "string", "operation": "equals" } }],
          "combinator": "and"
        }
      }
    },
    {
      "id": "node-4",
      "name": "QuickBooks - Create Invoice",
      "type": "n8n-nodes-base.quickbooks",
      "typeVersion": 1,
      "position": [960, 160],
      "credentials": { "quickBooksOAuth2Api": { "id": "YOUR_QB_CREDENTIAL_ID", "name": "QuickBooks account" } },
      "parameters": {
        "resource": "invoice",
        "operation": "create",
        "additionalFields": {
          "DocNumber": "={{ $json.order_number }}",
          "TxnDate": "={{ new Date().toISOString().split('T')[0] }}",
          "CustomerRef": "={{ $json.customer_name }}",
          "Line": [{ "Amount": "={{ $json.total_price }}", "DetailType": "SalesItemLineDetail" }]
        }
      }
    },
    {
      "id": "node-5",
      "name": "Gmail - Send Order Confirmation",
      "type": "n8n-nodes-base.gmail",
      "typeVersion": 2.1,
      "position": [1200, 160],
      "credentials": { "gmailOAuth2": { "id": "YOUR_GMAIL_CREDENTIAL_ID", "name": "Gmail account" } },
      "parameters": {
        "resource": "message",
        "operation": "send",
        "sendTo": "={{ $json.customer_email }}",
        "subject": "=Order #{{ $json.order_number }} Confirmed! 🎉",
        "message": "=<h2>Order Confirmed!</h2><p>Hi {{ $json.customer_name }}, your order <strong>#{{ $json.order_number }}</strong> for <strong>${{ $json.total_price }}</strong> has been confirmed and is being prepared. Tracking info coming soon!</p>",
        "options": { "isHtml": true }
      }
    },
    {
      "id": "node-6",
      "name": "Google Sheets - Log Order",
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 4.5,
      "position": [1440, 160],
      "credentials": { "googleSheetsOAuth2Api": { "id": "YOUR_GOOGLE_SHEETS_CREDENTIAL_ID", "name": "Google Sheets account" } },
      "parameters": {
        "resource": "sheet",
        "operation": "appendOrUpdate",
        "documentId": { "__rl": true, "value": "YOUR_SPREADSHEET_ID", "mode": "id" },
        "sheetName": { "__rl": true, "value": "Orders", "mode": "name" },
        "columns": {
          "mappingMode": "defineBelow",
          "value": {
            "Order Number": "={{ $json.order_number }}",
            "Customer": "={{ $json.customer_name }}",
            "Email": "={{ $json.customer_email }}",
            "Total": "={{ $json.total_price }}",
            "Status": "Paid & Invoiced",
            "Date": "={{ $json.created_at }}"
          }
        },
        "options": {}
      }
    },
    {
      "id": "node-7",
      "name": "Slack - Low Stock Alert",
      "type": "n8n-nodes-base.slack",
      "typeVersion": 2.3,
      "position": [960, 440],
      "credentials": { "slackApi": { "id": "YOUR_SLACK_CREDENTIAL_ID", "name": "Slack account" } },
      "parameters": {
        "resource": "message",
        "operation": "send",
        "channel": { "__rl": true, "value": "#inventory-alerts", "mode": "name" },
        "text": "=⚠️ Order #{{ $json.order_number }} failed — payment status: {{ $json.financial_status }}. Please review manually.",
        "otherOptions": {}
      }
    },
    {
      "id": "node-8",
      "name": "Respond to Webhook",
      "type": "n8n-nodes-base.respondToWebhook",
      "typeVersion": 1,
      "position": [1680, 160],
      "parameters": { "respondWith": "json", "responseBody": "={ \"status\": \"processed\" }" }
    }
  ],
  "connections": {
    "Webhook - Shopify New Order": { "main": [[{ "node": "Code - Extract Order Data", "type": "main", "index": 0 }]] },
    "Code - Extract Order Data": { "main": [[{ "node": "IF - Payment Confirmed", "type": "main", "index": 0 }]] },
    "IF - Payment Confirmed": {
      "main": [
        [{ "node": "QuickBooks - Create Invoice", "type": "main", "index": 0 }],
        [{ "node": "Slack - Low Stock Alert", "type": "main", "index": 0 }]
      ]
    },
    "QuickBooks - Create Invoice": { "main": [[{ "node": "Gmail - Send Order Confirmation", "type": "main", "index": 0 }]] },
    "Gmail - Send Order Confirmation": { "main": [[{ "node": "Google Sheets - Log Order", "type": "main", "index": 0 }]] },
    "Google Sheets - Log Order": { "main": [[{ "node": "Respond to Webhook", "type": "main", "index": 0 }]] }
  },
  "settings": { "executionOrder": "v1" },
  "active": false,
  "tags": [{ "name": "Portfolio" }, { "name": "E-Commerce" }]
}
