User-Panel-Restarbeiten: PM-Guard, Profil-Rework, USt-ID-Prüfung, Buchungspflicht-Adresse
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
parent
036a53499f
commit
afcca34f91
25 changed files with 905 additions and 140 deletions
|
|
@ -5,6 +5,7 @@ namespace App\Services\Billing;
|
|||
use App\Models\Plan;
|
||||
use App\Models\SinglePurchase;
|
||||
use App\Models\User;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Laravel\Cashier\Checkout;
|
||||
|
||||
/**
|
||||
|
|
@ -27,11 +28,51 @@ class StripeCheckoutService
|
|||
? $plan->stripe_price_id_yearly
|
||||
: $plan->stripe_price_id_monthly;
|
||||
|
||||
$this->syncTaxIdFromBillingAddress($user);
|
||||
|
||||
return $user
|
||||
->newSubscription('default', $priceId)
|
||||
->checkout($this->sessionOptions());
|
||||
}
|
||||
|
||||
/**
|
||||
* Lokal gepflegte USt-ID vor dem Checkout an den Stripe-Customer
|
||||
* übergeben (User-Panel-Restarbeiten, 12.06.2026) — Stripe Tax
|
||||
* berücksichtigt sie dann ohne erneute Eingabe im Checkout. Fehler
|
||||
* (z. B. von Stripe abgelehnte ID) blockieren den Checkout nicht:
|
||||
* Stripe validiert die im Checkout erfasste ID ohnehin selbst.
|
||||
*/
|
||||
private function syncTaxIdFromBillingAddress(User $user): void
|
||||
{
|
||||
$vatId = strtoupper((string) preg_replace('/\s+/', '', (string) $user->billingAddress?->vat_id));
|
||||
|
||||
if ($vatId === '') {
|
||||
return;
|
||||
}
|
||||
|
||||
$prefixCountry = substr($vatId, 0, 2) === 'EL' ? 'GR' : substr($vatId, 0, 2);
|
||||
|
||||
if ($prefixCountry !== 'DE' && ! in_array($prefixCountry, (array) config('billing.eu_country_codes', []), true)) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
$user->createOrGetStripeCustomer();
|
||||
|
||||
$alreadySet = collect($user->taxIds())
|
||||
->contains(fn (object $taxId): bool => strtoupper((string) $taxId->value) === $vatId);
|
||||
|
||||
if (! $alreadySet) {
|
||||
$user->createTaxId('eu_vat', $vatId);
|
||||
}
|
||||
} catch (\Throwable $exception) {
|
||||
Log::warning('USt-ID konnte nicht an Stripe übergeben werden.', [
|
||||
'user_id' => $user->id,
|
||||
'error' => $exception->getMessage(),
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gemeinsame Session-Optionen: Stripe Tax braucht eine gültige
|
||||
* Kundenadresse — die im Checkout erfasste Rechnungsadresse (und der
|
||||
|
|
@ -69,6 +110,8 @@ class StripeCheckoutService
|
|||
*/
|
||||
public function forSinglePurchase(User $user, SinglePurchase $purchase): Checkout
|
||||
{
|
||||
$this->syncTaxIdFromBillingAddress($user);
|
||||
|
||||
return $user->checkout([config('billing.single_pm_stripe_price_id') => 1], [
|
||||
...$this->sessionOptions(),
|
||||
'metadata' => ['single_purchase_id' => (string) $purchase->id],
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue