diff --git a/app/Http/Controllers/Controller.php b/app/Http/Controllers/Controller.php index 0f4934846..a2978e2ee 100644 --- a/app/Http/Controllers/Controller.php +++ b/app/Http/Controllers/Controller.php @@ -46,15 +46,6 @@ public function link() } return redirect()->route('login')->with('error', 'Invalid credentials.'); } - public function subscription() - { - if (!isCloud()) { - abort(404); - } - return view('subscription.index', [ - 'settings' => InstanceSettings::get(), - ]); - } public function license() { diff --git a/app/Http/Livewire/Subscription/Show.php b/app/Http/Livewire/Subscription/Show.php new file mode 100644 index 000000000..ff028f68f --- /dev/null +++ b/app/Http/Livewire/Subscription/Show.php @@ -0,0 +1,30 @@ +settings = InstanceSettings::get(); + $this->alreadySubscribed = currentTeam()->subscription()->exists(); + } + public function stripeCustomerPortal() { + $session = getStripeCustomerPortalSession(currentTeam()); + if (is_null($session)) { + return; + } + return redirect($session->url); + } + public function render() + { + return view('livewire.subscription.show')->layout('layouts.subscription'); + } +} diff --git a/bootstrap/helpers/subscriptions.php b/bootstrap/helpers/subscriptions.php index 3369776f0..130654db5 100644 --- a/bootstrap/helpers/subscriptions.php +++ b/bootstrap/helpers/subscriptions.php @@ -110,7 +110,10 @@ function getStripeCustomerPortalSession(Team $team) { Stripe::setApiKey(config('subscription.stripe_api_key')); $return_url = route('team.index'); - $stripe_customer_id = $team->subscription->stripe_customer_id; + $stripe_customer_id = data_get($team,'subscription.stripe_customer_id'); + if (!$stripe_customer_id) { + return null; + } $session = \Stripe\BillingPortal\Session::create([ 'customer' => $stripe_customer_id, 'return_url' => $return_url, diff --git a/resources/views/livewire/subscription/show.blade.php b/resources/views/livewire/subscription/show.blade.php new file mode 100644 index 000000000..a0a096a91 --- /dev/null +++ b/resources/views/livewire/subscription/show.blade.php @@ -0,0 +1,49 @@ +@if ($settings->is_resale_license_active) + @if (auth()->user()->isAdminFromSession()) +
+
+
+

Subscription

+ + @if (subscriptionProvider() === 'stripe' && $alreadySubscribed) + Manage My Subscription + @endif +
+
+ Currently active team: {{ session('currentTeam.name') }} +
+ @if (request()->query->get('cancelled')) +
+ + + + Something went wrong with your subscription. Please try again or contact + support. +
+ @endif + + @if (config('subscription.provider') !== null) + + @endif +
+
+ @else +
+
+

Subscription

+ +
+
+ Currently active team: {{ session('currentTeam.name') }} +
+
You are not an admin or have been removed from this team. If this does not make sense, please contact + us.
+
+ @endif +@else +
Resale license is not active. Please contact your instance admin.
+@endif diff --git a/resources/views/subscription/index.blade.php b/resources/views/subscription/index.blade.php deleted file mode 100644 index d36f26c81..000000000 --- a/resources/views/subscription/index.blade.php +++ /dev/null @@ -1,46 +0,0 @@ - - @if ($settings->is_resale_license_active) - @if (auth()->user()->isAdminFromSession()) -
-
-
-

Subscription

- -
-
- Currently active team: {{ session('currentTeam.name') }} -
- @if (request()->query->get('cancelled')) -
- - - - Something went wrong with your subscription. Please try again or contact - support. -
- @endif - @if (config('subscription.provider') !== null) - - @endif -
-
- @else -
-
-

Subscription

- -
-
- Currently active team: {{ session('currentTeam.name') }} -
-
You are not an admin or have been removed from this team. If this does not make sense, please contact us.
-
- @endif - @else -
Resale license is not active. Please contact your instance admin.
- @endif -
diff --git a/routes/web.php b/routes/web.php index 89b37fdce..8fde48405 100644 --- a/routes/web.php +++ b/routes/web.php @@ -18,6 +18,7 @@ use App\Http\Livewire\Server\PrivateKey\Show as PrivateKeyShow; use App\Http\Livewire\Server\Proxy\Show as ProxyShow; use App\Http\Livewire\Server\Show; +use App\Http\Livewire\Subscription\Show as SubscriptionShow; use App\Http\Livewire\Waitlist\Index as WaitlistIndex; use App\Models\GithubApp; use App\Models\GitlabApp; @@ -133,7 +134,7 @@ Route::middleware(['throttle:force-password-reset'])->group(function () { Route::get('/force-password-reset', [Controller::class, 'force_passoword_reset'])->name('auth.force-password-reset'); }); - Route::get('/subscription', [Controller::class, 'subscription'])->name('subscription.index'); + Route::get('/subscription', SubscriptionShow::class)->name('subscription.index'); // Route::get('/help', Help::class)->name('help'); Route::get('/settings', [Controller::class, 'settings'])->name('settings.configuration'); Route::get('/settings/license', [Controller::class, 'license'])->name('settings.license');