Repository navigation
fix(core): record Stripe subscription invoices on current API versions - #150
Merged
Merged
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Bug
From Stripe API version 2025-03-31, an invoice no longer has a top-level
subscription: it names its subscription underparent.subscription_details.subscription.upsertInvoiceFromStripestarts withif (!inv.subscription) return null, so on current API versions every subscription invoice is ignored:invoice.paidstores 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)readsinv.subscription, orinv.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.StripeInvoicetype gains the optionalparentandlinesfields.That's all of it:
upsertInvoiceFromStripeuses the two helpers, andinvoice.payment_failedgoes through it too. No change towebhook.tsorcheckout.ts.Tests
New
packages/core/test/stripe-invoice-parent.test.ts, 4 tests:parent, or at the top level.The recording test fails without the change. Core 364 pass; the 4 local
routing-response-adapterfailures 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
inv.payment_intent, which current API versions don't send either. fix(core): confirm Stripe subscription checkouts and keep the customer #138 adds an Invoice Payments lookup that could serve it. This PR doesn't touchpayment_intent, and it merges cleanly with feat(core): track Stripe renewal invoice refunds #147, fix(core): confirm Stripe subscription checkouts and keep the customer #138 and feat(flutterwave): Flutterwave payment provider package #107.