From f78fd212bbc14a9a1501f40b6a7055322356b104 Mon Sep 17 00:00:00 2001 From: Andras Bacsai Date: Fri, 23 Feb 2024 12:59:14 +0100 Subject: [PATCH] fix: subscription / plan switch, etc --- app/Livewire/Subscription/Index.php | 9 +- app/Livewire/Subscription/Show.php | 3 + app/Models/Subscription.php | 6 +- app/Models/User.php | 3 + config/subscription.php | 6 ++ docker-compose.prod.yml | 6 ++ resources/views/livewire/dashboard.blade.php | 86 +++++++++---------- .../livewire/subscription/actions.blade.php | 1 - .../livewire/subscription/show.blade.php | 13 +-- routes/web.php | 2 +- 10 files changed, 74 insertions(+), 61 deletions(-) diff --git a/app/Livewire/Subscription/Index.php b/app/Livewire/Subscription/Index.php index afc3729c6..4f36750c7 100644 --- a/app/Livewire/Subscription/Index.php +++ b/app/Livewire/Subscription/Index.php @@ -10,14 +10,19 @@ class Index extends Component { public InstanceSettings $settings; public bool $alreadySubscribed = false; - public function mount() { + public function mount() + { if (!isCloud()) { return redirect(RouteServiceProvider::HOME); } + if (data_get(currentTeam(), 'subscription')) { + return redirect()->route('subscription.show'); + } $this->settings = InstanceSettings::get(); $this->alreadySubscribed = currentTeam()->subscription()->exists(); } - public function stripeCustomerPortal() { + public function stripeCustomerPortal() + { $session = getStripeCustomerPortalSession(currentTeam()); if (is_null($session)) { return; diff --git a/app/Livewire/Subscription/Show.php b/app/Livewire/Subscription/Show.php index 8069b98a6..ad677ce53 100644 --- a/app/Livewire/Subscription/Show.php +++ b/app/Livewire/Subscription/Show.php @@ -11,6 +11,9 @@ public function mount() if (!isCloud()) { return redirect()->route('dashboard'); } + if (!data_get(currentTeam(), 'subscription')) { + return redirect()->route('subscription.index'); + } } public function render() { diff --git a/app/Models/Subscription.php b/app/Models/Subscription.php index cd35dc477..668394bc4 100644 --- a/app/Models/Subscription.php +++ b/app/Models/Subscription.php @@ -30,8 +30,7 @@ public function type() if (in_array($subscription, $ultimate)) { return 'ultimate'; } - } - if (isStripe()) { + } else if (isStripe()) { if (!$this->stripe_plan_id) { return 'zero'; } @@ -55,7 +54,8 @@ public function type() }; })->first(); if ($stripePlanId) { - return Str::of($stripePlanId)->after('stripe_price_id_')->before('_')->lower(); + raY($stripePlanId); + return str($stripePlanId)->after('stripe_price_id_')->before('_')->lower(); } } return 'zero'; diff --git a/app/Models/User.php b/app/Models/User.php index ad5120a3d..f8507a6b9 100644 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -159,6 +159,9 @@ public function otherTeams() public function role() { + if (data_get($this, 'pivot')) { + return $this->pivot->role; + } return auth()->user()->teams->where('id', currentTeam()->id)->first()->pivot->role; } } diff --git a/config/subscription.php b/config/subscription.php index 677689ff1..96a9a8e1c 100644 --- a/config/subscription.php +++ b/config/subscription.php @@ -13,6 +13,12 @@ 'stripe_price_id_ultimate_yearly' => env('STRIPE_PRICE_ID_ULTIMATE_YEARLY', null), 'stripe_excluded_plans' => env('STRIPE_EXCLUDED_PLANS', null), + 'stripe_price_id_basic_monthly_old' => env('STRIPE_PRICE_ID_BASIC_MONTHLY_OLD', null), + 'stripe_price_id_basic_yearly_old' => env('STRIPE_PRICE_ID_BASIC_YEARLY_OLD', null), + 'stripe_price_id_pro_monthly_old' => env('STRIPE_PRICE_ID_PRO_MONTHLY_OLD', null), + 'stripe_price_id_pro_yearly_old' => env('STRIPE_PRICE_ID_PRO_YEARLY_OLD', null), + 'stripe_price_id_ultimate_monthly_old' => env('STRIPE_PRICE_ID_ULTIMATE_MONTHLY_OLD', null), + 'stripe_price_id_ultimate_yearly_old' => env('STRIPE_PRICE_ID_ULTIMATE_YEARLY_OLD', null), // Paddle 'paddle_vendor_id' => env('PADDLE_VENDOR_ID', null), diff --git a/docker-compose.prod.yml b/docker-compose.prod.yml index 407be245b..6a80dab47 100644 --- a/docker-compose.prod.yml +++ b/docker-compose.prod.yml @@ -57,6 +57,12 @@ services: - STRIPE_PRICE_ID_PRO_YEARLY - STRIPE_PRICE_ID_ULTIMATE_MONTHLY - STRIPE_PRICE_ID_ULTIMATE_YEARLY + - STRIPE_PRICE_ID_BASIC_MONTHLY_OLD + - STRIPE_PRICE_ID_BASIC_YEARLY_OLD + - STRIPE_PRICE_ID_PRO_MONTHLY_OLD + - STRIPE_PRICE_ID_PRO_YEARLY_OLD + - STRIPE_PRICE_ID_ULTIMATE_MONTHLY_OLD + - STRIPE_PRICE_ID_ULTIMATE_YEARLY_OLD - STRIPE_EXCLUDED_PLANS - PADDLE_VENDOR_ID - PADDLE_WEBHOOK_SECRET diff --git a/resources/views/livewire/dashboard.blade.php b/resources/views/livewire/dashboard.blade.php index 7b5ea1417..e8ba873ea 100644 --- a/resources/views/livewire/dashboard.blade.php +++ b/resources/views/livewire/dashboard.blade.php @@ -5,7 +5,7 @@

Dashboard

Your self-hosted environment
@if (request()->query->get('success')) -
+
@endif @if ($projects->count() === 0 && $servers->count() === 0) - No resources found. Add your first server / private key here. + No resources found. Add your first server & private key here or go to the boarding page. @endif @if ($projects->count() > 0)

Projects

- @endif - @if ($projects->count() === 1) -
- @else -
- @endif - @foreach ($projects as $project) -
- @if (data_get($project, 'environments')->count() === 1) - -
{{ $project->name }}
-
- {{ $project->description }}
-
+ @if ($projects->count() === 1) +
@else - -
{{ $project->name }}
-
- {{ $project->description }}
-
- @endif -
- - + Add Resource - - - - - - - - +
+ @endif + @foreach ($projects as $project) + -
- @endforeach + @endforeach
@if ($projects->count() > 0)

Servers

@@ -139,6 +138,7 @@
No deployments running.
@endforelse
+@endif