Skip to content

Refactor Subscription model to properly handle canceled status#1798

Closed
Diddyy wants to merge 1 commit intolaravel:16.xfrom
Diddyy:16.x
Closed

Refactor Subscription model to properly handle canceled status#1798
Diddyy wants to merge 1 commit intolaravel:16.xfrom
Diddyy:16.x

Conversation

@Diddyy
Copy link
Copy Markdown
Contributor

@Diddyy Diddyy commented Nov 3, 2025

Summary

This pull request refines the subscription status logic to ensure that the stripe_status field is treated as the source of truth when determining whether a subscription is active, canceled, or within a grace or trial period.

Currently, subscriptions canceled directly via Stripe (for example, when a test clock is canceled or when a subscription is immediately canceled during a trial) may still appear as valid within the application. This happens because the stripe_status field isn't consistently considered in status validation methods.

Changes

  • canceled() — Now checks stripe_status before other attributes (ends_at) for clearer intent and correctness.
  • onTrial() / onGracePeriod() — Refactored to use early returns for readability and to align with Laravel’s style conventions.
  • Scope Methods — Updated to mirror the instance methods for consistent behavior between query and model contexts.
  • Tests — Added dedicated tests covering:
    • Subscriptions canceled via Stripe’s API or test clocks.
    • Immediate cancellations during trial periods.
    • Edge cases around ends_at and trial_ends_at.

This change ensures that:

  • The subscription status reflects the true state in Stripe.
  • Users no longer retain access after cancellation.
  • Trial and grace periods behave consistently even when canceled early.
  • Code readability and maintainability are improved with clearer control flow.

All existing behavior for active and scheduled-cancellation subscriptions remains unchanged.

Related Issues

#1550 #1791

- Update canceled() to check stripe_status first (source of truth)
- Refactor onTrial() and onGracePeriod() to use early returns for clarity
- Align scope methods with instance methods for consistency
- Add comprehensive tests for canceled status scenarios including test clock cases
- Follow Laravel conventions: early returns, single responsibility, consistent formatting
@taylorotwell
Copy link
Copy Markdown
Member

Thanks for your pull request to Laravel!

Unfortunately, I'm going to delay merging this code for now. To preserve our ability to adequately maintain the framework, we need to be very careful regarding the amount of code we include.

If applicable, please consider releasing your code as a package so that the community can still take advantage of your contributions!

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.

2 participants