Skip to content

fix(minting): read current_period_end from subscription item#534

Open
blove wants to merge 2 commits into
mainfrom
claude/fix-subscription-period-end
Open

fix(minting): read current_period_end from subscription item#534
blove wants to merge 2 commits into
mainfrom
claude/fix-subscription-period-end

Conversation

@blove
Copy link
Copy Markdown
Contributor

@blove blove commented May 25, 2026

Summary

Stripe API `2026-04-22.dahlia` moved `current_period_end` / `current_period_start` from the `Subscription` object to each `SubscriptionItem`. Our handler still read the legacy subscription-level field, which is now always `null` — so every new `customer.subscription.created` event 500'd with `subscription has no current_period_end`.

This PR reads the item-level field first, falls back to the legacy subscription-level field (replayed historical events, older API versions).

Smoke

Verified live in test mode with a Team annual subscription: handler now mints, upserts, and emails a token with `expires_at` matching Stripe's `item.current_period_end`.

🤖 Generated with Claude Code

blove and others added 2 commits May 24, 2026 20:49
Ran scripts/stripe/sync-products.ts against the live Stripe test-mode
account after PR #532 landed. The script created 4 recurring prices
(monthly + annual × developer_seat + team) and archived the prior
one-time-payment prices.

Operational follow-ups completed in parallel:
- DB migration 0002 applied to the minting Neon DB
  (stripe_payment_id → stripe_subscription_id)
- Webhook endpoint we_1TZcsHGYRsLErhxbdN2JTFTr enabled_events updated:
  customer.subscription.{created,updated,deleted}, invoice.paid,
  charge.refunded (dropped checkout.session.completed)

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
… sub object

Stripe API version 2026-04-22 (dahlia) moved `current_period_end` and
`current_period_start` from the Subscription object to each SubscriptionItem.
The handler was reading the legacy subscription-level field, which is now
always null, causing `handleSubscriptionCreated` to throw with
`subscription <id> has no current_period_end` for every new subscription.

Read the item-level field first, fall back to the legacy subscription-level
field for replayed historical events or older API versions.

Verified with a live test-mode Team annual subscription
(sub_1Tapk3GYRsLErhxb3jnWnxPy): handler now mints + emails the license with
expires_at = 2027-05-25 (matches Stripe's item.current_period_end).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@vercel
Copy link
Copy Markdown

vercel Bot commented May 25, 2026

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

Project Deployment Actions Updated (UTC)
threadplane Ready Ready Preview, Comment May 25, 2026 4:24am

Request Review

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