{
  "name": "Cake Merchant — Instant Order Fulfillment",
  "nodes": [
    {
      "parameters": {
        "httpMethod": "POST",
        "path": "cakemerchant-fulfill",
        "responseMode": "responseNode",
        "options": {}
      },
      "id": "e1b2c3d4-0005-4000-8000-000000000001",
      "name": "Webhook",
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 2,
      "position": [250, 300],
      "webhookId": "cakemerchant-fulfill"
    },
    {
      "parameters": {
        "operation": "read",
        "documentId": { "__rl": true, "value": "YOUR_SPREADSHEET_ID", "mode": "id" },
        "sheetName": { "__rl": true, "value": "Products", "mode": "list" },
        "filtersUI": {
          "values": [
            {
              "lookupColumn": "Product Name",
              "lookupValue": "={{ $json.body.data.metadata.description }}"
            }
          ]
        },
        "options": {}
      },
      "id": "e1b2c3d4-0005-4000-8000-000000000002",
      "name": "Lookup Product",
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 4.5,
      "position": [480, 300],
      "credentials": {
        "googleSheetsOAuth2Api": {
          "id": "CREDENTIAL_ID",
          "name": "Google Sheets — replace with your OAuth credentials"
        }
      }
    },
    {
      "parameters": {
        "conditions": {
          "options": { "caseSensitive": true, "leftValue": "", "typeValidation": "strict" },
          "conditions": [
            {
              "id": "has-product",
              "leftValue": "={{ $json['Download URL'] || $json['License Key'] }}",
              "rightValue": "",
              "operator": { "type": "string", "operation": "isNotEmpty" }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "id": "e1b2c3d4-0005-4000-8000-000000000003",
      "name": "Product Found?",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2.2,
      "position": [710, 300]
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            { "id": "email", "name": "buyerEmail", "value": "={{ $('Webhook').item.json.body.data.metadata.buyer_fields.email }}", "type": "string" },
            { "id": "desc", "name": "productName", "value": "={{ $('Webhook').item.json.body.data.metadata.description }}", "type": "string" },
            { "id": "dl", "name": "downloadUrl", "value": "={{ $json['Download URL'] }}", "type": "string" },
            { "id": "key", "name": "licenseKey", "value": "={{ $json['License Key'] }}", "type": "string" },
            { "id": "row", "name": "rowNumber", "value": "={{ $json.row_number }}", "type": "number" },
            { "id": "chargeId", "name": "chargeId", "value": "={{ $('Webhook').item.json.body.data.id }}", "type": "string" }
          ]
        },
        "options": {}
      },
      "id": "e1b2c3d4-0005-4000-8000-000000000004",
      "name": "Prepare Delivery",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [940, 200]
    },
    {
      "parameters": {
        "sendTo": "={{ $json.buyerEmail }}",
        "subject": "=Your order is ready — {{ $json.productName }}",
        "emailType": "html",
        "html": "=<h2>Your Order is Ready!</h2><p>Thank you for your purchase of <strong>{{ $json.productName }}</strong>.</p>{{ $json.downloadUrl ? '<p><strong>Download:</strong> <a href=\"' + $json.downloadUrl + '\">Click here to download</a></p>' : '' }}{{ $json.licenseKey ? '<p><strong>License Key:</strong> <code>' + $json.licenseKey + '</code></p>' : '' }}<p><strong>Charge ID:</strong> {{ $json.chargeId }}</p><p style=\"margin-top:1rem;color:#888;font-size:0.85rem;\">Powered by Cake Merchant</p>",
        "options": {}
      },
      "id": "e1b2c3d4-0005-4000-8000-000000000005",
      "name": "Send Delivery Email",
      "type": "n8n-nodes-base.emailSend",
      "typeVersion": 2.1,
      "position": [1170, 200],
      "credentials": {
        "smtp": {
          "id": "CREDENTIAL_ID",
          "name": "SMTP — replace with your mail server credentials"
        }
      }
    },
    {
      "parameters": {
        "operation": "update",
        "documentId": { "__rl": true, "value": "YOUR_SPREADSHEET_ID", "mode": "id" },
        "sheetName": { "__rl": true, "value": "Products", "mode": "list" },
        "columns": {
          "mappingMode": "defineBelow",
          "value": {
            "Status": "Delivered",
            "Delivered At": "={{ new Date().toISOString() }}",
            "Charge ID": "={{ $json.chargeId }}"
          }
        },
        "options": {}
      },
      "id": "e1b2c3d4-0005-4000-8000-000000000006",
      "name": "Mark as Delivered",
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 4.5,
      "position": [1400, 200],
      "credentials": {
        "googleSheetsOAuth2Api": {
          "id": "CREDENTIAL_ID",
          "name": "Google Sheets — replace with your OAuth credentials"
        }
      }
    },
    {
      "parameters": {
        "respondWith": "text",
        "responseBody": "OK"
      },
      "id": "e1b2c3d4-0005-4000-8000-000000000007",
      "name": "Respond OK",
      "type": "n8n-nodes-base.respondToWebhook",
      "typeVersion": 1.1,
      "position": [1630, 300]
    }
  ],
  "connections": {
    "Webhook": {
      "main": [
        [{ "node": "Lookup Product", "type": "main", "index": 0 }]
      ]
    },
    "Lookup Product": {
      "main": [
        [{ "node": "Product Found?", "type": "main", "index": 0 }]
      ]
    },
    "Product Found?": {
      "main": [
        [{ "node": "Prepare Delivery", "type": "main", "index": 0 }],
        [{ "node": "Respond OK", "type": "main", "index": 0 }]
      ]
    },
    "Prepare Delivery": {
      "main": [
        [{ "node": "Send Delivery Email", "type": "main", "index": 0 }]
      ]
    },
    "Send Delivery Email": {
      "main": [
        [{ "node": "Mark as Delivered", "type": "main", "index": 0 }]
      ]
    },
    "Mark as Delivered": {
      "main": [
        [{ "node": "Respond OK", "type": "main", "index": 0 }]
      ]
    }
  },
  "pinData": {},
  "settings": { "executionOrder": "v1" },
  "staticData": null,
  "tags": [],
  "triggerCount": 0,
  "updatedAt": "2026-02-15T00:00:00.000Z",
  "versionId": "1"
}
