presseportale/app/Services/Auth/CustomerAccountProvisioner.php
Kevin Adametz 4466858aac Optimierung 3.5: Kleinere Zentralisierungen (VAT, findByEmail, Waehrung, Provisioning)
- VatResolver::normalizeCountryCode()/isEuCountry() als Single Source of Truth;
  resolve(), VatIdValidationService und StripeCheckoutService nutzen jetzt die
  zentrale EU-Pruefung statt eigener config-Lookups.
- User::findByEmail() buendelt die LOWER(email)-Lookups (ContactAccessService,
  SocialAuthService). Bleibt bewusst case-insensitiv, da E-Mails nicht
  normalisiert gespeichert werden; der indexfreundliche Direktvergleich
  braucht erst eine Schreib-Normalisierung (offen, dokumentiert).
- config('billing.default_currency') ersetzt 8 verstreute 'EUR'/'eur'-Literale
  (Stripe-Calls via strtolower). Vereinheitlicht nebenbei die zuvor uneinheitlich
  gespeicherte SinglePurchase.currency.
- Neuer CustomerAccountProvisioner::provisionVerifiedCustomer() ist die
  gemeinsame Provisioning-Methode (verifiziert + aktiv + customer-Rolle) fuer
  ContactAccessService und SocialAuthService.
- Tests: UserFindByEmailTest, erweiterte VatResolverTest.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-19 11:14:05 +00:00

41 lines
1.4 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
namespace App\Services\Auth;
use App\Enums\RegistrationType;
use App\Models\User;
/**
* Legt verifizierte Kunden-Accounts an, die über einen vertrauenswürdigen Kanal
* entstehen – Magic-Link an eine hinterlegte E-Mail (ContactAccessService) oder
* Social-Login (SocialAuthService).
*
* Single Source of Truth für das lazy Provisioning: Account direkt aktiv mit
* customer-Rolle, die E-Mail gilt über den bestätigenden Kanal als verifiziert
* (Entscheidung 15.06.2026). Der Name fällt auf die E-Mail zurück, wenn keiner
* bekannt ist.
*/
class CustomerAccountProvisioner
{
public function __construct(private readonly UserRolePermissionSyncService $roleSync) {}
/**
* @param array<string, mixed> $extraAttributes Zusätzliche Spalten beim
* Anlegen (z. B. OAuth-Provider).
*/
public function provisionVerifiedCustomer(string $email, string $name, array $extraAttributes = []): User
{
$user = User::create([
'name' => $name !== '' ? $name : $email,
'email' => $email,
'registration_type' => RegistrationType::Company->value,
'is_active' => true,
...$extraAttributes,
]);
$user->forceFill(['email_verified_at' => now()])->save();
$this->roleSync->assignRoleAndSyncPermissions($user, 'customer');
return $user;
}
}