Skip to content

fix(billing): admin sync reads current_period_start from items.data[0] (Stripe API ≥ 2025-08-27)#3733

Merged
PierreBrisorgueil merged 1 commit into
masterfrom
fix/billing-admin-sync-period
May 29, 2026
Merged

fix(billing): admin sync reads current_period_start from items.data[0] (Stripe API ≥ 2025-08-27)#3733
PierreBrisorgueil merged 1 commit into
masterfrom
fix/billing-admin-sync-period

Conversation

@PierreBrisorgueil
Copy link
Copy Markdown
Contributor

Summary

  • syncOrgFromStripe was reading current_period_start directly from the top-level Stripe subscription object, which is absent on Stripe API ≥ 2025-08-27 (the repo uses 2026-04-22.dahlia). 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 currentPeriodStart: { $ne: null }).
  • Fix: mirror the dual-read fallback already used by the webhook handler — items.data[0].current_period_start ?? current_period_start (top-level).

Closes #3727.

Changes

  • modules/billing/services/billing.admin.service.js — dual-read for current_period_start in syncOrgFromStripe (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 in items.data[0]currentPeriodStart is non-null after sync
  • billing.admin.service.unit.tests.js — new test: Stripe sub with period only at top-level → currentPeriodStart is correct (legacy fallback)
  • All 1548 existing unit tests pass (npm test green)
  • Lint clean (npm run lint — ESLint: No issues found)

…≥ 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.
Copilot AI review requested due to automatic review settings May 29, 2026 09:04
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 29, 2026

Warning

Review limit reached

@PierreBrisorgueil, we couldn't start this review because you've reached your PR review rate limit.

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 @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

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 configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: ba1267a2-d5be-434d-8748-f1d5f0fb5894

📥 Commits

Reviewing files that changed from the base of the PR and between d42eb12 and 3322087.

📒 Files selected for processing (2)
  • modules/billing/services/billing.admin.service.js
  • modules/billing/tests/billing.admin.service.unit.tests.js
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/billing-admin-sync-period

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@codecov
Copy link
Copy Markdown

codecov Bot commented May 29, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 89.89%. Comparing base (f0e7a83) to head (3322087).
⚠️ Report is 2 commits behind head on master.

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           
Flag Coverage Δ
integration 60.07% <100.00%> (+<0.01%) ⬆️
unit 66.37% <100.00%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.


Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update d42eb12...3322087. Read the comment docs.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_start from items.data[0] first, falling back to top-level in syncOrgFromStripe.
  • 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.

@PierreBrisorgueil PierreBrisorgueil merged commit d093c86 into master May 29, 2026
9 checks passed
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.

[audit][P1][edge-case] billing: admin Stripe sync writes null period → sub dropped from weekly-reset sweep

2 participants