$plan], [ 'plan' => ['required', Rule::enum(SubscriptionPlan::class)], ])->validate(); $subscription = app(SubscriptionManager::class)->changePlan( Auth::user(), SubscriptionPlan::from($validated['plan']), ); unset($this->subscription, $this->invoices); $unpaidInvoice = $subscription->invoices() ->whereNotIn('state', ['paid', 'uncollectible']) ->latest('id') ->first(); if ($unpaidInvoice?->payment_url) { Flux::toast(variant: 'success', text: __('Plan updated — complete the payment to keep your new limit.')); $this->redirect($unpaidInvoice->payment_url, navigate: false); return; } Flux::toast(variant: 'success', text: __('Plan updated.')); } public function cancel(): void { app(SubscriptionManager::class)->cancel(Auth::user()); unset($this->subscription); Flux::toast(variant: 'success', text: __("Your subscription won't renew. You'll keep access until the end of the current period.")); } public function resume(): void { app(SubscriptionManager::class)->resume(Auth::user()); unset($this->subscription); Flux::toast(variant: 'success', text: __('Cancellation undone — your subscription will renew again.')); } #[Computed] public function subscription() { return Auth::user()->subscription ?? Auth::user()->subscription()->create(); } #[Computed] public function usageCount(): int { return Auth::user()->certificates()->count(); } #[Computed] public function invoices() { return $this->subscription->invoices()->latest('id')->get(); } /** * @return array */ #[Computed] public function plans(): array { return SubscriptionPlan::cases(); } }; ?>
@include('partials.settings-heading')
{{-- Current status --}}
{{ $this->subscription->plan->label() }} {{ $this->subscription->status->label() }}
@php $limit = $this->subscription->plan->certificateLimit(); @endphp @if ($limit !== null) {{ __(':used of :limit certificates used', ['used' => $this->usageCount, 'limit' => $limit]) }} @endif
@if ($this->subscription->plan->isPaid() && $this->subscription->current_period_ends_at)
@if ($this->subscription->cancel_at_period_end) {{ __('Ends on :date', ['date' => $this->subscription->current_period_ends_at->toFormattedDateString()]) }} {{ __('Undo cancellation') }} @else {{ __('Renews on :date', ['date' => $this->subscription->current_period_ends_at->toFormattedDateString()]) }} {{ __('Cancel subscription') }} @endif
@endif
@if ($this->subscription->status === SubscriptionStatus::PastDue && $this->subscription->grace_ends_at) {{ __("We haven't received payment yet. Without payment before :date we'll automatically switch you back to the Free plan.", ['date' => $this->subscription->grace_ends_at->toFormattedDateString()]) }} @endif
{{-- Plan switcher --}}
{{ __('Change plan') }}
@foreach ($this->plans as $plan) @php $isCurrent = $this->subscription->plan === $plan; @endphp
$isCurrent, 'border-slate-200 dark:border-slate-800' => ! $isCurrent, ])> {{ $plan->label() }} @php $planLimit = $plan->certificateLimit(); @endphp {{ $planLimit === null ? __('Unlimited certificates') : __('Up to :count certificates', ['count' => $planLimit]) }} €{{ number_format($plan->priceInclVatCents() / 100, 2, ',', '.') }}/{{ __('year') }} @if ($plan->isPaid()) €{{ number_format($plan->priceInCents() / 100, 2, ',', '.') }} {{ __('excl. VAT') }} @endif @if ($isCurrent) {{ __('Current plan') }} @else {{ $plan->priceInCents() > $this->subscription->plan->priceInCents() ? __('Upgrade') : __('Switch') }} @endif
@endforeach
{{-- Invoice history --}} @if ($this->invoices->isNotEmpty())
{{ __('Invoices') }} {{ __('Date') }} {{ __('Plan') }} {{ __('Amount') }} {{ __('Status') }} @foreach ($this->invoices as $invoice) {{ $invoice->invoice_date?->toFormattedDateString() }} {{ $invoice->plan->label() }} €{{ number_format($invoice->amount_cents / 100, 2, ',', '.') }} {{ $invoice->state }} @if ($invoice->state !== 'paid' && $invoice->payment_url) {{ __('Pay') }} @endif @endforeach
@endif