{
 "name": "Daily Square sales summary to Telegram (AutomateRecipes)",
 "nodes": [
  {
   "parameters": {
    "rule": {
     "interval": [
      {
       "field": "cronExpression",
       "expression": "0 23 * * *"
      }
     ]
    }
   },
   "id": "833d4842-01c2-5398-8657-25d22279485e",
   "name": "Daily at closing 23:00",
   "type": "n8n-nodes-base.scheduleTrigger",
   "typeVersion": 1.2,
   "position": [
    0,
    0
   ]
  },
  {
   "parameters": {
    "url": "https://connect.squareup.com/v2/payments",
    "authentication": "genericCredentialType",
    "genericAuthType": "httpHeaderAuth",
    "sendQuery": true,
    "queryParameters": {
     "parameters": [
      {
       "name": "begin_time",
       "value": "={{ $now.startOf('day').toISO() }}"
      },
      {
       "name": "end_time",
       "value": "={{ $now.toISO() }}"
      },
      {
       "name": "limit",
       "value": "100"
      }
     ]
    },
    "options": {}
   },
   "id": "a0a6c3ac-1585-5c6b-9260-af774becc274",
   "name": "Square: today's payments",
   "type": "n8n-nodes-base.httpRequest",
   "typeVersion": 4.2,
   "position": [
    220,
    0
   ],
   "credentials": {
    "httpHeaderAuth": {
     "id": "",
     "name": "YOUR_HTTPHEADERAUTH_CREDENTIAL"
    }
   }
  },
  {
   "parameters": {
    "jsCode": "// Header credential: Authorization = Bearer YOUR_SQUARE_ACCESS_TOKEN. Amounts are in cents. Only first 100 payments (add cursor pagination for busy days).\nconst p=($input.first().json.payments||[]).filter(x=>x.status==='COMPLETED');\nconst total=p.reduce((s,x)=>s+(x.amount_money?.amount||0),0)/100;\nconst cur=p[0]?.amount_money?.currency||'';\nreturn [{json:{count:p.length,total,text:`Today's sales: ${total.toFixed(2)} ${cur} from ${p.length} payments`}}];"
   },
   "id": "430b576f-51c1-58c4-8a68-a1864d320cfe",
   "name": "Sum totals",
   "type": "n8n-nodes-base.code",
   "typeVersion": 2,
   "position": [
    440,
    0
   ]
  },
  {
   "parameters": {
    "chatId": "YOUR_TELEGRAM_CHAT_ID",
    "text": "={{ $json.text }}",
    "additionalFields": {}
   },
   "id": "cb63669e-8243-5273-895b-4e96cbb866a0",
   "name": "Telegram: send summary",
   "type": "n8n-nodes-base.telegram",
   "typeVersion": 1.2,
   "position": [
    660,
    0
   ],
   "credentials": {
    "telegramApi": {
     "id": "",
     "name": "YOUR_TELEGRAMAPI_CREDENTIAL"
    }
   }
  }
 ],
 "connections": {
  "Daily at closing 23:00": {
   "main": [
    [
     {
      "node": "Square: today's payments",
      "type": "main",
      "index": 0
     }
    ]
   ]
  },
  "Square: today's payments": {
   "main": [
    [
     {
      "node": "Sum totals",
      "type": "main",
      "index": 0
     }
    ]
   ]
  },
  "Sum totals": {
   "main": [
    [
     {
      "node": "Telegram: send summary",
      "type": "main",
      "index": 0
     }
    ]
   ]
  }
 },
 "settings": {
  "executionOrder": "v1"
 },
 "active": false,
 "pinData": {},
 "meta": {
  "note": "Replace YOUR_* placeholders and attach your own credentials. Not tested on real services."
 }
}