{
  "id": "Pq2ofdKSIXGjpA4G",
  "meta": {
    "templateCredsSetupCompleted": true
  },
  "name": "Automated School Fee Reminder Workflow with Payment Link",
  "tags": [],
  "nodes": [
    {
      "id": "a4054030-d07a-4d6c-831a-ab4feb752d28",
      "name": "Daily Fee Check - 8 AM",
      "type": "n8n-nodes-base.scheduleTrigger",
      "position": [
        40,
        340
      ],
      "parameters": {
        "rule": {
          "interval": [
            {
              "triggerAtHour": 8
            }
          ]
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "4f2d2d48-1816-47ea-a5e3-763a47fb5153",
      "name": "Read Pending Fees",
      "type": "n8n-nodes-base.microsoftExcel",
      "position": [
        260,
        340
      ],
      "parameters": {
        "filters": {
          "fields": [
            {
              "value": "Pending",
              "column": "Status"
            }
          ]
        },
        "resource": "worksheet",
        "workbook": {
          "__rl": true,
          "mode": "id",
          "value": "=fee-records-workbook"
        }
      },
      "credentials": {
        "microsoftExcelOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 2
    },
    {
      "id": "abdbf0e0-202e-4a77-bade-0923c269bd47",
      "name": "Process Fee Reminders",
      "type": "n8n-nodes-base.code",
      "position": [
        480,
        340
      ],
      "parameters": {
        "jsCode": "const currentDate = new Date();\nconst reminderDate = new Date();\nreminderDate.setDate(currentDate.getDate() + 3);\n\nconst feeRecords = $input.all();\nconst reminders = [];\n\nfor (const record of feeRecords) {\n  const feeData = record.json;\n  const dueDate = new Date(feeData.dueDate);\n  \n  if (dueDate <= reminderDate && dueDate > currentDate) {\n    const paymentLink = `https://payments.school.edu/pay?student=${feeData.studentId}&amount=${feeData.amount}&ref=${feeData.feeId}`;\n    \n    reminders.push({\n      studentName: feeData.studentName,\n      parentName: feeData.parentName,\n      parentEmail: feeData.parentEmail,\n      parentPhone: feeData.parentPhone,\n      feeType: feeData.feeType,\n      amount: feeData.amount,\n      dueDate: feeData.dueDate,\n      feeId: feeData.feeId,\n      paymentLink: paymentLink,\n      daysRemaining: Math.ceil((dueDate - currentDate) / (1000 * 60 * 60 * 24))\n    });\n  }\n}\n\nreturn reminders.map(item => ({ json: item }));"
      },
      "typeVersion": 2
    },
    {
      "id": "4d9a3063-7660-4f5e-bae3-43264b93d500",
      "name": "Prepare Email Reminder",
      "type": "n8n-nodes-base.code",
      "position": [
        700,
        240
      ],
      "parameters": {
        "jsCode": "const feeData = $input.first().json;\n\nconst emailSubject = `Fee Reminder: ${feeData.feeType} Due in ${feeData.daysRemaining} days`;\nconst emailBody = `Dear ${feeData.parentName},\n\nThis is a friendly reminder that the ${feeData.feeType} for ${feeData.studentName} is due on ${feeData.dueDate}.\n\nFee Details:\n- Student: ${feeData.studentName}\n- Fee Type: ${feeData.feeType}\n- Amount: $${feeData.amount}\n- Due Date: ${feeData.dueDate}\n- Days Remaining: ${feeData.daysRemaining}\n\n\ud83d\udcb3 PAY NOW: ${feeData.paymentLink}\n\nTo avoid late fees, please complete payment before the due date. If you have any questions, contact our finance office.\n\nThank you,\nSchool Finance Office`;\n\nreturn [{\n  json: {\n    to: feeData.parentEmail,\n    subject: emailSubject,\n    body: emailBody,\n    parentName: feeData.parentName,\n    studentName: feeData.studentName,\n    paymentLink: feeData.paymentLink\n  }\n}];"
      },
      "typeVersion": 2
    },
    {
      "id": "00e52e34-38e0-449c-aeb7-ebd7abad5d19",
      "name": "Prepare WhatsApp Reminder",
      "type": "n8n-nodes-base.code",
      "position": [
        700,
        440
      ],
      "parameters": {
        "jsCode": "const feeData = $input.first().json;\n\nconst whatsappMessage = `\ud83c\udfeb *Fee Reminder*\\n\\nDear ${feeData.parentName},\\n\\n\ud83d\udcb0 ${feeData.feeType} for *${feeData.studentName}*\\n\ud83d\udcb5 Amount: $${feeData.amount}\\n\ud83d\udcc5 Due: ${feeData.dueDate}\\n\u23f0 ${feeData.daysRemaining} days remaining\\n\\n\ud83d\udd17 *Pay Now:* ${feeData.paymentLink}\\n\\n_Please pay before due date to avoid late fees._\\n\\nSchool Finance Office`;\n\nreturn [{\n  json: {\n    phone: feeData.parentPhone,\n    message: whatsappMessage,\n    parentName: feeData.parentName,\n    studentName: feeData.studentName,\n    paymentLink: feeData.paymentLink\n  }\n}];"
      },
      "typeVersion": 2
    },
    {
      "id": "feb3bb1d-09c8-4f3d-93d7-5f8a290610e0",
      "name": "Send Email Reminder",
      "type": "n8n-nodes-base.emailSend",
      "position": [
        1140,
        240
      ],
      "parameters": {
        "text": "={{$json.body}}",
        "options": {},
        "subject": "={{$json.subject}}",
        "toEmail": "={{$json.to}}",
        "fromEmail": "user@example.com",
        "emailFormat": "text"
      },
      "credentials": {
        "smtp": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 2.1
    },
    {
      "id": "5ba21990-c355-4c14-b9a8-30289b096b33",
      "name": "Update Reminder Status",
      "type": "n8n-nodes-base.microsoftExcel",
      "position": [
        1360,
        340
      ],
      "parameters": {
        "options": {},
        "dataMode": "autoMap",
        "resource": "worksheet",
        "workbook": {
          "__rl": true,
          "mode": "id",
          "value": "=fee-records-workbook"
        },
        "operation": "update",
        "worksheet": {
          "__rl": true,
          "mode": "id",
          "value": "=345yhhgt43wedf"
        },
        "columnToMatchOn": "=name"
      },
      "credentials": {
        "microsoftExcelOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 2
    },
    {
      "id": "d8213541-6f43-4550-b8f8-c3ff32a5892a",
      "name": "Workflow Info",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -40,
        -240
      ],
      "parameters": {
        "color": 3,
        "width": 540,
        "height": 400,
        "content": "### **Fee Reminder Workflow**\n\n**\u23f0 Daily Check:** Runs at 8 AM\n\n**\ud83d\udd0d Process:**\n1. Read pending fees from Excel\n2. Filter fees due in 3 days\n3. Generate payment links\n4. Send email & WhatsApp reminders\n5. Update reminder status\n\n**\ud83d\udce7 Channels:**\n- Email with payment link\n- WhatsApp with formatted message\n\n**\ud83d\udd17 Payment Integration:**\nAutomatically generates secure payment links for each fee reminder."
      },
      "typeVersion": 1
    },
    {
      "id": "8f415190-7c68-43fe-b9ac-8259fe14bce8",
      "name": "Wait For Prepare Reminder",
      "type": "n8n-nodes-base.wait",
      "position": [
        920,
        240
      ],
      "parameters": {},
      "typeVersion": 1.1
    },
    {
      "id": "08cea390-d569-4399-b1de-f84d9397c218",
      "name": "Wait For Prepare Reminder for WhatsApp",
      "type": "n8n-nodes-base.wait",
      "position": [
        920,
        440
      ],
      "parameters": {},
      "typeVersion": 1.1
    },
    {
      "id": "0c791c6b-f9c1-47ce-8dd2-a5f84afa51dd",
      "name": "Send message",
      "type": "n8n-nodes-base.whatsApp",
      "position": [
        1140,
        440
      ],
      "parameters": {
        "textBody": "={{$json.body}}",
        "operation": "send",
        "phoneNumberId": "=+919988776655",
        "additionalFields": {},
        "recipientPhoneNumber": "={{$json.toforwp}}"
      },
      "credentials": {
        "whatsAppApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1
    }
  ],
  "active": false,
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "439c53c8-91d7-41ec-8903-0c266343961d",
  "connections": {
    "Send message": {
      "main": [
        [
          {
            "node": "Update Reminder Status",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Read Pending Fees": {
      "main": [
        [
          {
            "node": "Process Fee Reminders",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Send Email Reminder": {
      "main": [
        [
          {
            "node": "Update Reminder Status",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Process Fee Reminders": {
      "main": [
        [
          {
            "node": "Prepare Email Reminder",
            "type": "main",
            "index": 0
          },
          {
            "node": "Prepare WhatsApp Reminder",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Daily Fee Check - 8 AM": {
      "main": [
        [
          {
            "node": "Read Pending Fees",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Prepare Email Reminder": {
      "main": [
        [
          {
            "node": "Wait For Prepare Reminder",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Prepare WhatsApp Reminder": {
      "main": [
        [
          {
            "node": "Wait For Prepare Reminder for WhatsApp",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Wait For Prepare Reminder": {
      "main": [
        [
          {
            "node": "Send Email Reminder",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Wait For Prepare Reminder for WhatsApp": {
      "main": [
        [
          {
            "node": "Send message",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}