invoiceguard 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (37) hide show
  1. invoiceguard-0.1.0/LICENSE +200 -0
  2. invoiceguard-0.1.0/PKG-INFO +234 -0
  3. invoiceguard-0.1.0/README.md +202 -0
  4. invoiceguard-0.1.0/pyproject.toml +60 -0
  5. invoiceguard-0.1.0/setup.cfg +4 -0
  6. invoiceguard-0.1.0/src/invoiceguard/__init__.py +7 -0
  7. invoiceguard-0.1.0/src/invoiceguard/cli.py +303 -0
  8. invoiceguard-0.1.0/src/invoiceguard/config.py +87 -0
  9. invoiceguard-0.1.0/src/invoiceguard/contracts.py +67 -0
  10. invoiceguard-0.1.0/src/invoiceguard/db.py +213 -0
  11. invoiceguard-0.1.0/src/invoiceguard/dunning.py +108 -0
  12. invoiceguard-0.1.0/src/invoiceguard/email_templates/day1.md +12 -0
  13. invoiceguard-0.1.0/src/invoiceguard/email_templates/day15.md +17 -0
  14. invoiceguard-0.1.0/src/invoiceguard/email_templates/day7.md +16 -0
  15. invoiceguard-0.1.0/src/invoiceguard/mail.py +37 -0
  16. invoiceguard-0.1.0/src/invoiceguard/stripe_links.py +55 -0
  17. invoiceguard-0.1.0/src/invoiceguard/web/__init__.py +0 -0
  18. invoiceguard-0.1.0/src/invoiceguard/web/db.py +306 -0
  19. invoiceguard-0.1.0/src/invoiceguard/web/main.py +152 -0
  20. invoiceguard-0.1.0/src/invoiceguard/web/static/style.css +152 -0
  21. invoiceguard-0.1.0/src/invoiceguard/web/templates/base.html +23 -0
  22. invoiceguard-0.1.0/src/invoiceguard/web/templates/detail.html +53 -0
  23. invoiceguard-0.1.0/src/invoiceguard/web/templates/index.html +79 -0
  24. invoiceguard-0.1.0/src/invoiceguard/webhooks.py +60 -0
  25. invoiceguard-0.1.0/src/invoiceguard.egg-info/PKG-INFO +234 -0
  26. invoiceguard-0.1.0/src/invoiceguard.egg-info/SOURCES.txt +35 -0
  27. invoiceguard-0.1.0/src/invoiceguard.egg-info/dependency_links.txt +1 -0
  28. invoiceguard-0.1.0/src/invoiceguard.egg-info/entry_points.txt +2 -0
  29. invoiceguard-0.1.0/src/invoiceguard.egg-info/requires.txt +11 -0
  30. invoiceguard-0.1.0/src/invoiceguard.egg-info/top_level.txt +1 -0
  31. invoiceguard-0.1.0/tests/test_cli.py +110 -0
  32. invoiceguard-0.1.0/tests/test_contract.py +35 -0
  33. invoiceguard-0.1.0/tests/test_dunning.py +123 -0
  34. invoiceguard-0.1.0/tests/test_e2e.py +152 -0
  35. invoiceguard-0.1.0/tests/test_stripe.py +77 -0
  36. invoiceguard-0.1.0/tests/test_web_dashboard.py +293 -0
  37. invoiceguard-0.1.0/tests/test_webhook.py +94 -0
