fix(billing): surface live cancelAt through getSubscription - #4023
Conversation
fetchSubscriptionDetails computed cancelAt from the live Stripe object but dropped it before returning, so getSubscription's merge kept the stale, DB-only value written by the last webhook. On reactivation (Stripe clears cancel_at, cancel_at_period_end stays false) a consumer reading cancelAt would see a cancellation that no longer exists until the webhook lands. Include cancelAt in the returned object so the live value overrides the persisted one, same treatment cancelAtPeriodEnd and currentPeriodEnd already get.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #4023 +/- ##
=======================================
Coverage 94.01% 94.01%
=======================================
Files 170 170
Lines 5810 5810
Branches 1859 1860 +1
=======================================
Hits 5462 5462
Misses 285 285
Partials 63 63
Flags with carried forward coverage won't be shown. Click here to find out more. Continue to review full report in Codecov by Harness.
🚀 New features to boost your workflow:
|
WalkthroughThe billing service now returns Stripe’s live ChangesBilling cancellation state
Estimated code review effort: 2 (Simple) | ~10 minutes Possibly related issues
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 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 |
Summary
fetchSubscriptionDetailsnow includes the already-computedcancelAtin the object it returns, sogetSubscription's merge overrides the persisted (DB) value with the live Stripe value — the same freshness treatmentcancelAtPeriodEndandcurrentPeriodEndalready receive.getSubscriptionmerges a livecancelAtPeriodEndwith a stale, DB-onlycancelAtwritten by the last webhook. Stripe represents a portal cancellation ascancel_at+canceled_at+ a cancellation reason, leavingcancel_at_period_endfalse — so a consumer readingcancelAtfor "this subscription is ending" sees a value Stripe already cleared after a reactivation, until the next webhook lands (or indefinitely if it's dropped/out of order).Scope
billingnonelowValidation
npm run lintnpm testGuardrails check
.env*,secrets/**, keys, tokens)Notes for reviewers
Summary by CodeRabbit