Plan changes prorated by hand
Finance works out each upgrade and downgrade in a spreadsheet.
Impact: Clinics were billed a few dollars wrong, and 64 disputed it in October.
All problemsData & Systems
Build the invoice engine for a SaaS billing system from a one-page spec.
Your mission · Build from a spec
Mossgate's two-person finance team bills from a spreadsheet and prorates every plan change by hand. October brought 64 billing disputes and $18,400 in credits written off. On January 12 clinics can change plans in the app themselves, and finance needs an engine that bills those changes correctly.
Finance works out each upgrade and downgrade in a spreadsheet.
Impact: Clinics were billed a few dollars wrong, and 64 disputed it in October.
A downgrade refund is noted in a comment and often never applied.
Impact: Clinics paid in full the next month and asked for their money back.
Every advance and change fails with NotImplementedError.
Impact: Self-serve plan changes cannot launch on January 12.
Edit the components marked “Your work”. The other components show where your changes fit.
| Field | Type | Notes |
|---|---|---|
price | integer >= 0 | Cents for one full period. 4900 is $49.00. |
interval | "month" | "year" | A month is 30 days, a year 365. |
| Field | Type | Notes |
|---|---|---|
account | string | The clinic, for example "clinic-0412". |
day | integer | The day the invoice is dated. |
lines | {kind, plan, amount}[] | kind is period, unused (negative) or remaining. |
due | integer | Cents the processor charges, never below 0. |
credit | integer | The account's credit after this invoice. |
| Field | Type | Notes |
|---|---|---|
day | integer | The new day. |
invoices | Invoice[] | Every renewal, by day and then account. |
ended | {account, day}[] | Cancelled subscriptions that reached their period end. |
config/plan-catalog.json The live catalog: Solo and Clinic, monthly and yearly, prices in cents. Arguments for Preview.{
"plans": {
"solo": {
"price": 4900,
"interval": "month"
},
"clinic": {
"price": 12900,
"interval": "month"
},
"solo-annual": {
"price": 49000,
"interval": "year"
},
"clinic-annual": {
"price": 129000,
"interval": "year"
}
}
}samples/three-clinics.json Three clinics over 90 days: an upgrade, a downgrade that leaves credit, a cancel, and a yearly plan moved to monthly.[
{
"plans": {
"solo": {
"price": 4900,
"interval": "month"
},
"clinic": {
"price": 12900,
"interval": "month"
},
"solo-annual": {
"price": 49000,
"interval": "year"
},
"clinic-annual": {
"price": 129000,
"interval": "year"
}
}
},
[
{
"op": "subscribe",
"account": "clinic-0412",
"plan": "solo"
},
{
"op": "subscribe",
"account": "clinic-0577",
"plan": "clinic"
},
{
"op": "subscribe",
"account": "clinic-0903",
"plan": "solo-annual"
},
{
"op": "advance",
"days": 12
},
{
"op": "change",
"account": "clinic-0412",
"plan": "clinic"
},
{
"op": "change",
"account": "clinic-0577",
"plan": "solo"
},
{
"op": "advance",
"days": 18
},
{
"op": "cancel",
"account": "clinic-0577"
},
{
"op": "change",
"account": "clinic-0903",
"plan": "clinic"
},
{
"op": "advance",
"days": 60
}
]
]samples/three-clinics-expected.json What the spec says those events return. clinic-0903's unused year pays for its next months.[
{"account": "clinic-0412", "day": 0, "lines": [{"kind": "period", "plan": "solo", "amount": 4900}], "due": 4900, "credit": 0},
{"account": "clinic-0577", "day": 0, "lines": [{"kind": "period", "plan": "clinic", "amount": 12900}], "due": 12900, "credit": 0},
{"account": "clinic-0903", "day": 0, "lines": [{"kind": "period", "plan": "solo-annual", "amount": 49000}], "due": 49000, "credit": 0},
{"day": 12, "invoices": [], "ended": []},
{"account": "clinic-0412", "day": 12, "lines": [{"kind": "unused", "plan": "solo", "amount": -2940}, {"kind": "remaining", "plan": "clinic", "amount": 7740}], "due": 4800, "credit": 0},
{"account": "clinic-0577", "day": 12, "lines": [{"kind": "unused", "plan": "clinic", "amount": -7740}, {"kind": "remaining", "plan": "solo", "amount": 2940}], "due": 0, "credit": 4800},
{"day": 30, "invoices": [{"account": "clinic-0412", "day": 30, "lines": [{"kind": "period", "plan": "clinic", "amount": 12900}], "due": 12900, "credit": 0}, {"account": "clinic-0577", "day": 30, "lines": [{"kind": "period", "plan": "solo", "amount": 4900}], "due": 100, "credit": 0}], "ended": []},
{"account": "clinic-0577", "state": "cancelling", "ends": 60},
{"account": "clinic-0903", "day": 30, "lines": [{"kind": "unused", "plan": "solo-annual", "amount": -44973}, {"kind": "period", "plan": "clinic", "amount": 12900}], "due": 0, "credit": 32073},
{"day": 90, "invoices": [{"account": "clinic-0412", "day": 60, "lines": [{"kind": "period", "plan": "clinic", "amount": 12900}], "due": 12900, "credit": 0}, {"account": "clinic-0903", "day": 60, "lines": [{"kind": "period", "plan": "clinic", "amount": 12900}], "due": 0, "credit": 19173}, {"account": "clinic-0412", "day": 90, "lines": [{"kind": "period", "plan": "clinic", "amount": 12900}], "due": 12900, "credit": 0}, {"account": "clinic-0903", "day": 90, "lines": [{"kind": "period", "plan": "clinic", "amount": 12900}], "due": 0, "credit": 6273}], "ended": [{"account": "clinic-0577", "day": 60}]}
]logs/billing-disputes-2026-10.log October disputes from support: full-month charges on upgrades, lost credit, renewals on the wrong day.2026-10-03T14:12:40Z support dispute account=clinic-0218 reason="upgraded mid-month, charged a full month of Clinic" amount_usd=58.47 2026-10-09T09:31:05Z support dispute account=clinic-1170 reason="downgrade credit never applied" amount_usd=53.33 2026-10-14T16:02:19Z support dispute account=clinic-0663 reason="renewed on the 1st, plan started on the 17th" amount_usd=129.00 2026-10-21T11:47:52Z support dispute account=clinic-0412 reason="proration off by one cent on two lines" amount_usd=0.01 2026-10-28T08:20:11Z support dispute account=clinic-0981 reason="cancelled, still billed next month" amount_usd=49.00
metrics/billing-disputes-2026.csv Invoices, plan changes, disputes and credits written off per month since June.month,invoices,plan_changes,disputes,credits_written_off_usd 2026-06,2104,118,21,4260 2026-07,2151,131,27,6105 2026-08,2199,147,33,8890 2026-09,2246,162,45,12740 2026-10,2290,184,64,18400
TASK-201 Read docs/spec.md and decide what the ledger stores Reported by Imani (billing)
Expected NOTES.md says what is stored for each account and subscription, and why credit lives apart from the subscription.
Actual Billing has a clock, subscriptions and credit, but nothing writes down what a renewal or a change does, and that code is a stub.
TASK-202 Renewals: advance the clock and invoice every period that ends Reported by Imani (billing)
Expected Three renewal invoices, on days 30, 60 and 90.
Actual The advance fails with NotImplementedError: "Implement Billing.advance using the request contract".
TASK-203 Then proration and plan changes, then credit, then cancels Reported by Rafael (finance)
Expected Every result matches the expected file to the cent, clinic-0577 ends on day 60, and the short advances give the same invoices as the long one.
Actual The first change fails with NotImplementedError: "Implement Billing.change using the request contract".
TASK-204 Write down anything you chose to leave out or would do next Reported by Rafael (finance)
Expected A short list of what the engine does not handle yet and what you would build next, with a reason for each.
Actual NOTES.md has no entry.
Scores use evidence from your session. A short or incomplete session may not provide enough evidence for every skill. See a sample scorecard
Build the invoice engine for a SaaS company that sells monthly and yearly plans. Plans renew, clinics change plan in the middle of a period, and some cancel. The spec is one page and money is in whole cents. Start with renewals and grow it. Use the AI assistant however you like, and tell me your data model before you ask it for code.