Repository navigation
fix(core): read the Stripe subscription period from its items - #136
Merged
cavewebs merged 1 commit intoDec 3, 2026
Merged
Conversation
Stripe API versions from 2025-03-31 moved `current_period_start` and `current_period_end` from the subscription onto each subscription item. `upsertFromStripe` only read the subscription's own fields, so on current versions both fell back to "now": the admin showed the period ending the day it started, and the cancel dialog said access continued until today. The period now comes from the item (the one that ends first, if there are several), then the subscription's own fields for older API versions, then the stored period, and only then "now". 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 API version 2025-03-31, Stripe sends
current_period_startandcurrent_period_endon each subscription item instead of on the subscription.upsertFromStripereads them from the subscription only, so on current API versions both are missing and fall back to "now". Found while testing a shop end to end: a subscription paid on 1 December showed "1 Dec → 1 Dec" in the admin, and the cancel-at-period-end dialog said "Access continues until" that same day, while Stripe would end it a month later.Fix
In
upsertFromStripethe period now comes from, in order:The
StripeSubscriptiontype gains the item-level fields, and the top-level ones become optional.Tests
New
packages/core/test/stripe-subscription-period.test.ts, 4 tests, each through the real webhook route with a signedcustomer.subscription.updated:3 fail without the fix; the older-API test passes both ways, as intended. Full suite: core 364 pass (plus the 4 local
routing-response-adapterfailures: the EmDash patch isn't applied in a fresh worktree; they pass on CI), paystack 105, lite 144. Core typecheck and Biome lint clean.Compatibility
No change for accounts on API versions before 2025-03-31. Nothing else reads the top-level fields.
Review points
upsertInvoiceFromStripealso moves the period oninvoice.paid, fromperiod_start/period_end; that is untouched.invoice.subscriptionunderinvoice.parent.subscription_details.subscription. I haven't checked how that affectsinvoice.paidhandling here.Works on a real store once #127 merges: until
customers.stripeCustomerIdis indexed,customer.subscription.*webhooks fail before they reach this code. The code doesn't depend on #127 and merges on its own.