feat: migrate legacy subscription checks to unified payment system
- Replace Laravel Cashier methods with new subscription system - Remove session-based subscription checking in bulk components - Update Dashboard.php to use PaymentOrchestrator for provider-agnostic sync - Maintain backward compatibility with existing Stripe subscriptions - Improve performance by eliminating session overhead - Add automatic migration of legacy subscriptions to new system BREAKING CHANGE: Subscription checking now uses unified payment system instead of Laravel Cashier methods
This commit is contained in:
@@ -39,6 +39,7 @@ class Subscription extends Model
|
||||
'migration_source',
|
||||
'migration_date',
|
||||
'migration_reason',
|
||||
'created_at',
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
|
||||
@@ -40,6 +40,7 @@ class User extends Authenticatable implements FilamentUser, MustVerifyEmail
|
||||
protected $hidden = [
|
||||
'password',
|
||||
'remember_token',
|
||||
'level',
|
||||
];
|
||||
|
||||
/**
|
||||
@@ -166,11 +167,11 @@ class User extends Authenticatable implements FilamentUser, MustVerifyEmail
|
||||
return $this->hasOne(Subscription::class)
|
||||
->where(function ($query) {
|
||||
$query->where('status', 'active')
|
||||
->orWhere('status', 'trialing');
|
||||
->orWhere('status', 'trialing');
|
||||
})
|
||||
->where(function ($query) {
|
||||
$query->whereNull('ends_at')
|
||||
->orWhere('ends_at', '>', now());
|
||||
->orWhere('ends_at', '>', now());
|
||||
})
|
||||
->latest();
|
||||
}
|
||||
@@ -191,10 +192,10 @@ class User extends Authenticatable implements FilamentUser, MustVerifyEmail
|
||||
return $query->whereHas('subscriptions', function ($subscriptionQuery) {
|
||||
$subscriptionQuery->where(function ($q) {
|
||||
$q->where('status', 'active')
|
||||
->orWhere('status', 'trialing');
|
||||
->orWhere('status', 'trialing');
|
||||
})->where(function ($q) {
|
||||
$q->whereNull('ends_at')
|
||||
->orWhere('ends_at', '>', now());
|
||||
->orWhere('ends_at', '>', now());
|
||||
});
|
||||
});
|
||||
}
|
||||
@@ -206,7 +207,7 @@ class User extends Authenticatable implements FilamentUser, MustVerifyEmail
|
||||
{
|
||||
return $query->whereHas('subscriptions', function ($subscriptionQuery) {
|
||||
$subscriptionQuery->where('status', 'trialing')
|
||||
->where('trial_ends_at', '>', now());
|
||||
->where('trial_ends_at', '>', now());
|
||||
});
|
||||
}
|
||||
|
||||
@@ -217,9 +218,9 @@ class User extends Authenticatable implements FilamentUser, MustVerifyEmail
|
||||
{
|
||||
return $query->whereHas('subscriptions', function ($subscriptionQuery) {
|
||||
$subscriptionQuery->where('status', 'cancelled')
|
||||
->orWhere(function ($q) {
|
||||
$q->where('ends_at', '<=', now());
|
||||
});
|
||||
->orWhere(function ($q) {
|
||||
$q->where('ends_at', '<=', now());
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@@ -231,10 +232,10 @@ class User extends Authenticatable implements FilamentUser, MustVerifyEmail
|
||||
return $query->whereDoesntHave('subscriptions', function ($subscriptionQuery) {
|
||||
$subscriptionQuery->where(function ($q) {
|
||||
$q->where('status', 'active')
|
||||
->orWhere('status', 'trialing');
|
||||
->orWhere('status', 'trialing');
|
||||
})->where(function ($q) {
|
||||
$q->whereNull('ends_at')
|
||||
->orWhere('ends_at', '>', now());
|
||||
->orWhere('ends_at', '>', now());
|
||||
});
|
||||
});
|
||||
}
|
||||
@@ -246,10 +247,10 @@ class User extends Authenticatable implements FilamentUser, MustVerifyEmail
|
||||
{
|
||||
return $query->whereHas('subscriptions', function ($subscriptionQuery) use ($provider) {
|
||||
$subscriptionQuery->where('provider', $provider)
|
||||
->where(function ($q) {
|
||||
$q->whereNull('ends_at')
|
||||
->orWhere('ends_at', '>', now());
|
||||
});
|
||||
->where(function ($q) {
|
||||
$q->whereNull('ends_at')
|
||||
->orWhere('ends_at', '>', now());
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@@ -260,9 +261,9 @@ class User extends Authenticatable implements FilamentUser, MustVerifyEmail
|
||||
{
|
||||
return $query->whereHas('subscriptions', function ($subscriptionQuery) use ($days) {
|
||||
$subscriptionQuery->where('status', 'active')
|
||||
->whereNotNull('ends_at')
|
||||
->where('ends_at', '<=', now()->addDays($days))
|
||||
->where('ends_at', '>', now());
|
||||
->whereNotNull('ends_at')
|
||||
->where('ends_at', '<=', now()->addDays($days))
|
||||
->where('ends_at', '>', now());
|
||||
});
|
||||
}
|
||||
|
||||
@@ -274,11 +275,11 @@ class User extends Authenticatable implements FilamentUser, MustVerifyEmail
|
||||
return $this->subscriptions()
|
||||
->where(function ($query) {
|
||||
$query->where('status', 'active')
|
||||
->orWhere('status', 'trialing');
|
||||
->orWhere('status', 'trialing');
|
||||
})
|
||||
->where(function ($query) {
|
||||
$query->whereNull('ends_at')
|
||||
->orWhere('ends_at', '>', now());
|
||||
->orWhere('ends_at', '>', now());
|
||||
})
|
||||
->exists();
|
||||
}
|
||||
@@ -302,10 +303,10 @@ class User extends Authenticatable implements FilamentUser, MustVerifyEmail
|
||||
return $this->subscriptions()
|
||||
->where(function ($query) {
|
||||
$query->where('status', 'cancelled')
|
||||
->orWhere(function ($q) {
|
||||
$q->whereNotNull('ends_at')
|
||||
->orWhere(function ($q) {
|
||||
$q->whereNotNull('ends_at')
|
||||
->where('ends_at', '<=', now());
|
||||
});
|
||||
});
|
||||
})
|
||||
->exists();
|
||||
}
|
||||
@@ -421,7 +422,7 @@ class User extends Authenticatable implements FilamentUser, MustVerifyEmail
|
||||
'total_subscriptions' => $subscriptions->count(),
|
||||
'active_subscriptions' => $subscriptions->where(function ($sub) {
|
||||
return in_array($sub->status, ['active', 'trialing']) &&
|
||||
(!$sub->ends_at || $sub->ends_at->isFuture());
|
||||
(! $sub->ends_at || $sub->ends_at->isFuture());
|
||||
})->count(),
|
||||
'total_spent' => $this->getTotalSpent(),
|
||||
'current_plan' => $this->getCurrentPlan()?->name,
|
||||
|
||||
Reference in New Issue
Block a user