152 lines
5.0 KiB
PHP
152 lines
5.0 KiB
PHP
<?php
|
|||
|
|
|
||
|
|
use Illuminate\Support\Facades\Auth;
|
||
|
|
use Livewire\Attributes\Computed;
|
||
|
|
use Livewire\Attributes\Title;
|
||
|
|
use Livewire\Component;
|
||
|
|
|
||
|
|
new #[Title('Billing settings')]
|
||
|
|
class extends Component
|
||
|
|
{
|
||
|
|
/**
|
||
|
|
* Get the organization that holds the subscription being managed.
|
||
|
|
*/
|
||
|
|
#[Computed]
|
||
|
|
public function organization()
|
||
|
|
{
|
||
|
|
return Auth::user()?->currentOrganization()->first();
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Get the current subscription, if there is one.
|
||
|
|
*/
|
||
|
|
#[Computed]
|
||
|
|
public function subscription()
|
||
|
|
{
|
||
|
|
return $this->organization?->currentSubscription();
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Get the plan the organization is on, falling back to a description built
|
||
|
|
* from the raw Stripe status for states that are not a plan.
|
||
|
|
*
|
||
|
|
* @return array{name: string, price: string, interval: string}|null
|
||
|
|
*/
|
||
|
|
#[Computed]
|
||
|
|
public function plan(): ?array
|
||
|
|
{
|
||
|
|
return $this->organization?->currentPlan();
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Get a human readable label for the subscription status.
|
||
|
|
*/
|
||
|
|
#[Computed]
|
||
|
|
public function status(): string
|
||
|
|
{
|
||
|
|
$subscription = $this->subscription;
|
||
|
|
|
||
|
|
if ($subscription === null) {
|
||
|
|
return __('No subscription');
|
||
|
|
}
|
||
|
|
|
||
|
|
return match ($subscription->stripe_status) {
|
||
|
|
'active' => __('Active'),
|
||
|
|
'trialing' => __('Free trial'),
|
||
|
|
'past_due' => __('Past due'),
|
||
|
|
'canceled' => __('Canceled'),
|
||
|
|
'unpaid' => __('Unpaid'),
|
||
|
|
'incomplete' => __('Incomplete'),
|
||
|
|
'incomplete_expired' => __('Expired'),
|
||
|
|
default => ucfirst((string) $subscription->stripe_status),
|
||
|
|
};
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Describe the state of the current subscription in a single sentence.
|
||
|
|
*/
|
||
|
|
#[Computed]
|
||
|
|
public function summary(): string
|
||
|
|
{
|
||
|
|
$subscription = $this->subscription;
|
||
|
|
|
||
|
|
if ($this->organization?->hasLifetimeAccess() === true) {
|
||
|
|
return __('Lifetime access. No subscription is required.');
|
||
|
|
}
|
||
|
|
|
||
|
|
if ($subscription === null) {
|
||
|
|
return __('You are on the free plan and cannot use your workspace until you subscribe.');
|
||
|
|
}
|
||
|
|
|
||
|
|
if ($subscription->ends_at !== null && $subscription->ends_at->isFuture()) {
|
||
|
|
return __('Your plan stays active until :date. Subscribe again to keep your access after that.', [
|
||
|
|
'date' => $subscription->ends_at->toFormattedDateString(),
|
||
|
|
]);
|
||
|
|
}
|
||
|
|
|
||
|
|
if ($subscription->trial_ends_at !== null && $subscription->trial_ends_at->isFuture()) {
|
||
|
|
return __('Your free trial ends on :date.', [
|
||
|
|
'date' => $subscription->trial_ends_at->toFormattedDateString(),
|
||
|
|
]);
|
||
|
|
}
|
||
|
|
|
||
|
|
return __('Your subscription renews automatically.');
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Determine whether the customer portal button should be shown. The portal
|
||
|
|
* only exists once Stripe knows about the organization as a customer.
|
||
|
|
*/
|
||
|
|
#[Computed]
|
||
|
|
public function canManagePaymentMethod(): bool
|
||
|
|
{
|
||
|
|
return $this->organization?->hasStripeId() === true;
|
||
|
|
}
|
||
|
|
}; ?>
|
||
|
|
|
||
|
|
<section class="w-full">
|
||
|
|
@include('partials.settings-heading')
|
||
|
|
|
||
|
|
<flux:heading level="2" class="sr-only">{{ __('Billing settings') }}</flux:heading>
|
||
|
|
|
||
|
|
<x-pages::settings.layout :heading="__('Billing')" :subheading="__('Manage your plan and payment details')">
|
||
|
|
<div class="space-y-6" data-test="billing-overview">
|
||
|
|
<flux:card class="space-y-3">
|
||
|
|
<div class="flex items-center justify-between gap-4">
|
||
|
|
<div>
|
||
|
|
<flux:heading size="sm">{{ $this->plan['name'] ?? __('Free') }}</flux:heading>
|
||
|
|
|
||
|
|
<flux:text size="sm" class="text-zinc-500 dark:text-zinc-400">
|
||
|
|
{{ $this->status }}
|
||
|
|
</flux:text>
|
||
|
|
</div>
|
||
|
|
|
||
|
|
<flux:badge :color="$this->organization?->isEntitled() ? 'green' : 'red'" size="sm">
|
||
|
|
{{ $this->organization?->isEntitled() ? __('Active') : __('Inactive') }}
|
||
|
|
</flux:badge>
|
||
|
|
</div>
|
||
|
|
|
||
|
|
<flux:text size="sm">{{ $this->summary }}</flux:text>
|
||
|
|
</flux:card>
|
||
|
|
|
||
|
|
<div class="flex flex-wrap items-center gap-3">
|
||
|
|
@if ($this->organization?->isEntitled() !== true)
|
||
|
|
<flux:button :href="route('pricing')" variant="primary" wire:navigate data-test="subscribe-button">
|
||
|
|
{{ __('Subscribe') }}
|
||
|
|
</flux:button>
|
||
|
|
@endif
|
||
|
|
|
||
|
|
@if ($this->canManagePaymentMethod)
|
||
|
|
<form method="POST" action="{{ route('billing.portal') }}">
|
||
|
|
@csrf
|
||
|
|
|
||
|
|
<flux:button type="submit" variant="ghost" data-test="billing-portal-button">
|
||
|
|
{{ __('Manage payment method') }}
|
||
|
|
</flux:button>
|
||
|
|
</form>
|
||
|
|
@endif
|
||
|
|
</div>
|
||
|
|
</div>
|
||
|
|
</x-pages::settings.layout>
|
||
|
|
</section>
|