fix(billing): admin sync reads current_period_start from items.data[0] (Stripe API ≥ 2025-08-27)#3733
Conversation
…≥ 2025-08-27) syncOrgFromStripe was reading current_period_start from the top-level Stripe subscription object, which no longer exists on API version ≥ 2025-08-27. The field moved to items.data[0].current_period_start. After an admin force-sync, currentPeriodStart was written as null, silently dropping that subscription from the weekly-reset sweep (findAllDueForResetByLastReset filters null out). Mirror the dual-read fallback already used by the webhook handler: items.data[0].current_period_start ?? current_period_start (top-level). Fixes #3727.
|
Warning Review limit reached
More reviews will be available in 33 minutes and 53 seconds. Learn how PR review limits work. Your organization has run out of usage credits. Purchase more in the billing tab. ⌛ How to resolve this issue?After more reviews become available, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available. Please see our Fair Usage Limits Policy for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: ASSERTIVE Plan: Pro Run ID: 📒 Files selected for processing (2)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #3733 +/- ##
=======================================
Coverage 89.89% 89.89%
=======================================
Files 148 148
Lines 4888 4889 +1
Branches 1532 1533 +1
=======================================
+ Hits 4394 4395 +1
Misses 389 389
Partials 105 105
Flags with carried forward coverage won't be shown. Click here to find out more. Continue to review full report in Codecov by Sentry.
🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Pull request overview
Fixes a bug in admin Stripe sync where current_period_start was read only from the top-level Stripe subscription, which is absent on Stripe API ≥ 2025-08-27 (the repo pins 2026-04-22.dahlia). This caused currentPeriodStart to be written as null, silently dropping the subscription from the weekly-reset sweep. The fix mirrors the existing dual-read pattern used in the webhook handler.
Changes:
- Dual-read
current_period_startfromitems.data[0]first, falling back to top-level insyncOrgFromStripe. - Added unit tests for both the new-API path (items-only) and legacy fallback (top-level).
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| modules/billing/services/billing.admin.service.js | Adds dual-read fallback for current_period_start matching webhook/service patterns. |
| modules/billing/tests/billing.admin.service.unit.tests.js | Adds two unit tests covering items-only and top-level fallback paths. |
Summary
syncOrgFromStripewas readingcurrent_period_startdirectly from the top-level Stripe subscription object, which is absent on Stripe API ≥ 2025-08-27 (the repo uses2026-04-22.dahlia). The field moved toitems.data[0].current_period_start.currentPeriodStartwas written asnull, silently dropping that subscription from the weekly-reset sweep (findAllDueForResetByLastResetfilterscurrentPeriodStart: { $ne: null }).items.data[0].current_period_start ?? current_period_start(top-level).Closes #3727.
Changes
modules/billing/services/billing.admin.service.js— dual-read forcurrent_period_startinsyncOrgFromStripe(3 lines)modules/billing/tests/billing.admin.service.unit.tests.js— 2 new tests: items-only path (new API) + top-level fallback (legacy API)Test plan
billing.admin.service.unit.tests.js— new test: Stripe sub with period only initems.data[0]→currentPeriodStartis non-null after syncbilling.admin.service.unit.tests.js— new test: Stripe sub with period only at top-level →currentPeriodStartis correct (legacy fallback)npm testgreen)npm run lint— ESLint: No issues found)