fix: subscription / plan switch, etc

This commit is contained in:
Andras Bacsai 2024-02-23 12:59:14 +01:00
parent f931ebece8
commit f78fd212bb
10 changed files with 74 additions and 61 deletions

View File

@ -10,14 +10,19 @@ class Index extends Component
{ {
public InstanceSettings $settings; public InstanceSettings $settings;
public bool $alreadySubscribed = false; public bool $alreadySubscribed = false;
public function mount() { public function mount()
{
if (!isCloud()) { if (!isCloud()) {
return redirect(RouteServiceProvider::HOME); return redirect(RouteServiceProvider::HOME);
} }
if (data_get(currentTeam(), 'subscription')) {
return redirect()->route('subscription.show');
}
$this->settings = InstanceSettings::get(); $this->settings = InstanceSettings::get();
$this->alreadySubscribed = currentTeam()->subscription()->exists(); $this->alreadySubscribed = currentTeam()->subscription()->exists();
} }
public function stripeCustomerPortal() { public function stripeCustomerPortal()
{
$session = getStripeCustomerPortalSession(currentTeam()); $session = getStripeCustomerPortalSession(currentTeam());
if (is_null($session)) { if (is_null($session)) {
return; return;

View File

@ -11,6 +11,9 @@ public function mount()
if (!isCloud()) { if (!isCloud()) {
return redirect()->route('dashboard'); return redirect()->route('dashboard');
} }
if (!data_get(currentTeam(), 'subscription')) {
return redirect()->route('subscription.index');
}
} }
public function render() public function render()
{ {

View File

@ -30,8 +30,7 @@ public function type()
if (in_array($subscription, $ultimate)) { if (in_array($subscription, $ultimate)) {
return 'ultimate'; return 'ultimate';
} }
} } else if (isStripe()) {
if (isStripe()) {
if (!$this->stripe_plan_id) { if (!$this->stripe_plan_id) {
return 'zero'; return 'zero';
} }
@ -55,7 +54,8 @@ public function type()
}; };
})->first(); })->first();
if ($stripePlanId) { 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'; return 'zero';

View File

@ -159,6 +159,9 @@ public function otherTeams()
public function role() public function role()
{ {
if (data_get($this, 'pivot')) {
return $this->pivot->role;
}
return auth()->user()->teams->where('id', currentTeam()->id)->first()->pivot->role; return auth()->user()->teams->where('id', currentTeam()->id)->first()->pivot->role;
} }
} }

View File

