Skip to content

feat(epic-web): leave invoices paid after the cutover to Course Builder - #1920

Merged
Creeland merged 3 commits into
mainfrom
creeland/epw-invoice-paid-at-cutoff
Nov 18, 2026
Merged

Creeland merged 3 commits into
mainfrom
creeland/epw-invoice-paid-at-cutoff

Conversation

@Creeland

Copy link
Copy Markdown
Contributor

What

stripe-invoice-paid now decides, right after re-fetching the invoice and before reading the catalog or writing anything, whether this app owns it:

  • EPIC_WEB_INVOICE_CUTOVER_AT unset → unchanged behaviour: every paid one-off Epic Web invoice is fulfilled here.
  • Set (exactly YYYY-MM-DDTHH:MM[:SS[.mmm]]Z, e.g. 2026-12-08T15:05:00Z, the same format Course Builder accepts) and the invoice's status_transitions.paid_at is at or after it → returns {kind: 'ignore', reason: 'owned-by-course-builder', paidAt, cutoverAt}; Course Builder fulfils it.
  • Set and paid before it → fulfilled here, as today.
  • Set but in any other form (including empty, numeric offsets such as +00:00, and impossible dates such as 2026-02-30) → the run fails loudly (retriable, so a fix is picked up); it never silently picks a side.
  • A paid invoice without paid_at → the run fails without retry; we don't guess.

PaidInvoiceSchema now parses status_transitions.paid_at.

Why

During the Epic Web move to Course Builder both apps receive invoice.paid / invoice.payment_succeeded from the same Stripe account, and team invoices are created by hand in the dashboard, so there is no origin marker to split on (unlike checkout sessions, see #1919). With both handlers live, every invoice would be fulfilled twice: two purchases, twice the seats, two welcome emails.

The split is by when the invoice was paid, against one cutoff both apps carry in the same variable. paid_at is set once and never changes, and both handlers decide on the re-fetched invoice, so each invoice has exactly one owner regardless of deploy order, retries or redeliveries. Course Builder's half (ignore when the variable is unset or paid_at < cutoff) lands separately.

Safety

  • Inert until the variable is set: no behaviour change on merge.
  • The decision is a memoized step, so a variable changed mid-run can't flip it after a purchase is written.
  • Set the variable on both apps with the same value, and on Course Builder before (or together with) legacy. Until Course Builder honours it, an invoice paid after the cutoff would be fulfilled by nobody.

Tests

  • lib/invoice-fulfilment.test.ts: 32 new cases (boundaries, millisecond cutoff, the accepted forms and 15 rejected ones, mirroring Course Builder's parser tests so both apps accept exactly the same strings, 4 missing-paid_at shapes, unpaid invoice, schema).
  • New inngest/functions/stripe/invoice-paid.test.ts: 5 handler cases. An ignored invoice runs only load invoice + decide owner, with no catalog read and no write or event; before the cutoff and unset still fulfil; misconfiguration fails without reading or writing.
  • jest (epic-web): 63/63. tsc --noEmit: clean.

Not for merge without review; the cutoff value is chosen separately.

The Course Builder half is on badass-courses/course-builder branch creeland/epw-invoice-cutoff-on-1199 (a patch on top of course-builder#1199).

🤖 Generated with Claude Code

Both this app and the Course Builder app fulfil a paid one-off Epic Web
invoice, and both Stripe endpoints stay live through the migration, so
each invoice would be fulfilled twice. Invoices are created by hand and
carry no app marker.

Ownership is split by when the invoice was paid, against one cutoff
both apps read from EPIC_WEB_INVOICE_CUTOVER_AT (ISO-8601 UTC, trailing
Z). With the variable set, an invoice paid at or after it is ignored
here (owned-by-course-builder). Unset keeps today's behaviour. A
malformed value, or a paid invoice with no paid_at, fails the run
instead of picking a side.

Inert until the variable is set.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@vercel

vercel Bot commented Nov 16, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
badass-turbo Ready Ready Preview Nov 18, 2026 10:34pm UTC
epic-react-v1 Ready Ready Preview Nov 18, 2026 10:34pm UTC
epic-web Ready Ready Preview Nov 18, 2026 10:34pm UTC
testing-javascript Ready Ready Preview Nov 18, 2026 10:34pm UTC
total-typescript-turbo Ready Ready Preview Nov 18, 2026 10:34pm UTC

This branch was successfully deployed

5 active deployments
Preview – epic-web — 91f06bf0 Deployed Nov 18, 2026 by vercel[bot]
Preview – epic-react-v1 — 91f06bf0 Deployed Nov 18, 2026 by vercel[bot]
Preview – total-typescript-turbo — 91f06bf0 Deployed Nov 18, 2026 by vercel[bot]
Preview – badass-turbo — 91f06bf0 Deployed Nov 18, 2026 by vercel[bot]
Preview – testing-javascript — 91f06bf0 Deployed Nov 18, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant