12-05-2026 Frontend dev
Some checks are pending
linter / quality (push) Waiting to run
tests / ci (push) Waiting to run

This commit is contained in:
Kevin Adametz 2026-05-12 18:32:33 +02:00
parent 405df0a122
commit 5b8bdf4182
779 changed files with 480564 additions and 6241 deletions

View file

@ -0,0 +1,57 @@
<?php
namespace App\Services\Api;
use App\Enums\UserPaymentOptionStatus;
use App\Models\User;
class ApiAccessEligibilityService
{
public function canCreateToken(User $user): bool
{
return $this->denialReason($user) === null;
}
public function denialReason(User $user): ?string
{
if (! $user->is_active) {
return 'Ihr Benutzerkonto ist nicht aktiv. API-Tokens können nur für aktive Benutzer erstellt werden.';
}
if ($this->hasActivePaymentOption($user) || $this->hasPaidLegacyInvoice($user)) {
return null;
}
return 'API-Tokens werden erst freigeschaltet, wenn ein aktiver Zahlungsstatus oder freigegebener Bestandsschutz vorliegt.';
}
private function hasActivePaymentOption(User $user): bool
{
return $user->userPaymentOptions()
->where(function ($query): void {
$query
->where(function ($active): void {
$active
->where('status', UserPaymentOptionStatus::Active->value)
->whereDate('current_period_start', '<=', now())
->whereDate('current_period_end', '>=', now());
})
->orWhere(function ($grandfathered): void {
$grandfathered
->where('status', UserPaymentOptionStatus::Grandfathered->value)
->whereDate('grandfathered_until', '>=', now());
});
})
->exists();
}
private function hasPaidLegacyInvoice(User $user): bool
{
$latestInvoice = $user->legacyInvoices()
->latest('invoice_date')
->latest('id')
->first(['id', 'status']);
return $latestInvoice?->status === 'paid';
}
}