@@ -0,0 +1,200 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ Use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We don't recommend using a
185
+ plain text file; if you use a plain text file, use the following
186
+ notice:
187
+
188
+ Copyright [yyyy] [name of copyright owner]
189
+
190
+ Licensed under the Apache License, Version 2.0 (the "License");
191
+ you may not use this file except in compliance with the License.
192
+ You may obtain a copy of the License at
193
+
194
+ http://www.apache.org/licenses/LICENSE-2.0
195
+
196
+ Unless required by applicable law or agreed to in writing, software
197
+ distributed under the License is distributed on an "AS IS" BASIS,
198
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
199
+ See the License for the specific language governing permissions and
200
+ limitations under the License.
@@ -0,0 +1,234 @@
1
+ Metadata-Version: 2.4
2
+ Name: invoiceguard
3
+ Version: 0.1.0
4
+ Summary: Freelancer payment enforcement: deposit links tied to a contract with a late-fee clause, then automated 3-stage collections.
5
+ Author: InvoiceGuard contributors
6
+ License: Apache-2.0
7
+ Project-URL: Homepage, https://github.com/Bilal-Junaid-Jiwani/invoiceguard
8
+ Keywords: freelance,invoicing,stripe,collections,dunning
9
+ Classifier: Development Status :: 3 - Alpha
10
+ Classifier: Intended Audience :: End Users/Desktop
11
+ Classifier: License :: OSI Approved :: Apache Software License
12
+ Classifier: Programming Language :: Python :: 3
13
+ Classifier: Programming Language :: Python :: 3.10
14
+ Classifier: Programming Language :: Python :: 3.11
15
+ Classifier: Programming Language :: Python :: 3.12
16
+ Classifier: Environment :: Console
17
+ Classifier: Topic :: Office/Business :: Financial
18
+ Requires-Python: >=3.10
19
+ Description-Content-Type: text/markdown
20
+ License-File: LICENSE
21
+ Requires-Dist: stripe<16,>=12
22
+ Requires-Dist: PyYAML>=6
23
+ Requires-Dist: click>=8
24
+ Requires-Dist: fastapi>=0.110
25
+ Requires-Dist: uvicorn[standard]>=0.29
26
+ Requires-Dist: python-multipart>=0.0.18
27
+ Requires-Dist: jinja2>=3.1
28
+ Provides-Extra: dev
29
+ Requires-Dist: pytest>=8; extra == "dev"
30
+ Requires-Dist: httpx>=0.27; extra == "dev"
31
+ Dynamic: license-file
32
+
33
+ # InvoiceGuard
34
+
35
+ **Freelancer payment enforcement: deposit links tied to a contract with a late-fee clause — then automated, escalating collections.**
36
+
37
+ Solo freelancers don't get paid. A Kaplan Group report (April 2026) found **85% of freelancers experience late payment**; a Freelancers Union survey found **91%** have experienced late/overdue payments, with 54% waiting 3+ months. InvoiceGuard's wedge:
38
+
39
+ 1. **Before work starts:** generate a contract with a late-fee clause, create a Stripe deposit payment link. The client acknowledges the contract by accepting (paying) the deposit link.
40
+ 2. **After the due date:** an automated 3-stage email escalation — day-1 polite nudge → day-7 firm reminder → day-15 formal notice quoting the late-fee clause — until a Stripe webhook marks the invoice paid.
41
+
42
+ Local-first (SQLite), open-source (Apache-2.0), works alongside your existing invoicing tools via Stripe. No platform switch required.
43
+
44
+ > **Honest scope:** v1's "signature" is a client-acknowledgment checkbox (recorded when the deposit link is paid), not a legal e-signature. See [Limits of v1](#limits-of-v1).
45
+
46
+ ---
47
+
48
+ ## 5-minute quickstart
49
+
50
+ **0. Install**
51
+
52
+ ```bash
53
+ pip install invoiceguard
54
+ # or, from a local clone: pip install -r requirements.txt && pip install -e .
55
+ invoiceguard init # creates ~/.invoiceguard (config template, DB, email templates)
56
+ ```
57
+
58
+ **1. Add your Stripe test key** (~2 min)
59
+
60
+ 1. Go to <https://dashboard.stripe.com/test/apikeys> (toggle **Test mode** on).
61
+ 2. **Developers → API keys → Create secret key**, copy the `sk_test_...` value.
62
+ 3. Paste it into `~/.invoiceguard/config.yaml` as `stripe_secret_key`, **or** export it:
63
+ ```bash
64
+ export INVOICEGUARD_STRIPE_SECRET_KEY="sk_test_..."
65
+ ```
66
+
67
+ **2. Add your SMTP details** (~2 min) — how dunning emails are sent. In `~/.invoiceguard/config.yaml`:
68
+
69
+ ```yaml
70
+ smtp:
71
+ host: "smtp.gmail.com"
72
+ port: 587
73
+ username: "you@example.com"
74
+ password: "YOUR_GMAIL_APP_PASSWORD" # or export INVOICEGUARD_SMTP_PASSWORD
75
+ from_addr: "you@example.com"
76
+ use_tls: true
77
+ ```
78
+
79
+ (Gmail: create an **App Password** at Google Account → Security → 2-Step Verification → App passwords. Any SMTP provider works.)
80
+
81
+ **3. Create a client, project, and deposit link** (~1 min)
82
+
83
+ ```bash
84
+ invoiceguard client add --name "Acme Corp" --email "billing@acme.com"
85
+
86
+ invoiceguard project create --client "Acme Corp" --title "Website redesign" \
87
+ --amount 2000 --deposit-pct 50 --late-fee-pct 1.5 --ack
88
+ # ^ generates the contract markdown (with the late-fee clause) and records
89
+ # client acknowledgment (--ack = client accepted the deposit link)
90
+
91
+ invoiceguard invoice create --project 1 --kind deposit
92
+ # => invoice #1 (deposit): $1,000.00
93
+ # pay link: https://buy.stripe.com/...
94
+ # due: 2026-10-07 status: sent
95
+ ```
96
+
97
+ Send the pay link to the client. That's the whole pre-work flow.
98
+
99
+ **4. Let collections run themselves**
100
+
101
+ ```bash
102
+ # add to your crontab (runs the dunning scan every morning at 9:00):
103
+ 0 9 * * * /path/to/venv/bin/invoiceguard check-due >> ~/.invoiceguard/check-due.log 2>&1
104
+ ```
105
+
106
+ `invoiceguard check-due` scans invoices past their due date and sends the next escalation stage (day1 → day7 → day15), using the editable markdown templates in `~/.invoiceguard/templates/`. It's idempotent — a stage is never sent twice for the same invoice. When the client pays, Stripe's webhook flips the invoice to `paid` automatically.
107
+
108
+ **5. Stripe webhook (so payments mark invoices paid)**
109
+
110
+ 1. In the Stripe dashboard: **Developers → Webhooks → Add endpoint**.
111
+ 2. URL: `https://YOUR-HOST/webhooks/stripe` (the dashboard app serves this; see below).
112
+ 3. Select event: `checkout.session.completed`.
113
+ 4. Copy the **Signing secret** (`whsec_...`) into `stripe_webhook_secret` in the config (or export `INVOICEGUARD_STRIPE_WEBHOOK_SECRET`). The dashboard webhook reads the secret from the env var first, then the config file, then the legacy `STRIPE_WEBHOOK_SECRET` env var.
114
+
115
+ ---
116
+
117
+ ## CLI reference
118
+
119
+ | Command | What it does |
120
+ |---|---|
121
+ | `invoiceguard init` | Create `~/.invoiceguard/` (config template, DB, email templates) |
122
+ | `invoiceguard client add --name N --email E` | Add a client |
123
+ | `invoiceguard client list` | List clients |
124
+ | `invoiceguard project create --client N --title T --amount 2000 [--deposit-pct 50] [--late-fee-pct 1.5] [--late-fee-grace-days 15] [--ack]` | Create project + generate contract markdown |
125
+ | `invoiceguard project ack ID` | Record client acknowledgment of the contract |
126
+ | `invoiceguard project list` | List projects |
127
+ | `invoiceguard invoice create --project ID --kind deposit\|milestone\|final [--amount X] [--due-days 7]` | Create a Stripe payment link (status → `sent`) |
128
+ | `invoiceguard invoice list` | List invoices |
129
+ | `invoiceguard invoice mark-paid ID` | Manually mark paid |
130
+ | `invoiceguard invoice void ID` | Void an invoice |
131
+ | `invoiceguard check-due` | Run the dunning scan (cron target) |
132
+ | `invoiceguard dashboard [--port 8000]` | Launch the local web dashboard (`http://127.0.0.1:8000`) — invoice list, detail with escalation timeline, Stripe webhook receiver |
133
+
134
+ Kind defaults: `deposit` = `deposit_pct`% of project total; `final` = remainder after deposit; `milestone` = full amount unless `--amount` overrides.
135
+
136
+ ## Configuration
137
+
138
+ `~/.invoiceguard/config.yaml` (override path with `$INVOICEGUARD_CONFIG`; DB with `$INVOICEGUARD_DB`):
139
+
140
+ ```yaml
141
+ stripe_secret_key: "sk_test_..." # or INVOICEGUARD_STRIPE_SECRET_KEY
142
+ stripe_webhook_secret: "whsec_..." # or INVOICEGUARD_STRIPE_WEBHOOK_SECRET
143
+ smtp:
144
+ host: "smtp.gmail.com"
145
+ port: 587
146
+ username: "you@example.com"
147
+ password: "APP_PASSWORD" # or INVOICEGUARD_SMTP_PASSWORD
148
+ from_addr: "you@example.com"
149
+ use_tls: true
150
+ app:
151
+ base_url: "http://localhost:8000"
152
+ ```
153
+
154
+ Keys come **only** from config/env — never hardcoded, never committed (`.gitignore` covers `config.yaml`, `.env`, `*.key`, and the local DB).
155
+
156
+ ## Dunning templates
157
+
158
+ `~/.invoiceguard/templates/day1.md`, `day7.md`, `day15.md` — plain markdown with `{variables}`:
159
+
160
+ `{client_name}` `{project_title}` `{amount}` `{due_date}` `{days_overdue}` `{late_fee_pct}` `{pay_url}`
161
+
162
+ Edit them freely; `check-due` picks them up on the next run. Stage timing: day1 fires at ≥1 day overdue, day7 at ≥7, day15 at ≥15 — earliest unsent due stage wins, one email per invoice per run.
163
+
164
+ ## Database schema (contract with the dashboard app)
165
+
166
+ SQLite, default `~/.invoiceguard/invoiceguard.db`. The dashboard app reads/writes these exact tables — column names and types are frozen; additive migrations only:
167
+
168
+ ```sql
169
+ CREATE TABLE clients(id INTEGER PRIMARY KEY, name TEXT NOT NULL, email TEXT, created_at TEXT NOT NULL);
170
+ CREATE TABLE projects(id INTEGER PRIMARY KEY, client_id INTEGER NOT NULL REFERENCES clients(id), title TEXT NOT NULL, amount_cents INTEGER NOT NULL, currency TEXT NOT NULL DEFAULT 'USD', deposit_pct REAL NOT NULL DEFAULT 50.0, late_fee_pct REAL NOT NULL DEFAULT 1.5, late_fee_grace_days INTEGER NOT NULL DEFAULT 15, contract_md TEXT NOT NULL, contract_ack INTEGER NOT NULL DEFAULT 0, contract_ack_at TEXT, created_at TEXT NOT NULL);
171
+ CREATE TABLE invoices(id INTEGER PRIMARY KEY, project_id INTEGER NOT NULL REFERENCES projects(id), kind TEXT NOT NULL, amount_cents INTEGER NOT NULL, currency TEXT NOT NULL DEFAULT 'USD', status TEXT NOT NULL DEFAULT 'draft', stripe_url TEXT, stripe_session_id TEXT, due_date TEXT, sent_at TEXT, paid_at TEXT, created_at TEXT NOT NULL);
172
+ CREATE TABLE dunning_events(id INTEGER PRIMARY KEY, invoice_id INTEGER NOT NULL REFERENCES invoices(id), stage TEXT NOT NULL, sent_at TEXT NOT NULL);
173
+ ```
174
+
175
+ kinds: `deposit | milestone | final`. statuses: `draft | sent | paid | overdue | void`. stages: `day1 | day7 | day15`.
176
+
177
+ ## Web dashboard
178
+
179
+ `invoiceguard dashboard` launches the web dashboard for real — uvicorn serving
180
+ `invoiceguard.web.main:app` (default `http://127.0.0.1:8000`, `--port` to
181
+ change it). It shares this SQLite database: invoice list with status filters
182
+ and escalation stages, per-invoice detail with a chronological timeline, and
183
+ the `POST /webhooks/stripe` endpoint that marks invoices paid when Stripe
184
+ reports a completed checkout session.
185
+
186
+ Quick webhook smoke test (no network — the payload is signed locally):
187
+
188
+ ```bash
189
+ INVOICEGUARD_DB=/tmp/ig-demo.db .venv/bin/python seed_demo.py --fresh
190
+ INVOICEGUARD_DB=/tmp/ig-demo.db INVOICEGUARD_STRIPE_WEBHOOK_SECRET=whsec_test_x \
191
+ .venv/bin/invoiceguard dashboard
192
+ # -> http://127.0.0.1:8000/ (Ctrl-C to stop)
193
+ ```
194
+
195
+ ## Docker
196
+
197
+ ```bash
198
+ docker compose up -d # CLI container, data in the invoiceguard-data volume
199
+ docker compose run --rm app check-due # one-off dunning scan
200
+ ```
201
+
202
+ Put secrets in a `.env` file next to `docker-compose.yml` (never committed): `INVOICEGUARD_STRIPE_SECRET_KEY`, `INVOICEGUARD_STRIPE_WEBHOOK_SECRET`, `INVOICEGUARD_SMTP_PASSWORD`. Port 8000 is exposed for the dashboard.
203
+
204
+ ## Running tests
205
+
206
+ ```bash
207
+ python -m venv .venv && .venv/bin/pip install -r requirements.txt && .venv/bin/pip install -e .
208
+ .venv/bin/python -m pytest tests/ -q
209
+ ```
210
+
211
+ 54 tests, all green (2026-10-02): contract clause rendering, dunning stage selection + idempotency, template rendering, webhook signature verification (real HMAC check, offline), Stripe link creation (mocked SDK, params asserted), CLI flows, dashboard integration (page rendering + offline webhook checks incl. the `invoiceguard_invoice_id` metadata-key regression and the webhook-secret resolution regression: `INVOICEGUARD_STRIPE_WEBHOOK_SECRET` env / config-file secret honored, placeholder rejected), and a full end-to-end (init → client → project → invoice → `check-due` against a real local SMTP server → assert email captured + `dunning_events` row written).
212
+
213
+ ## Limits of v1
214
+
215
+ - **No live Stripe call was verified in this build environment** — Stripe's connector isn't connected here. `invoice create` was verified with a mocked `stripe` SDK asserting the exact `PaymentLink.create` params (line items, price data, metadata); webhook handling was verified with **real** `stripe.Webhook.construct_event` signature verification using a test secret (works offline). You add your own test key (2 min, above) and the live path is standard Stripe API.
216
+ - **v1 acknowledgment is a checkbox, not a signature.** Paying the deposit link = the client accepted the terms; `contract_ack=1` records it. Real e-signature is roadmap.
217
+ - **Email deliverability is yours.** InvoiceGuard sends via *your* SMTP. Use a reputable provider (Gmail App Password, SendGrid, etc.) and warm up new addresses; check spam folders in testing.
218
+ - **Late-fee enforceability varies by jurisdiction.** The clause is a contractual starting point, not legal advice. Adjust `late_fee_pct` / grace days per project.
219
+
220
+ ## Roadmap
221
+
222
+ - **Real e-signature** — typed-name / drawn-signature capture on the contract, stored with the project.
223
+ - **SMS / WhatsApp escalation** — day-15 via message, not just email.
224
+ - **Agency mode** — multi-freelancer workspaces, per-client dunning policies.
225
+ - Late-fee accrual calculator + ledger on the dashboard.
226
+ - Partial payments / payment plans.
227
+
228
+ ## Changelog
229
+
230
+ Release history lives in [CHANGELOG.md](CHANGELOG.md) — newest first, no fluff.
231
+
232
+ ## License
233
+
234
+ Apache-2.0 — see [LICENSE](LICENSE).
@@ -0,0 +1,202 @@
1
+ # InvoiceGuard
2
+
3
+ **Freelancer payment enforcement: deposit links tied to a contract with a late-fee clause — then automated, escalating collections.**
4
+
5
+ Solo freelancers don't get paid. A Kaplan Group report (April 2026) found **85% of freelancers experience late payment**; a Freelancers Union survey found **91%** have experienced late/overdue payments, with 54% waiting 3+ months. InvoiceGuard's wedge:
6
+
7
+ 1. **Before work starts:** generate a contract with a late-fee clause, create a Stripe deposit payment link. The client acknowledges the contract by accepting (paying) the deposit link.
8
+ 2. **After the due date:** an automated 3-stage email escalation — day-1 polite nudge → day-7 firm reminder → day-15 formal notice quoting the late-fee clause — until a Stripe webhook marks the invoice paid.
9
+
10
+ Local-first (SQLite), open-source (Apache-2.0), works alongside your existing invoicing tools via Stripe. No platform switch required.
11
+
12
+ > **Honest scope:** v1's "signature" is a client-acknowledgment checkbox (recorded when the deposit link is paid), not a legal e-signature. See [Limits of v1](#limits-of-v1).
13
+
14
+ ---
15
+
16
+ ## 5-minute quickstart
17
+
18
+ **0. Install**
19
+
20
+ ```bash
21
+ pip install invoiceguard
22
+ # or, from a local clone: pip install -r requirements.txt && pip install -e .
23
+ invoiceguard init # creates ~/.invoiceguard (config template, DB, email templates)
24
+ ```
25
+
26
+ **1. Add your Stripe test key** (~2 min)
27
+
28
+ 1. Go to <https://dashboard.stripe.com/test/apikeys> (toggle **Test mode** on).
29
+ 2. **Developers → API keys → Create secret key**, copy the `sk_test_...` value.
30
+ 3. Paste it into `~/.invoiceguard/config.yaml` as `stripe_secret_key`, **or** export it:
31
+ ```bash
32
+ export INVOICEGUARD_STRIPE_SECRET_KEY="sk_test_..."
33
+ ```
34
+
35
+ **2. Add your SMTP details** (~2 min) — how dunning emails are sent. In `~/.invoiceguard/config.yaml`:
36
+
37
+ ```yaml
38
+ smtp:
39
+ host: "smtp.gmail.com"
40
+ port: 587
41
+ username: "you@example.com"
42
+ password: "YOUR_GMAIL_APP_PASSWORD" # or export INVOICEGUARD_SMTP_PASSWORD
43
+ from_addr: "you@example.com"
44
+ use_tls: true
45
+ ```
46
+
47
+ (Gmail: create an **App Password** at Google Account → Security → 2-Step Verification → App passwords. Any SMTP provider works.)
48
+
49
+ **3. Create a client, project, and deposit link** (~1 min)
50
+
51
+ ```bash
52
+ invoiceguard client add --name "Acme Corp" --email "billing@acme.com"
53
+
54
+ invoiceguard project create --client "Acme Corp" --title "Website redesign" \
55
+ --amount 2000 --deposit-pct 50 --late-fee-pct 1.5 --ack
56
+ # ^ generates the contract markdown (with the late-fee clause) and records
57
+ # client acknowledgment (--ack = client accepted the deposit link)
58
+
59
+ invoiceguard invoice create --project 1 --kind deposit
60
+ # => invoice #1 (deposit): $1,000.00
61
+ # pay link: https://buy.stripe.com/...
62
+ # due: 2026-10-07 status: sent
63
+ ```
64
+
65
+ Send the pay link to the client. That's the whole pre-work flow.
66
+
67
+ **4. Let collections run themselves**
68
+
69
+ ```bash
70
+ # add to your crontab (runs the dunning scan every morning at 9:00):
71
+ 0 9 * * * /path/to/venv/bin/invoiceguard check-due >> ~/.invoiceguard/check-due.log 2>&1
72
+ ```
73
+
74
+ `invoiceguard check-due` scans invoices past their due date and sends the next escalation stage (day1 → day7 → day15), using the editable markdown templates in `~/.invoiceguard/templates/`. It's idempotent — a stage is never sent twice for the same invoice. When the client pays, Stripe's webhook flips the invoice to `paid` automatically.
75
+
76
+ **5. Stripe webhook (so payments mark invoices paid)**
77
+
78
+ 1. In the Stripe dashboard: **Developers → Webhooks → Add endpoint**.
79
+ 2. URL: `https://YOUR-HOST/webhooks/stripe` (the dashboard app serves this; see below).
80
+ 3. Select event: `checkout.session.completed`.
81
+ 4. Copy the **Signing secret** (`whsec_...`) into `stripe_webhook_secret` in the config (or export `INVOICEGUARD_STRIPE_WEBHOOK_SECRET`). The dashboard webhook reads the secret from the env var first, then the config file, then the legacy `STRIPE_WEBHOOK_SECRET` env var.
82
+
83
+ ---
84
+
85
+ ## CLI reference
86
+
87
+ | Command | What it does |
88
+ |---|---|
89
+ | `invoiceguard init` | Create `~/.invoiceguard/` (config template, DB, email templates) |
90
+ | `invoiceguard client add --name N --email E` | Add a client |
91
+ | `invoiceguard client list` | List clients |
92
+ | `invoiceguard project create --client N --title T --amount 2000 [--deposit-pct 50] [--late-fee-pct 1.5] [--late-fee-grace-days 15] [--ack]` | Create project + generate contract markdown |
93
+ | `invoiceguard project ack ID` | Record client acknowledgment of the contract |
94
+ | `invoiceguard project list` | List projects |
95
+ | `invoiceguard invoice create --project ID --kind deposit\|milestone\|final [--amount X] [--due-days 7]` | Create a Stripe payment link (status → `sent`) |
96
+ | `invoiceguard invoice list` | List invoices |
97
+ | `invoiceguard invoice mark-paid ID` | Manually mark paid |
98
+ | `invoiceguard invoice void ID` | Void an invoice |
99
+ | `invoiceguard check-due` | Run the dunning scan (cron target) |
100
+ | `invoiceguard dashboard [--port 8000]` | Launch the local web dashboard (`http://127.0.0.1:8000`) — invoice list, detail with escalation timeline, Stripe webhook receiver |
101
+
102
+ Kind defaults: `deposit` = `deposit_pct`% of project total; `final` = remainder after deposit; `milestone` = full amount unless `--amount` overrides.
103
+
104
+ ## Configuration
105
+
106
+ `~/.invoiceguard/config.yaml` (override path with `$INVOICEGUARD_CONFIG`; DB with `$INVOICEGUARD_DB`):
107
+
108
+ ```yaml
109
+ stripe_secret_key: "sk_test_..." # or INVOICEGUARD_STRIPE_SECRET_KEY
110
+ stripe_webhook_secret: "whsec_..." # or INVOICEGUARD_STRIPE_WEBHOOK_SECRET
111
+ smtp:
112
+ host: "smtp.gmail.com"
113
+ port: 587
114
+ username: "you@example.com"
115
+ password: "APP_PASSWORD" # or INVOICEGUARD_SMTP_PASSWORD
116
+ from_addr: "you@example.com"
117
+ use_tls: true
118
+ app:
119
+ base_url: "http://localhost:8000"
120
+ ```
121
+
122
+ Keys come **only** from config/env — never hardcoded, never committed (`.gitignore` covers `config.yaml`, `.env`, `*.key`, and the local DB).
123
+
124
+ ## Dunning templates
125
+
126
+ `~/.invoiceguard/templates/day1.md`, `day7.md`, `day15.md` — plain markdown with `{variables}`:
127
+
128
+ `{client_name}` `{project_title}` `{amount}` `{due_date}` `{days_overdue}` `{late_fee_pct}` `{pay_url}`
129
+
130
+ Edit them freely; `check-due` picks them up on the next run. Stage timing: day1 fires at ≥1 day overdue, day7 at ≥7, day15 at ≥15 — earliest unsent due stage wins, one email per invoice per run.
131
+
132
+ ## Database schema (contract with the dashboard app)
133
+
134
+ SQLite, default `~/.invoiceguard/invoiceguard.db`. The dashboard app reads/writes these exact tables — column names and types are frozen; additive migrations only:
135
+
136
+ ```sql
137
+ CREATE TABLE clients(id INTEGER PRIMARY KEY, name TEXT NOT NULL, email TEXT, created_at TEXT NOT NULL);
138
+ CREATE TABLE projects(id INTEGER PRIMARY KEY, client_id INTEGER NOT NULL REFERENCES clients(id), title TEXT NOT NULL, amount_cents INTEGER NOT NULL, currency TEXT NOT NULL DEFAULT 'USD', deposit_pct REAL NOT NULL DEFAULT 50.0, late_fee_pct REAL NOT NULL DEFAULT 1.5, late_fee_grace_days INTEGER NOT NULL DEFAULT 15, contract_md TEXT NOT NULL, contract_ack INTEGER NOT NULL DEFAULT 0, contract_ack_at TEXT, created_at TEXT NOT NULL);
139
+ CREATE TABLE invoices(id INTEGER PRIMARY KEY, project_id INTEGER NOT NULL REFERENCES projects(id), kind TEXT NOT NULL, amount_cents INTEGER NOT NULL, currency TEXT NOT NULL DEFAULT 'USD', status TEXT NOT NULL DEFAULT 'draft', stripe_url TEXT, stripe_session_id TEXT, due_date TEXT, sent_at TEXT, paid_at TEXT, created_at TEXT NOT NULL);
140
+ CREATE TABLE dunning_events(id INTEGER PRIMARY KEY, invoice_id INTEGER NOT NULL REFERENCES invoices(id), stage TEXT NOT NULL, sent_at TEXT NOT NULL);
141
+ ```
142
+
143
+ kinds: `deposit | milestone | final`. statuses: `draft | sent | paid | overdue | void`. stages: `day1 | day7 | day15`.
144
+
145
+ ## Web dashboard
146
+
147
+ `invoiceguard dashboard` launches the web dashboard for real — uvicorn serving
148
+ `invoiceguard.web.main:app` (default `http://127.0.0.1:8000`, `--port` to
149
+ change it). It shares this SQLite database: invoice list with status filters
150
+ and escalation stages, per-invoice detail with a chronological timeline, and
151
+ the `POST /webhooks/stripe` endpoint that marks invoices paid when Stripe
152
+ reports a completed checkout session.
153
+
154
+ Quick webhook smoke test (no network — the payload is signed locally):
155
+
156
+ ```bash
157
+ INVOICEGUARD_DB=/tmp/ig-demo.db .venv/bin/python seed_demo.py --fresh
158
+ INVOICEGUARD_DB=/tmp/ig-demo.db INVOICEGUARD_STRIPE_WEBHOOK_SECRET=whsec_test_x \
159
+ .venv/bin/invoiceguard dashboard
160
+ # -> http://127.0.0.1:8000/ (Ctrl-C to stop)
161
+ ```
162
+
163
+ ## Docker
164
+
165
+ ```bash
166
+ docker compose up -d # CLI container, data in the invoiceguard-data volume
167
+ docker compose run --rm app check-due # one-off dunning scan
168
+ ```
169
+
170
+ Put secrets in a `.env` file next to `docker-compose.yml` (never committed): `INVOICEGUARD_STRIPE_SECRET_KEY`, `INVOICEGUARD_STRIPE_WEBHOOK_SECRET`, `INVOICEGUARD_SMTP_PASSWORD`. Port 8000 is exposed for the dashboard.
171
+
172
+ ## Running tests
173
+
174
+ ```bash
175
+ python -m venv .venv && .venv/bin/pip install -r requirements.txt && .venv/bin/pip install -e .
176
+ .venv/bin/python -m pytest tests/ -q
177
+ ```
178
+
179
+ 54 tests, all green (2026-10-02): contract clause rendering, dunning stage selection + idempotency, template rendering, webhook signature verification (real HMAC check, offline), Stripe link creation (mocked SDK, params asserted), CLI flows, dashboard integration (page rendering + offline webhook checks incl. the `invoiceguard_invoice_id` metadata-key regression and the webhook-secret resolution regression: `INVOICEGUARD_STRIPE_WEBHOOK_SECRET` env / config-file secret honored, placeholder rejected), and a full end-to-end (init → client → project → invoice → `check-due` against a real local SMTP server → assert email captured + `dunning_events` row written).
180
+
181
+ ## Limits of v1
182
+
183
+ - **No live Stripe call was verified in this build environment** — Stripe's connector isn't connected here. `invoice create` was verified with a mocked `stripe` SDK asserting the exact `PaymentLink.create` params (line items, price data, metadata); webhook handling was verified with **real** `stripe.Webhook.construct_event` signature verification using a test secret (works offline). You add your own test key (2 min, above) and the live path is standard Stripe API.
184
+ - **v1 acknowledgment is a checkbox, not a signature.** Paying the deposit link = the client accepted the terms; `contract_ack=1` records it. Real e-signature is roadmap.
185
+ - **Email deliverability is yours.** InvoiceGuard sends via *your* SMTP. Use a reputable provider (Gmail App Password, SendGrid, etc.) and warm up new addresses; check spam folders in testing.
186
+ - **Late-fee enforceability varies by jurisdiction.** The clause is a contractual starting point, not legal advice. Adjust `late_fee_pct` / grace days per project.
187
+
188
+ ## Roadmap
189
+
190
+ - **Real e-signature** — typed-name / drawn-signature capture on the contract, stored with the project.
191
+ - **SMS / WhatsApp escalation** — day-15 via message, not just email.
192
+ - **Agency mode** — multi-freelancer workspaces, per-client dunning policies.
193
+ - Late-fee accrual calculator + ledger on the dashboard.
194
+ - Partial payments / payment plans.
195
+
196
+ ## Changelog
197
+
198
+ Release history lives in [CHANGELOG.md](CHANGELOG.md) — newest first, no fluff.
199
+
200
+ ## License
201
+
202
+ Apache-2.0 — see [LICENSE](LICENSE).