Tech With Galvan
Back to Articles
AutomationApr 22, 2029 • 5 min read

How to Automate Invoices and Payment Reminders

Automate invoice generation and payment reminders — Python scripts, templates, and tools that get you paid faster. For freelancers and small businesses.

Galvan
Galvan

Founder & Creator

Introduction

Late payments are the #1 cash flow problem for freelancers. The root cause: manual invoicing — you forget to send the invoice, the client forgets to pay, and you spend hours chasing money.

Automated invoicing fixes this: invoices generated and sent automatically, with payment reminders at the right time. This post shows you how to set it up.

The automation flow

Project completed → Invoice generated (PDF) → Invoice sent (email)
    ↓
Day 7: Reminder email ("Invoice due in 8 days")
    ↓
Day 14: Reminder email ("Invoice due tomorrow")
    ↓
Day 15: Invoice due (Net 15)
    ↓
Day 21: Overdue notice ("Invoice is 6 days overdue + 2% late fee")
    ↓
Day 30: Final notice ("Invoice is 15 days overdue. Late fee applies.")
    ↓
Day 45: Pause work / escalate

Step 1: Invoice template (Python + FPDF)

from fpdf import FPDF
from datetime import datetime, timedelta

def generate_invoice(client_name, client_email, items, invoice_num, due_days=15):
    pdf = FPDF()
    pdf.add_page()
    pdf.set_font("Arial", "B", 16)
    pdf.cell(0, 10, "INVOICE", ln=True, align="C")
    
    pdf.set_font("Arial", "", 11)
    pdf.cell(0, 8, f"Invoice #: {invoice_num}", ln=True)
    pdf.cell(0, 8, f"Date: {datetime.now().strftime('%B %d, %Y')}", ln=True)
    pdf.cell(0, 8, f"Due Date: {(datetime.now() + timedelta(days=due_days)).strftime('%B %d, %Y')}", ln=True)
    pdf.ln(5)
    
    pdf.cell(0, 8, f"Bill to: {client_name}", ln=True)
    pdf.cell(0, 8, f"Email: {client_email}", ln=True)
    pdf.ln(5)
    
    # Line items
    pdf.set_font("Arial", "B", 11)
    pdf.cell(90, 8, "Description", border=1)
    pdf.cell(20, 8, "Qty", border=1)
    pdf.cell(40, 8, "Rate", border=1)
    pdf.cell(40, 8, "Amount", border=1, ln=True)
    
    pdf.set_font("Arial", "", 11)
    total = 0
    for item in items:
        pdf.cell(90, 8, item["desc"], border=1)
        pdf.cell(20, 8, str(item["qty"]), border=1)
        pdf.cell(40, 8, f"Rs. {item['rate']:,}", border=1)
        amt = item["qty"] * item["rate"]
        pdf.cell(40, 8, f"Rs. {amt:,}", border=1, ln=True)
        total += amt
    
    pdf.set_font("Arial", "B", 11)
    pdf.cell(150, 8, "Total:", border=1)
    pdf.cell(40, 8, f"Rs. {total:,}", border=1, ln=True)
    
    pdf.ln(10)
    pdf.set_font("Arial", "", 10)
    pdf.cell(0, 8, "Payment: UPI, bank transfer, or Razorpay", ln=True)
    pdf.cell(0, 8, "UPI: yourname@upi | Bank: [details]", ln=True)
    pdf.cell(0, 8, "Late fee: 2% per month after due date", ln=True)
    
    filename = f"invoice_{invoice_num}.pdf"
    pdf.output(filename)
    return filename, total

Step 2: Send invoice via email (Resend)

import resend, os

resend.api_key = os.environ["RESEND_API_KEY"]

def send_invoice(client_name, client_email, items, invoice_num):
    filename, total = generate_invoice(client_name, client_email, items, invoice_num)
    
    with open(filename, "rb") as f:
        pdf_data = f.read()
    
    import base64
    resend.Emails.send({
        "from": "Your Business <[email protected]>",
        "to": [client_email],
        "subject": f"Invoice {invoice_num} — ₹{total:,}",
        "html": f"""
        <p>Hi {client_name},</p>
        <p>Please find attached invoice {invoice_num} for ₹{total:,}.</p>
        <p><strong>Due date:</strong> {(datetime.now() + timedelta(days=15)).strftime('%B %d, %Y')}</p>
        <p><strong>Payment:</strong> UPI (yourname@upi) or bank transfer</p>
        <p>Thank you for your business!</p>
        """,
        "attachments": [{"filename": filename, "content": base64.b64encode(pdf_data).decode()}],
    })
    print(f"Invoice {invoice_num} sent to {client_name}")

