Bug fix
- Surface the localized "network already connected" message on the
Facebook/Instagram/InstagramFacebook/LinkedInPage/Threads/YouTube OAuth
callbacks: catch NetworkAlreadyConnectedException before the generic catch
so the conflict no longer falls through to a generic error + Log::error.
Scope / dead code
- Remove the orphaned BillingController::checkout() + app.billing.checkout route
(onboarding starts checkout directly); delete the now-dead DiscordWidget and
useFeatureAccess composable; prune orphaned i18n keys left by removing the
plan picker / upgrade dialog / count limits (billing.subscribe.*,
accounts.limit_reached, workspaces.limit_reached, common.discord.*).
- Drop the unused `plan` prop from the usage page and the unused `label` from
the onboarding persona payload (labels come from i18n); remove
Persona::options()/label().
Conventions
- declare(strict_types=1) on the two new migrations.
- Extract autofill validation into AutofillBrandRequest (FormRequest).
- Drop the unused $plan param from AccountPolicy::swapPlan.
- CreateUser: drop the stale config('cashier.trial_days', 7) fallback (now 8).
- Rename LimitEnforcementTest to InvitePermissionTest; use Pest mock() helper in
WorkspaceQuantitySyncTest; move shared test helpers into Pest.php.
- Memoize BillingCycle window() + subscription lookup.
60 lines
2.2 KiB
PHP
60 lines
2.2 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Actions\User;
|
|
|
|
use App\Enums\Plan\Slug;
|
|
use App\Jobs\PostHog\SyncUser;
|
|
use App\Models\Account;
|
|
use App\Models\Plan;
|
|
use App\Models\User;
|
|
use App\Services\PostHogService;
|
|
use Illuminate\Support\Facades\DB;
|
|
|
|
class CreateUser
|
|
{
|
|
/**
|
|
* @param array{name: string, email: string, password?: string, google_id?: string, github_id?: string, email_verified_at?: \DateTimeInterface|null, is_invite?: bool, registration_ip?: string|null} $data
|
|
* @param array<string, string> $utmParameters
|
|
*/
|
|
public static function execute(array $data, array $utmParameters = []): User
|
|
{
|
|
$user = DB::transaction(function () use ($data, $utmParameters): User {
|
|
$isInviteRegistration = data_get($data, 'is_invite', false);
|
|
$requiresCardForTrial = (bool) config('trypost.billing.require_card_for_trial', true);
|
|
$accountAttributes = [
|
|
'name' => data_get($data, 'name')."'s Account",
|
|
'billing_email' => data_get($data, 'email'),
|
|
];
|
|
|
|
if (! $requiresCardForTrial) {
|
|
$accountAttributes['plan_id'] = Plan::where('slug', Slug::Workspace)->value('id');
|
|
$accountAttributes['trial_ends_at'] = now()->addDays(config('cashier.trial_days'));
|
|
}
|
|
|
|
$account = Account::create($accountAttributes);
|
|
|
|
$user = User::create(array_merge([
|
|
'name' => data_get($data, 'name'),
|
|
'email' => data_get($data, 'email'),
|
|
'password' => data_get($data, 'password'),
|
|
'google_id' => data_get($data, 'google_id'),
|
|
'github_id' => data_get($data, 'github_id'),
|
|
'email_verified_at' => data_get($data, 'email_verified_at', $isInviteRegistration ? now() : null),
|
|
'account_id' => $account->id,
|
|
'registration_ip' => data_get($data, 'registration_ip'),
|
|
], $utmParameters));
|
|
|
|
$account->update(['owner_id' => $user->id]);
|
|
|
|
return $user;
|
|
});
|
|
|
|
if (PostHogService::isEnabled()) {
|
|
SyncUser::dispatch((string) $user->id);
|
|
}
|
|
|
|
return $user;
|
|
}
|
|
}
|