Skip to content

fix(core): record Stripe subscription invoices on current API versions - #150

Merged
cavewebs merged 1 commit into
emdashCommerce:mainfrom
FIKANOVA:fix/stripe-invoice-parent
Dec 3, 2026
Merged

cavewebs merged 1 commit into
emdashCommerce:mainfrom
FIKANOVA:fix/stripe-invoice-parent

Conversation

@moset15

@moset15 moset15 commented Dec 3, 2026

Copy link
Copy Markdown
Contributor

Bug

From Stripe API version 2025-03-31, an invoice no longer has a top-level subscription: it names its subscription under parent.subscription_details.subscription. upsertInvoiceFromStripe starts with if (!inv.subscription) return null, so on current API versions every subscription invoice is ignored:

  • invoice.paid stores no invoice row, so the renewal email never goes out.
  • invoice.payment_failed (dunning) never marks the subscription past due from the invoice.

Found while testing a shop end to end: after several paid Stripe subscriptions, the shop had no subscription invoices at all.

There's a second problem on the same path. When an invoice was recorded, the subscription period was taken from the invoice's own period_start/period_end. Those aren't the subscription period: on the first invoice they're both the creation time.

Fix

  • invoiceSubscriptionId(inv) reads inv.subscription, or inv.parent.subscription_details.subscription.
  • invoiceSubscriptionPeriod(inv) takes the period from the invoice's subscription lines (lines.data[].period). It falls back to the invoice's own dates when there are no line periods and they span something.
  • The StripeInvoice type gains the optional parent and lines fields.

That's all of it: upsertInvoiceFromStripe uses the two helpers, and invoice.payment_failed goes through it too. No change to webhook.ts or checkout.ts.

Tests

New packages/core/test/stripe-invoice-parent.test.ts, 4 tests:

  • Both shapes: the subscription is found under parent, or at the top level.
  • The period: it comes from the subscription line, not the invoice's own dates.
  • A current-shape renewal invoice is recorded, and it moves the subscription's period.
  • An older-shape invoice is still recorded.

The recording test fails without the change. Core 364 pass; the 4 local routing-response-adapter failures pass on CI. Typecheck and Biome clean.

Also tested by hand on a running shop (EmDash 1.6, Stripe test mode): paid subscription checkouts now record their invoices, with the period running one interval from the payment.

Review points

From Stripe API 2025-03-31 an invoice names its subscription under
parent.subscription_details, not subscription, so upsertInvoiceFromStripe
returned early: invoice.paid and invoice.payment_failed were ignored (no
invoice rows, no renewal email, no past-due). Read either shape, and take
the period from the invoice's subscription lines.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@cavewebs
cavewebs merged commit 38a989b into emdashCommerce:main Dec 3, 2026
11 checks passed
@moset15
moset15 deleted the fix/stripe-invoice-parent branch December 6, 2026 01:36
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.

2 participants