@ -13,6 +13,12 @@
'stripe_price_id_ultimate_yearly' => env('STRIPE_PRICE_ID_ULTIMATE_YEARLY', null), 'stripe_price_id_ultimate_yearly' => env('STRIPE_PRICE_ID_ULTIMATE_YEARLY', null),
'stripe_excluded_plans' => env('STRIPE_EXCLUDED_PLANS', 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
'paddle_vendor_id' => env('PADDLE_VENDOR_ID', null), 'paddle_vendor_id' => env('PADDLE_VENDOR_ID', null),

View File

@ -57,6 +57,12 @@ services:
- STRIPE_PRICE_ID_PRO_YEARLY - STRIPE_PRICE_ID_PRO_YEARLY
- STRIPE_PRICE_ID_ULTIMATE_MONTHLY - STRIPE_PRICE_ID_ULTIMATE_MONTHLY
- STRIPE_PRICE_ID_ULTIMATE_YEARLY - 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 - STRIPE_EXCLUDED_PLANS
- PADDLE_VENDOR_ID - PADDLE_VENDOR_ID
- PADDLE_WEBHOOK_SECRET - PADDLE_WEBHOOK_SECRET

View File

@ -5,7 +5,7 @@
<h1>Dashboard</h1> <h1>Dashboard</h1>
<div class="subtitle">Your self-hosted environment</div> <div class="subtitle">Your self-hosted environment</div>
@if (request()->query->get('success')) @if (request()->query->get('success'))
<div class="text-white rounded alert alert-success"> <div class="mb-10 text-white rounded alert alert-success">
<svg xmlns="http://www.w3.org/2000/svg" class="w-6 h-6 stroke-current shrink-0" fill="none" <svg xmlns="http://www.w3.org/2000/svg" class="w-6 h-6 stroke-current shrink-0" fill="none"
viewBox="0 0 24 24"> viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
@ -16,53 +16,52 @@
</div> </div>
@endif @endif
@if ($projects->count() === 0 && $servers->count() === 0) @if ($projects->count() === 0 && $servers->count() === 0)
No resources found. Add your first server / private key <a class="text-white underline" No resources found. Add your first server & private key <a class="text-white underline"
href="{{ route('server.create') }}">here</a>. href="{{ route('server.create') }}">here</a> or go to the <a class="text-white underline" href="{{ route('boarding') }}">boarding page</a>.
@endif @endif
@if ($projects->count() > 0) @if ($projects->count() > 0)
<h3 class="pb-4">Projects</h3> <h3 class="pb-4">Projects</h3>
@endif @if ($projects->count() === 1)
@if ($projects->count() === 1) <div class="grid grid-cols-1 gap-2">
<div class="grid grid-cols-1 gap-2">
@else
<div class="grid grid-cols-1 gap-2 xl:grid-cols-2">
@endif
@foreach ($projects as $project)
<div class="gap-2 border border-transparent cursor-pointer box group">
@if (data_get($project, 'environments')->count() === 1)
<a class="flex flex-col flex-1 mx-6 hover:no-underline"
href="{{ route('project.resource.index', ['project_uuid' => data_get($project, 'uuid'), 'environment_name' => data_get($project, 'environments.0.name', 'production')]) }}">
<div class="font-bold text-white">{{ $project->name }}</div>
<div class="description">
{{ $project->description }}</div>
</a>
@else @else
<a class="flex flex-col flex-1 mx-6 hover:no-underline" <div class="grid grid-cols-1 gap-2 xl:grid-cols-2">
href="{{ route('project.show', ['project_uuid' => data_get($project, 'uuid')]) }}"> @endif
<div class="font-bold text-white">{{ $project->name }}</div> @foreach ($projects as $project)
<div class="description"> <div class="gap-2 border border-transparent cursor-pointer box group">
{{ $project->description }}</div> @if (data_get($project, 'environments')->count() === 1)
</a> <a class="flex flex-col flex-1 mx-6 hover:no-underline"
@endif href="{{ route('project.resource.index', ['project_uuid' => data_get($project, 'uuid'), 'environment_name' => data_get($project, 'environments.0.name', 'production')]) }}">
<div class="flex items-center"> <div class="font-bold text-white">{{ $project->name }}</div>
<a class="mx-4 rounded group-hover:text-white hover:no-underline" <div class="description">
href="{{ route('project.resource.create', ['project_uuid' => data_get($project, 'uuid'), 'environment_name' => data_get($project, 'environments.0.name', 'production')]) }}"> {{ $project->description }}</div>
<span class="font-bold hover:text-warning">+ Add Resource</span> </a>
</a> @else
<a class="mx-4 rounded group-hover:text-white" <a class="flex flex-col flex-1 mx-6 hover:no-underline"
href="{{ route('project.edit', ['project_uuid' => data_get($project, 'uuid')]) }}"> href="{{ route('project.show', ['project_uuid' => data_get($project, 'uuid')]) }}">
<svg xmlns="http://www.w3.org/2000/svg" class="icon hover:text-warning" viewBox="0 0 24 24" <div class="font-bold text-white">{{ $project->name }}</div>
stroke-width="1.5" stroke="currentColor" fill="none" stroke-linecap="round" <div class="description">
stroke-linejoin="round"> {{ $project->description }}</div>
<path stroke="none" d="M0 0h24v24H0z" fill="none" /> </a>
<path @endif
d="M10.325 4.317c.426 -1.756 2.924 -1.756 3.35 0a1.724 1.724 0 0 0 2.573 1.066c1.543 -.94 3.31 .826 2.37 2.37a1.724 1.724 0 0 0 1.065 2.572c1.756 .426 1.756 2.924 0 3.35a1.724 1.724 0 0 0 -1.066 2.573c.94 1.543 -.826 3.31 -2.37 2.37a1.724 1.724 0 0 0 -2.572 1.065c-.426 1.756 -2.924 1.756 -3.35 0a1.724 1.724 0 0 0 -2.573 -1.066c-1.543 .94 -3.31 -.826 -2.37 -2.37a1.724 1.724 0 0 0 -1.065 -2.572c-1.756 -.426 -1.756 -2.924 0 -3.35a1.724 1.724 0 0 0 1.066 -2.573c-.94 -1.543 .826 -3.31 2.37 -2.37c1 .608 2.296 .07 2.572 -1.065z" /> <div class="flex items-center">
<path d="M9 12a3 3 0 1 0 6 0a3 3 0 0 0 -6 0" /> <a class="mx-4 rounded group-hover:text-white hover:no-underline"
</svg> href="{{ route('project.resource.create', ['project_uuid' => data_get($project, 'uuid'), 'environment_name' => data_get($project, 'environments.0.name', 'production')]) }}">
</a> <span class="font-bold hover:text-warning">+ Add Resource</span>
</a>
<a class="mx-4 rounded group-hover:text-white"
href="{{ route('project.edit', ['project_uuid' => data_get($project, 'uuid')]) }}">
<svg xmlns="http://www.w3.org/2000/svg" class="icon hover:text-warning" viewBox="0 0 24 24"
stroke-width="1.5" stroke="currentColor" fill="none" stroke-linecap="round"
stroke-linejoin="round">
<path stroke="none" d="M0 0h24v24H0z" fill="none" />
<path
d="M10.325 4.317c.426 -1.756 2.924 -1.756 3.35 0a1.724 1.724 0 0 0 2.573 1.066c1.543 -.94 3.31 .826 2.37 2.37a1.724 1.724 0 0 0 1.065 2.572c1.756 .426 1.756 2.924 0 3.35a1.724 1.724 0 0 0 -1.066 2.573c.94 1.543 -.826 3.31 -2.37 2.37a1.724 1.724 0 0 0 -2.572 1.065c-.426 1.756 -2.924 1.756 -3.35 0a1.724 1.724 0 0 0 -2.573 -1.066c-1.543 .94 -3.31 -.826 -2.37 -2.37a1.724 1.724 0 0 0 -1.065 -2.572c-1.756 -.426 -1.756 -2.924 0 -3.35a1.724 1.724 0 0 0 1.066 -2.573c-.94 -1.543 .826 -3.31 2.37 -2.37c1 .608 2.296 .07 2.572 -1.065z" />
<path d="M9 12a3 3 0 1 0 6 0a3 3 0 0 0 -6 0" />
</svg>
</a>
</div>
</div> </div>
</div> @endforeach
@endforeach
</div> </div>
@if ($projects->count() > 0) @if ($projects->count() > 0)
<h3 class="py-4">Servers</h3> <h3 class="py-4">Servers</h3>
@ -139,6 +138,7 @@
<div>No deployments running.</div> <div>No deployments running.</div>
@endforelse @endforelse
</div> </div>
@endif
<script> <script>
function gotoProject(uuid, environment = 'production') { function gotoProject(uuid, environment = 'production') {
window.location.href = '/project/' + uuid + '/' + environment; window.location.href = '/project/' + uuid + '/' + environment;

View File

@ -20,7 +20,6 @@ class="text-warning">{{ data_get(currentTeam(), 'subscription')->type() }}</stro
<path fill="#635BFF" <path fill="#635BFF"
d="M512 110.08c0-36.409-17.636-65.138-51.342-65.138c-33.85 0-54.33 28.73-54.33 64.854c0 42.808 24.179 64.426 58.88 64.426c16.925 0 29.725-3.84 39.396-9.244v-28.445c-9.67 4.836-20.764 7.823-34.844 7.823c-13.796 0-26.027-4.836-27.591-21.618h69.547c0-1.85.284-9.245.284-12.658Zm-70.258-13.511c0-16.071 9.814-22.756 18.774-22.756c8.675 0 17.92 6.685 17.92 22.756h-36.694Zm-90.31-51.627c-13.939 0-22.899 6.542-27.876 11.094l-1.85-8.818h-31.288v165.83l35.555-7.537l.143-40.249c5.12 3.698 12.657 8.96 25.173 8.96c25.458 0 48.64-20.48 48.64-65.564c-.142-41.245-23.609-63.716-48.498-63.716Zm-8.534 97.991c-8.391 0-13.37-2.986-16.782-6.684l-.143-52.765c3.698-4.124 8.818-6.968 16.925-6.968c12.942 0 21.902 14.506 21.902 33.137c0 19.058-8.818 33.28-21.902 33.28ZM241.493 36.551l35.698-7.68V0l-35.698 7.538V36.55Zm0 10.809h35.698v124.444h-35.698V47.36Zm-38.257 10.524L200.96 47.36h-30.72v124.444h35.556V87.467c8.39-10.951 22.613-8.96 27.022-7.396V47.36c-4.551-1.707-21.191-4.836-29.582 10.524Zm-71.112-41.386l-34.702 7.395l-.142 113.92c0 21.05 15.787 36.551 36.836 36.551c11.662 0 20.195-2.133 24.888-4.693V140.8c-4.55 1.849-27.022 8.391-27.022-12.658V77.653h27.022V47.36h-27.022l.142-30.862ZM35.982 83.484c0-5.546 4.551-7.68 12.09-7.68c10.808 0 24.461 3.272 35.27 9.103V51.484c-11.804-4.693-23.466-6.542-35.27-6.542C19.2 44.942 0 60.018 0 85.192c0 39.252 54.044 32.995 54.044 49.92c0 6.541-5.688 8.675-13.653 8.675c-11.804 0-26.88-4.836-38.827-11.378v33.849c13.227 5.689 26.596 8.106 38.827 8.106c29.582 0 49.92-14.648 49.92-40.106c-.142-42.382-54.329-34.845-54.329-50.774Z" /> d="M512 110.08c0-36.409-17.636-65.138-51.342-65.138c-33.85 0-54.33 28.73-54.33 64.854c0 42.808 24.179 64.426 58.88 64.426c16.925 0 29.725-3.84 39.396-9.244v-28.445c-9.67 4.836-20.764 7.823-34.844 7.823c-13.796 0-26.027-4.836-27.591-21.618h69.547c0-1.85.284-9.245.284-12.658Zm-70.258-13.511c0-16.071 9.814-22.756 18.774-22.756c8.675 0 17.92 6.685 17.92 22.756h-36.694Zm-90.31-51.627c-13.939 0-22.899 6.542-27.876 11.094l-1.85-8.818h-31.288v165.83l35.555-7.537l.143-40.249c5.12 3.698 12.657 8.96 25.173 8.96c25.458 0 48.64-20.48 48.64-65.564c-.142-41.245-23.609-63.716-48.498-63.716Zm-8.534 97.991c-8.391 0-13.37-2.986-16.782-6.684l-.143-52.765c3.698-4.124 8.818-6.968 16.925-6.968c12.942 0 21.902 14.506 21.902 33.137c0 19.058-8.818 33.28-21.902 33.28ZM241.493 36.551l35.698-7.68V0l-35.698 7.538V36.55Zm0 10.809h35.698v124.444h-35.698V47.36Zm-38.257 10.524L200.96 47.36h-30.72v124.444h35.556V87.467c8.39-10.951 22.613-8.96 27.022-7.396V47.36c-4.551-1.707-21.191-4.836-29.582 10.524Zm-71.112-41.386l-34.702 7.395l-.142 113.92c0 21.05 15.787 36.551 36.836 36.551c11.662 0 20.195-2.133 24.888-4.693V140.8c-4.55 1.849-27.022 8.391-27.022-12.658V77.653h27.022V47.36h-27.022l.142-30.862ZM35.982 83.484c0-5.546 4.551-7.68 12.09-7.68c10.808 0 24.461 3.272 35.27 9.103V51.484c-11.804-4.693-23.466-6.542-35.27-6.542C19.2 44.942 0 60.018 0 85.192c0 39.252 54.044 32.995 54.044 49.92c0 6.541-5.688 8.675-13.653 8.675c-11.804 0-26.88-4.836-38.827-11.378v33.849c13.227 5.689 26.596 8.106 38.827 8.106c29.582 0 49.92-14.648 49.92-40.106c-.142-42.382-54.329-34.845-54.329-50.774Z" />
</svg></x-forms.button> </svg></x-forms.button>
</div> </div>
</div> </div>
<div class="pt-4"> <div class="pt-4">

View File

@ -1,16 +1,7 @@
<div> <div>
<div > <div>
<h1>Subscription</h1> <h1>Subscription</h1>
<div>Here you can see and manage your subscription.</div> <div>Here you can see and manage your subscription.</div>
</div> </div>
<div class="pb-8"> <livewire:subscription.actions />
@if (data_get(currentTeam(), 'subscription'))
<livewire:subscription.actions />
@else
<div>You are not subscribed to any plan. Please subscribe to a plan to continue.</div>
<x-forms.button class="mt-4"><a class="text-white hover:no-underline"
href="{{ route('subscription.index') }}">Subscribe Now</a>
</x-forms.button>
@endif
</div>
</div> </div>

View File

@ -111,8 +111,8 @@
Route::get('/', Dashboard::class)->name('dashboard'); Route::get('/', Dashboard::class)->name('dashboard');
Route::get('/boarding', BoardingIndex::class)->name('boarding'); Route::get('/boarding', BoardingIndex::class)->name('boarding');
Route::get('/subscription/new', SubscriptionIndex::class)->name('subscription.index');
Route::get('/subscription', SubscriptionShow::class)->name('subscription.show'); Route::get('/subscription', SubscriptionShow::class)->name('subscription.show');
Route::get('/subscription/new', SubscriptionIndex::class)->name('subscription.index');
Route::get('/settings', SettingsIndex::class)->name('settings.index'); Route::get('/settings', SettingsIndex::class)->name('settings.index');
Route::get('/settings/license', SettingsLicense::class)->name('settings.license'); Route::get('/settings/license', SettingsLicense::class)->name('settings.license');