Step 3: Payment reminders (automated)

import resend, os
from datetime import datetime, timedelta

resend.api_key = os.environ["RESEND_API_KEY"]

def send_reminder(invoice, days_overdue):
    client = invoice["client"]
    amount = invoice["amount"]
    inv_num = invoice["number"]
    
    if days_overdue == -7:  # 7 days before due
        subject = f"Reminder: Invoice {inv_num} due in 7 days"
        body = f"Hi {client['name']}, this is a friendly reminder that invoice {inv_num} for ₹{amount:,} is due on {invoice['due_date']}."
    elif days_overdue == 0:  # Due today
        subject = f"Invoice {inv_num} is due today"
        body = f"Hi {client['name']}, invoice {inv_num} for ₹{amount:,} is due today. Please process payment at your earliest convenience."
    elif days_overdue == 7:  # 7 days overdue
        subject = f"Overdue: Invoice {inv_num} (7 days)"
        body = f"Hi {client['name']}, invoice {inv_num} for ₹{amount:,} is now 7 days overdue. Please process payment to avoid late fees."
    elif days_overdue == 14:  # 14 days overdue
        subject = f"Final notice: Invoice {inv_num} (14 days overdue)"
        body = f"Hi {client['name']}, invoice {inv_num} for ₹{amount:,} is now 14 days overdue. A 2% late fee has been applied. Total due: ₹{int(amount * 1.02):,}. Please process payment immediately."
    else:
        return
    
    resend.Emails.send({
        "from": "Billing <[email protected]>",
        "to": [client["email"]],
        "subject": subject,
        "html": f"<p>{body}</p><p>Payment link: [Razorpay link]</p>",
    })
    print(f"Reminder sent to {client['name']} (Day {days_overdue})")

Step 4: Automate with cron

# Run daily at 10 AM
0 10 * * * cd /path/to/project && python invoice_reminders.py

Or use GitHub Actions:

name: Invoice Reminders
on:
  schedule:
    - cron: '0 10 * * *'
jobs:
  remind:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - run: python invoice_reminders.py

Step 5: Track invoices

Google Sheets tracker

Invoice # Client Amount Due Date Status Days Overdue Last Reminder
INV-001 Acme Corp ₹35,000 2026-03-23 Paid 0 —
INV-002 StartupX ₹15,000 2026-03-20 Overdue 5 Day 7
INV-003 BlogCo ₹8,000 2026-03-28 Pending 0 —

Status flow

Draft → Sent → Paid / Overdue → Final Notice → Collections

Step 6: Payment tracking

def check_payments():
    """Check which invoices have been paid (via Razorpay/PayPal webhook or manual)."""
    invoices = load_invoices_from_db()
    for inv in invoices:
        if inv["status"] == "sent":
            # Check if payment received (via Razorpay API, bank statement, etc.)
            if payment_received(inv["number"]):
                inv["status"] = "paid"
                inv["paid_date"] = datetime.now().isoformat()
                save_invoice(inv)
                print(f"Invoice {inv['number']} marked as paid")

Common mistakes

  • Not invoicing immediately — delayed invoices = delayed payments
  • No payment terms — “due on receipt” means nothing. Set a date.
  • No reminders — clients forget. Remind them.
  • No late fee — without consequences, clients prioritize other payments
  • Not tracking — if you don’t track, you don’t know who owes you money
  • Manual invoicing — automate it. Your time is worth more than the setup cost.

Key Concepts

  • Invoice = document requesting payment
  • Net 15/30 = payment due in 15/30 days
  • Late fee = penalty for overdue payment (2% per month standard)
  • Payment link = one-click payment (Razorpay, Stripe, PayPal)
  • Cron job = scheduled task that runs automatically
  • Escalation = progressive steps from reminder to legal action

What to Try Next

FAQ

Should I use invoicing software or a custom script?

Start with a template (free). As you grow, use software (Wave, Zoho Invoice, FreshBooks) for automation, tracking, and payment links. Custom scripts are great for developers who want full control.

How do I handle clients who don’t pay?

Follow the escalation ladder: gentle reminder → firm reminder → phone call → final notice → pause work → collections. See Handle Late-Paying Clients for scripts at each stage.

Can I automate invoicing for retainer clients?

Yes — set up a monthly cron job that generates and sends invoices on the 1st of each month. Include the retainer amount, any additional work, and the due date. Automate the reminders too. See Automate Customer Follow-Ups.