trypost/app/Http/Middleware/App/EnsureAccountReady.php
Paulo Castellano 177e7f8681 feat(signup): no-card 7-day trial on Starter plan
New signups land on a 7-day generic trial (Cashier trial_ends_at) without
a Stripe customer or subscription. Account is on Starter plan limits during
the trial. After 7 days, EnsureAccountReady redirects to /subscribe per the
existing flow.

- CreateUser sets account.trial_ends_at and plan_id = Starter
- EnsureAccountReady allows access when subscribed() OR onGenericTrial()
- Account::isOnTrial() includes generic trial check

Existing users unaffected: paying users have a subscription;
never-paid users continue redirecting to /subscribe.
2026-05-14 19:37:46 -03:00

44 lines
984 B
PHP

<?php
declare(strict_types=1);
namespace App\Http\Middleware\App;
use App\Models\Account;
use Closure;
use Illuminate\Http\Request;
use Symfony\Component\HttpFoundation\Response;
class EnsureAccountReady
{
/**
* @param Closure(Request): (Response) $next
*/
public function handle(Request $request, Closure $next): Response
{
$user = $request->user();
if (! $user) {
return $next($request);
}
$account = $user->account;
if (! config('trypost.self_hosted')) {
$hasAccess = $account && (
$account->subscribed(Account::SUBSCRIPTION_NAME)
|| $account->onGenericTrial()
);
if (! $hasAccess) {
return redirect()->route('app.subscribe');
}
}
if (! $user->workspaces()->exists()) {
return redirect()->route('app.workspaces.create');
}
return $next($request);
}
}