164 lines
5.9 KiB
PHP
164 lines
5.9 KiB
PHP
<?php
|
|
|
|
use App\Models\Organization;
|
|
use Illuminate\Http\RedirectResponse;
|
|
use Illuminate\Support\Facades\Auth;
|
|
use Illuminate\Validation\Rule;
|
|
use Livewire\Attributes\Computed;
|
|
use Livewire\Attributes\Layout;
|
|
use Livewire\Attributes\Title;
|
|
use Livewire\Component;
|
|
|
|
new #[Layout('layouts::marketing')]
|
|
#[Title('Pricing')]
|
|
class extends Component
|
|
{
|
|
/**
|
|
* The plan key the visitor chose. Held as state so the server can validate
|
|
* it against the configured plans rather than trusting the button.
|
|
*/
|
|
public string $plan = '';
|
|
|
|
/**
|
|
* The trial length configured for new subscriptions.
|
|
*/
|
|
public function trialDays(): int
|
|
{
|
|
return Organization::trialDays();
|
|
}
|
|
|
|
/**
|
|
* Determine whether the signed-in user already has access, in which case
|
|
* there is nothing to sell them.
|
|
*/
|
|
#[Computed]
|
|
public function isSubscribed(): bool
|
|
{
|
|
return Auth::user()?->hasActiveSubscription() ?? false;
|
|
}
|
|
|
|
/**
|
|
* Get the plans that are configured and available to purchase.
|
|
*
|
|
* @return array<string, array{name: string, price: string, interval: string}>
|
|
*/
|
|
#[Computed]
|
|
public function plans(): array
|
|
{
|
|
return Organization::availablePlans();
|
|
}
|
|
|
|
/**
|
|
* Start a Stripe Checkout session for the given plan.
|
|
*/
|
|
public function subscribe(string $plan): RedirectResponse
|
|
{
|
|
abort_if(Auth::guest(), 403);
|
|
|
|
$this->plan = $plan;
|
|
|
|
$this->validate([
|
|
'plan' => ['required', Rule::in(array_keys(Organization::availablePlans()))],
|
|
], [
|
|
'plan.in' => __('That plan is not available.'),
|
|
]);
|
|
|
|
$organization = Auth::user()->currentOrganization()->first();
|
|
|
|
abort_if($organization === null, 403);
|
|
|
|
return $organization->checkoutForPlan($this->plan)->redirect();
|
|
}
|
|
}; ?>
|
|
|
|
<section class="flex w-full max-w-5xl flex-col gap-10">
|
|
<div class="flex flex-col items-center gap-3 text-center">
|
|
<flux:heading size="xl" level="1">{{ __('Plans and pricing') }}</flux:heading>
|
|
|
|
@if (session('billing.checkout_failed'))
|
|
<flux:callout variant="danger" class="w-full" data-test="pricing-status">
|
|
{{ session('billing.checkout_failed') }}
|
|
</flux:callout>
|
|
@endif
|
|
|
|
@if ($this->isSubscribed)
|
|
|
|
<flux:subheading>{{ __('Your workspace already has an active subscription.') }}</flux:subheading>
|
|
@else
|
|
<flux:subheading class="max-w-2xl text-center">
|
|
{{ __('Subscribe to unlock your todos, folders and notes.') }}
|
|
</flux:subheading>
|
|
@endif
|
|
</div>
|
|
|
|
@if ($this->isSubscribed)
|
|
<flux:button :href="route('billing.edit')" variant="primary" wire:navigate data-test="manage-subscription-button">
|
|
{{ __('Manage your subscription') }}
|
|
</flux:button>
|
|
@elseif (count($this->plans) === 0)
|
|
<flux:callout variant="warning" class="mx-auto max-w-2xl">
|
|
{{ __('No plans are available right now. Please check back soon.') }}
|
|
</flux:callout>
|
|
@else
|
|
<div class="grid w-full gap-6 md:grid-cols-2 lg:grid-cols-3">
|
|
@foreach ($this->plans as $key => $plan)
|
|
<flux:card class="flex flex-col gap-5" data-test="plan-{{ $key }}">
|
|
<div class="flex flex-col gap-1">
|
|
<flux:heading size="lg">{{ $plan['name'] }}</flux:heading>
|
|
|
|
<p class="text-2xl font-semibold text-zinc-900 dark:text-white" data-test="plan-{{ $key }}-amount">
|
|
{{ Organization::formatAmount($plan['amount']) }}
|
|
</p>
|
|
|
|
<flux:text size="sm" class="text-zinc-500 dark:text-zinc-400">
|
|
{{ __('Billed every :interval', ['interval' => $plan['interval']]) }}
|
|
</flux:text>
|
|
</div>
|
|
|
|
<ul class="flex flex-1 flex-col gap-2 text-sm">
|
|
<li class="flex items-center gap-2">
|
|
<flux:icon.check class="size-4 shrink-0" />
|
|
<span>{{ __('Unlimited todos and folders') }}</span>
|
|
</li>
|
|
<li class="flex items-center gap-2">
|
|
<flux:icon.check class="size-4 shrink-0" />
|
|
<span>{{ __('Notes on every todo') }}</span>
|
|
</li>
|
|
<li class="flex items-center gap-2">
|
|
<flux:icon.check class="size-4 shrink-0" />
|
|
<span>{{ __('Status, due dates and priorities') }}</span>
|
|
</li>
|
|
</ul>
|
|
|
|
@auth
|
|
<flux:button
|
|
wire:click="subscribe('{{ $key }}')"
|
|
variant="primary"
|
|
class="w-full"
|
|
data-test="subscribe-{{ $key }}-button"
|
|
>
|
|
{{ $this->trialDays() > 0
|
|
? __('Start :days-day free trial', ['days' => $this->trialDays()])
|
|
: __('Subscribe') }}
|
|
</flux:button>
|
|
@else
|
|
<flux:button :href="route('register')" variant="primary" class="w-full" wire:navigate>
|
|
{{ __('Create an account') }}
|
|
</flux:button>
|
|
@endauth
|
|
</flux:card>
|
|
@endforeach
|
|
</div>
|
|
|
|
@if ($this->trialDays() > 0)
|
|
<flux:text size="sm" class="text-center text-zinc-500 dark:text-zinc-400">
|
|
{{ __('Your trial ends after :days days and you can cancel at any time.', ['days' => $this->trialDays()]) }}
|
|
</flux:text>
|
|
@endif
|
|
@endif
|
|
|
|
@error('plan')
|
|
<flux:error name="plan" />
|
|
@enderror
|
|
</section>
|