An open-source, self-hostable PaaS alternative to Vercel, Heroku & Netlify that lets you easily deploy static sites, databases, full-stack applications and 360+ one-click services on your own servers.
PHP coolifydatabasesdeploymentdockerdocker-composeinertiajslaravelmariadbmysqlnextjsnodejsphppostgresredisself-hostedself-hostingserverstatic-sitesveltesvelte5
move subscription to livewire + show manage subscription button for people already subscribed once
Andras Bacsaia4f1fcba5820
diff --git a/app/Http/Controllers/Controller.php b/app/Http/Controllers/Controller.phpindex 0f4934846d..a2978e2eea 100644--- a/app/Http/Controllers/Controller.php+++ b/app/Http/Controllers/Controller.php@@ -46,15 +46,6 @@ class Controller extends BaseController}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.phpnew file mode 100644index 0000000000..ff028f68fe--- /dev/null+++ b/app/Http/Livewire/Subscription/Show.php@@ -0,0 +1,30 @@+<?php++namespace App\Http\Livewire\Subscription;++use App\Models\InstanceSettings;+use Livewire\Component;++class Show extends Component+{+ public InstanceSettings $settings;+ public bool $alreadySubscribed = false;+ public function mount() {+ if (!isCloud()) {+ return redirect('/');+ }+ $this->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.phpindex 3369776f00..130654db56 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.phpnew file mode 100644index 0000000000..a0a096a917--- /dev/null+++ b/resources/views/livewire/subscription/show.blade.php@@ -0,0 +1,49 @@+@if ($settings->is_resale_license_active)+ @if (auth()->user()->isAdminFromSession())+ <div class="flex justify-center mx-10">+ <div x-data>+ <div class="flex gap-2">+ <h1>Subscription</h1>+ <livewire:switch-team />+ @if (subscriptionProvider() === 'stripe' && $alreadySubscribed)+ <x-forms.button wire:click='stripeCustomerPortal'>Manage My Subscription</x-forms.button>+ @endif+ </div>+ <div class="flex items-center pb-8">+ <span>Currently active team: <span+ class="text-warning">{{ session('currentTeam.name') }}</span></span>+ </div>+ @if (request()->query->get('cancelled'))+ <div class="mb-6 rounded alert alert-error">+ <svg xmlns="http://www.w3.org/2000/svg" class="w-6 h-6 stroke-current shrink-0" fill="none"+ viewBox="0 0 24 24">+ <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2"+ d="M10 14l2-2m0 0l2-2m-2 2l-2-2m2 2l2 2m7-2a9 9 0 11-18 0 9 9 0 0118 0z" />+ </svg>+ <span>Something went wrong with your subscription. Please try again or contact+ support.</span>+ </div>+ @endif++ @if (config('subscription.provider') !== null)+ <livewire:subscription.pricing-plans />+ @endif+ </div>+ </div>+ @else+ <div class="flex flex-col justify-center mx-10">+ <div class="flex gap-2">+ <h1>Subscription</h1>+ <livewire:switch-team />+ </div>+ <div class="flex items-center pb-8">+ <span>Currently active team: <span class="text-warning">{{ session('currentTeam.name') }}</span></span>+ </div>+ <div>You are not an admin or have been removed from this team. If this does not make sense, please <span+ class="text-white underline cursor-pointer" wire:click="help" onclick="help.showModal()">contact+ us</span>.</div>+ </div>+ @endif+@else+ <div class="px-10">Resale license is not active. Please contact your instance admin.</div>+@endifdiff --git a/resources/views/subscription/index.blade.php b/resources/views/subscription/index.blade.phpdeleted file mode 100644index d36f26c81c..0000000000--- a/resources/views/subscription/index.blade.php+++ /dev/null@@ -1,46 +0,0 @@-<x-layout-subscription>- @if ($settings->is_resale_license_active)- @if (auth()->user()->isAdminFromSession())- <div class="flex justify-center mx-10">- <div x-data>- <div class="flex gap-2">- <h1>Subscription</h1>- <livewire:switch-team />- </div>- <div class="flex items-center pb-8">- <span>Currently active team: <span- class="text-warning">{{ session('currentTeam.name') }}</span></span>- </div>- @if (request()->query->get('cancelled'))- <div class="mb-6 rounded alert alert-error">- <svg xmlns="http://www.w3.org/2000/svg" class="w-6 h-6 stroke-current shrink-0" fill="none"- viewBox="0 0 24 24">- <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2"- d="M10 14l2-2m0 0l2-2m-2 2l-2-2m2 2l2 2m7-2a9 9 0 11-18 0 9 9 0 0118 0z" />- </svg>- <span>Something went wrong with your subscription. Please try again or contact- support.</span>- </div>- @endif- @if (config('subscription.provider') !== null)- <livewire:subscription.pricing-plans />- @endif- </div>- </div>- @else- <div class="flex flex-col justify-center mx-10">- <div class="flex gap-2">- <h1>Subscription</h1>- <livewire:switch-team />- </div>- <div class="flex items-center pb-8">- <span>Currently active team: <span- class="text-warning">{{ session('currentTeam.name') }}</span></span>- </div>- <div>You are not an admin or have been removed from this team. If this does not make sense, please <span class="text-white underline cursor-pointer" wire:click="help" onclick="help.showModal()">contact us</span>.</div>- </div>- @endif- @else- <div class="px-10" >Resale license is not active. Please contact your instance admin.</div>- @endif-</x-layout-subscription>diff --git a/routes/web.php b/routes/web.phpindex 89b37fdce4..8fde48405d 100644--- a/routes/web.php+++ b/routes/web.php@@ -18,6 +18,7 @@ use App\Http\Livewire\Server\Destination\Show as DestinationShow;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(['auth', 'verified'])->group(function () {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');