{
  "name": "Cake Merchant — Daily Sales Summary Email",
  "nodes": [
    {
      "parameters": {
        "rule": {
          "interval": [
            { "field": "hours", "hoursInterval": 1, "triggerAtHour": 18 }
          ]
        }
      },
      "id": "d1b2c3d4-0004-4000-8000-000000000001",
      "name": "Every Day at 6 PM",
      "type": "n8n-nodes-base.scheduleTrigger",
      "typeVersion": 1.2,
      "position": [250, 300]
    },
    {
      "parameters": {
        "url": "=https://cakemerchant.io/api/charges",
        "authentication": "genericCredentialType",
        "genericAuthType": "httpHeaderAuth",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            { "name": "Authorization", "value": "Bearer YOUR_API_KEY" }
          ]
        },
        "options": {}
      },
      "id": "d1b2c3d4-0004-4000-8000-000000000002",
      "name": "Fetch Charges",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [480, 300],
      "credentials": {
        "httpHeaderAuth": {
          "id": "CREDENTIAL_ID",
          "name": "Cake Merchant API Key — replace with your key"
        }
      }
    },
    {
      "parameters": {
        "jsCode": "// Filter to today's confirmed charges and aggregate\nconst now = new Date();\nconst todayStr = now.toISOString().slice(0, 10);\n\nconst charges = $input.first().json.charges || $input.first().json.data || [];\n\nconst todayConfirmed = charges.filter(c => {\n  return c.status === 'confirmed' &&\n    c.confirmed_at && c.confirmed_at.startsWith(todayStr);\n});\n\nconst totalUsd = todayConfirmed.reduce((sum, c) => sum + (parseFloat(c.amount) || 0), 0);\nconst totalXmr = todayConfirmed.reduce((sum, c) => sum + (parseFloat(c.amount_xmr) || 0), 0);\nconst count = todayConfirmed.length;\n\nconst subject = `Daily Sales Summary — ${todayStr} — ${count} orders, $${totalUsd.toFixed(2)}`;\n\nconst html = `<h2>Daily Sales Summary</h2>\n<p><strong>Date:</strong> ${todayStr}</p>\n<p><strong>Orders:</strong> ${count}</p>\n<p><strong>Total USD:</strong> $${totalUsd.toFixed(2)}</p>\n<p><strong>Total XMR:</strong> ${totalXmr.toFixed(6)} XMR</p>\n<hr>\n<p style=\"color:#888;font-size:0.85rem;\">Powered by Cake Merchant</p>`;\n\nreturn [{ json: { subject, html, count, totalUsd, totalXmr, date: todayStr } }];"
      },
      "id": "d1b2c3d4-0004-4000-8000-000000000003",
      "name": "Aggregate Sales",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [710, 300]
    },
    {
      "parameters": {
        "sendTo": "merchant@example.com",
        "subject": "={{ $json.subject }}",
        "emailType": "html",
        "html": "={{ $json.html }}",
        "options": {}
      },
      "id": "d1b2c3d4-0004-4000-8000-000000000004",
      "name": "Send Summary Email",
      "type": "n8n-nodes-base.emailSend",
      "typeVersion": 2.1,
      "position": [940, 300],
      "credentials": {
        "smtp": {
          "id": "CREDENTIAL_ID",
          "name": "SMTP — replace with your mail server credentials"
        }
      }
    }
  ],
  "connections": {
    "Every Day at 6 PM": {
      "main": [
        [{ "node": "Fetch Charges", "type": "main", "index": 0 }]
      ]
    },
    "Fetch Charges": {
      "main": [
        [{ "node": "Aggregate Sales", "type": "main", "index": 0 }]
      ]
    },
    "Aggregate Sales": {
      "main": [
        [{ "node": "Send Summary Email", "type": "main", "index": 0 }]
      ]
    }
  },
  "pinData": {},
  "settings": { "executionOrder": "v1" },
  "staticData": null,
  "tags": [],
  "triggerCount": 0,
  "updatedAt": "2026-02-15T00:00:00.000Z",
  "versionId": "1"
}
