- Make Server property nullable in Settings components (Index, Advanced, Updates) - Add conditional server loading: only load when not on cloud - Add null checks before using server for DNS validation and proxy configuration - Fix isInstanceAdmin() to check root team's pivot role directly instead of current team - Make root team (id=0) bypass subscription check on cloud - Remove isInstanceAdmin() from main middleware bypass: only settings/admin routes are exempted - Update isSubscribed() to only check isSubscriptionActive() for navbar consistency 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
119 lines
2.5 KiB
PHP
119 lines
2.5 KiB
PHP
<?php
|
|
|
|
use App\Models\Team;
|
|
use Stripe\Stripe;
|
|
|
|
function isSubscriptionActive()
|
|
{
|
|
return once(function () {
|
|
if (! isCloud()) {
|
|
return false;
|
|
}
|
|
$team = currentTeam();
|
|
if (! $team) {
|
|
return false;
|
|
}
|
|
// Root team (id=0) doesn't require subscription
|
|
if ($team->id === 0) {
|
|
return true;
|
|
}
|
|
$subscription = $team?->subscription;
|
|
|
|
if (is_null($subscription)) {
|
|
return false;
|
|
}
|
|
if (isStripe()) {
|
|
return $subscription->stripe_invoice_paid === true;
|
|
}
|
|
|
|
return false;
|
|
});
|
|
}
|
|
|
|
function isSubscriptionOnGracePeriod()
|
|
{
|
|
return once(function () {
|
|
$team = currentTeam();
|
|
if (! $team) {
|
|
return false;
|
|
}
|
|
$subscription = $team?->subscription;
|
|
if (! $subscription) {
|
|
return false;
|
|
}
|
|
if (isStripe()) {
|
|
return $subscription->stripe_cancel_at_period_end;
|
|
}
|
|
|
|
return false;
|
|
});
|
|
}
|
|
function subscriptionProvider()
|
|
{
|
|
return config('subscription.provider');
|
|
}
|
|
function isStripe()
|
|
{
|
|
return config('subscription.provider') === 'stripe';
|
|
}
|
|
function getStripeCustomerPortalSession(Team $team)
|
|
{
|
|
Stripe::setApiKey(config('subscription.stripe_api_key'));
|
|
$return_url = route('subscription.show');
|
|
$stripe_customer_id = data_get($team, 'subscription.stripe_customer_id');
|
|
if (! $stripe_customer_id) {
|
|
return null;
|
|
}
|
|
|
|
return \Stripe\BillingPortal\Session::create([
|
|
'customer' => $stripe_customer_id,
|
|
'return_url' => $return_url,
|
|
]);
|
|
}
|
|
function allowedPathsForUnsubscribedAccounts()
|
|
{
|
|
return [
|
|
'subscription/new',
|
|
'login',
|
|
'logout',
|
|
'force-password-reset',
|
|
'livewire/update',
|
|
'admin',
|
|
];
|
|
}
|
|
function allowedPathsForBoardingAccounts()
|
|
{
|
|
return [
|
|
...allowedPathsForUnsubscribedAccounts(),
|
|
'onboarding',
|
|
'livewire/update',
|
|
];
|
|
}
|
|
function allowedPathsForInvalidAccounts()
|
|
{
|
|
return [
|
|
'logout',
|
|
'verify',
|
|
'force-password-reset',
|
|
'livewire/update',
|
|
];
|
|
}
|
|
|
|
function updateStripeCustomerEmail(Team $team, string $newEmail): void
|
|
{
|
|
if (! isStripe()) {
|
|
return;
|
|
}
|
|
|
|
$stripe_customer_id = data_get($team, 'subscription.stripe_customer_id');
|
|
if (! $stripe_customer_id) {
|
|
return;
|
|
}
|
|
|
|
Stripe::setApiKey(config('subscription.stripe_api_key'));
|
|
|
|
\Stripe\Customer::update(
|
|
$stripe_customer_id,
|
|
['email' => $newEmail]
|
|
);
|
|
}
|