@@ -0,0 +1,96 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Livewire\Attributes\Computed;
|
||||
use Livewire\Attributes\Layout;
|
||||
use Livewire\Attributes\Title;
|
||||
use Livewire\Attributes\Url;
|
||||
use Livewire\Component;
|
||||
|
||||
new #[Layout('layouts::marketing')]
|
||||
#[Title('Confirming your subscription')]
|
||||
class extends Component
|
||||
{
|
||||
/**
|
||||
* How long to keep polling for the webhook before giving up.
|
||||
*/
|
||||
private const TIMEOUT_SECONDS = 30;
|
||||
|
||||
/**
|
||||
* The Stripe Checkout session id, used only to correlate the page with
|
||||
* the checkout that just completed.
|
||||
*/
|
||||
#[Url(as: 'session_id', except: '')]
|
||||
public string $sessionId = '';
|
||||
|
||||
/**
|
||||
* Seconds spent waiting so far.
|
||||
*/
|
||||
public int $waitedSeconds = 0;
|
||||
|
||||
public bool $timedOut = false;
|
||||
|
||||
/**
|
||||
* Confirm the subscription arrived. Cashier 16 has no checkout session
|
||||
* lookup, so the webhook is polled against the local subscription row.
|
||||
*/
|
||||
public function confirm(): void
|
||||
{
|
||||
if ($this->hasSubscription) {
|
||||
$this->redirect(route('dashboard'), navigate: true);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$this->waitedSeconds += 1;
|
||||
|
||||
if ($this->waitedSeconds >= self::TIMEOUT_SECONDS) {
|
||||
$this->timedOut = true;
|
||||
}
|
||||
}
|
||||
|
||||
#[Computed]
|
||||
public function hasSubscription(): bool
|
||||
{
|
||||
return Auth::user()?->hasActiveSubscription() ?? false;
|
||||
}
|
||||
}; ?>
|
||||
|
||||
<section class="flex w-full max-w-xl flex-col items-center gap-6 text-center"
|
||||
@if (! $timedOut)
|
||||
wire:poll.2s="confirm"
|
||||
@endif
|
||||
>
|
||||
@if ($this->hasSubscription)
|
||||
<flux:icon.check class="size-12 text-green-500" />
|
||||
|
||||
<flux:heading size="xl" level="1">{{ __('Your subscription is active') }}</flux:heading>
|
||||
|
||||
<flux:subheading>{{ __('Welcome aboard. Taking you to your todos now.') }}</flux:subheading>
|
||||
|
||||
<flux:button :href="route('dashboard')" variant="primary" wire:navigate data-test="go-to-dashboard-button">
|
||||
{{ __('Go to my todos') }}
|
||||
</flux:button>
|
||||
@elseif ($timedOut)
|
||||
<flux:icon.clock class="size-12 text-zinc-500" />
|
||||
|
||||
<flux:heading size="xl" level="1">{{ __('Still confirming your payment') }}</flux:heading>
|
||||
|
||||
<flux:subheading>
|
||||
{{ __('Your payment went through, but we have not heard from Stripe yet. Your access will turn on automatically as soon as it does.') }}
|
||||
</flux:subheading>
|
||||
|
||||
<flux:button :href="route('pricing')" variant="primary" wire:navigate data-test="back-to-pricing-button">
|
||||
{{ __('Back to plans') }}
|
||||
</flux:button>
|
||||
@else
|
||||
<div
|
||||
class="size-12 animate-spin rounded-full border-4 border-zinc-200 border-t-zinc-500 dark:border-white/10 dark:border-t-zinc-300"
|
||||
role="status"
|
||||
></div>
|
||||
|
||||
<flux:heading size="xl" level="1">{{ __('Confirming your subscription') }}</flux:heading>
|
||||
|
||||
<flux:subheading>{{ __('This usually takes a few seconds. Please do not close this page.') }}</flux:subheading>
|
||||
@endif
|
||||
</section>
|
||||
Reference in New Issue
Block a user