struktur der webseiten-js angepasst. filament aktualisiert.
This commit is contained in:
@@ -1,181 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Auth;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\User;
|
||||
use App\Models\Tenant;
|
||||
use App\Models\Package;
|
||||
use App\Models\TenantPackage;
|
||||
use App\Models\PackagePurchase;
|
||||
use Illuminate\Auth\Events\Registered;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
use Illuminate\Support\Facades\Mail;
|
||||
use Illuminate\Validation\Rules;
|
||||
use Illuminate\Support\Str;
|
||||
use Illuminate\Support\Facades\App;
|
||||
use Inertia\Inertia;
|
||||
use Inertia\Response;
|
||||
|
||||
class MarketingRegisterController extends Controller
|
||||
{
|
||||
/**
|
||||
* Show the registration page.
|
||||
*/
|
||||
public function create(Request $request): Response
|
||||
{
|
||||
$package_id = $request->query('package_id');
|
||||
$package = $package_id ? Package::find($package_id) : null;
|
||||
|
||||
$privacyHtml = view('legal.datenschutz-partial')->render();
|
||||
|
||||
return Inertia::render('auth/register', [
|
||||
'package' => $package,
|
||||
'privacyHtml' => $privacyHtml,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle an incoming registration request.
|
||||
*
|
||||
* @throws \Illuminate\Validation\ValidationException
|
||||
*/
|
||||
public function store(Request $request)
|
||||
{
|
||||
$validated = $request->validate([
|
||||
'username' => ['required', 'string', 'max:255', 'unique:'.User::class],
|
||||
'email' => ['required', 'string', 'lowercase', 'email', 'max:255', 'unique:'.User::class],
|
||||
'password' => ['required', 'confirmed', Rules\Password::defaults()],
|
||||
'first_name' => ['required', 'string', 'max:255'],
|
||||
'last_name' => ['required', 'string', 'max:255'],
|
||||
'address' => ['required', 'string', 'max:500'],
|
||||
'phone' => ['required', 'string', 'max:20'],
|
||||
'privacy_consent' => ['accepted'],
|
||||
'package_id' => ['nullable', 'integer'],
|
||||
]);
|
||||
|
||||
$shouldAutoVerify = App::environment(['local', 'testing']);
|
||||
|
||||
$user = User::create([
|
||||
'username' => $validated['username'],
|
||||
'email' => $validated['email'],
|
||||
'first_name' => $validated['first_name'],
|
||||
'last_name' => $validated['last_name'],
|
||||
'address' => $validated['address'],
|
||||
'phone' => $validated['phone'],
|
||||
'password' => Hash::make($validated['password']),
|
||||
'role' => 'user',
|
||||
'pending_purchase' => !empty($validated['package_id']),
|
||||
]);
|
||||
|
||||
if ($user->pending_purchase) {
|
||||
session()->put('pending_user_id', $user->id);
|
||||
}
|
||||
|
||||
if ($shouldAutoVerify) {
|
||||
$user->forceFill(['email_verified_at' => now()])->save();
|
||||
}
|
||||
|
||||
$tenant = Tenant::create([
|
||||
'user_id' => $user->id,
|
||||
'name' => $validated['first_name'] . ' ' . $validated['last_name'],
|
||||
'slug' => Str::slug($validated['first_name'] . ' ' . $validated['last_name'] . '-' . now()->timestamp),
|
||||
'email' => $validated['email'],
|
||||
'is_active' => true,
|
||||
'is_suspended' => false,
|
||||
'event_credits_balance' => 0,
|
||||
'subscription_tier' => 'free',
|
||||
'subscription_expires_at' => null,
|
||||
'settings' => json_encode([
|
||||
'branding' => [
|
||||
'logo_url' => null,
|
||||
'primary_color' => '#3B82F6',
|
||||
'secondary_color' => '#1F2937',
|
||||
'font_family' => 'Inter, sans-serif',
|
||||
],
|
||||
'features' => [
|
||||
'photo_likes_enabled' => false,
|
||||
'event_checklist' => false,
|
||||
'custom_domain' => false,
|
||||
'advanced_analytics' => false,
|
||||
],
|
||||
'custom_domain' => null,
|
||||
'contact_email' => $validated['email'],
|
||||
'event_default_type' => 'general',
|
||||
]),
|
||||
]);
|
||||
|
||||
event(new Registered($user));
|
||||
|
||||
Auth::login($user);
|
||||
|
||||
// Send Welcome Email
|
||||
Mail::to($user)->queue(new \App\Mail\Welcome($user));
|
||||
|
||||
$dashboardUrl = route('dashboard');
|
||||
|
||||
if (!empty($validated['package_id'])) {
|
||||
$package = Package::find($validated['package_id']);
|
||||
if (!$package) {
|
||||
$request->session()->flash('error', __('auth.registration_failed'));
|
||||
// No action if package not found
|
||||
return redirect()->route('dashboard')->with('success', __('auth.registration_success'));
|
||||
} else if ((float) $package->price <= 0.0) {
|
||||
// Assign free package
|
||||
TenantPackage::create([
|
||||
'tenant_id' => $tenant->id,
|
||||
'package_id' => $package->id,
|
||||
'active' => true,
|
||||
'price' => 0,
|
||||
]);
|
||||
|
||||
PackagePurchase::create([
|
||||
'tenant_id' => $tenant->id,
|
||||
'package_id' => $package->id,
|
||||
'type' => $package->type === 'endcustomer' ? 'endcustomer_event' : 'reseller_subscription',
|
||||
'price' => 0,
|
||||
'purchased_at' => now(),
|
||||
'provider_id' => 'free',
|
||||
]);
|
||||
|
||||
$tenant->update(['subscription_status' => 'active']);
|
||||
|
||||
$user->update(['role' => 'tenant_admin', 'pending_purchase' => false]);
|
||||
Auth::login($user); // Re-login to refresh session
|
||||
|
||||
$request->session()->flash('success', __('auth.registration_success'));
|
||||
|
||||
if ($shouldAutoVerify) {
|
||||
return redirect()->route('dashboard')->with('success', __('auth.registration_success'));
|
||||
} else {
|
||||
return redirect()->route('verification.notice')->with('status', 'registration-success');
|
||||
}
|
||||
} else {
|
||||
// For paid package, keep pending_purchase true, redirect to buy
|
||||
$request->session()->flash('success', __('auth.registration_success'));
|
||||
return redirect()->route('buy.packages', $package->id)->with('success', __('auth.registration_success'));
|
||||
}
|
||||
}
|
||||
|
||||
// No package
|
||||
$request->session()->flash('success', __('auth.registration_success'));
|
||||
|
||||
if ($shouldAutoVerify) {
|
||||
return redirect()->route('dashboard')->with('success', __('auth.registration_success'));
|
||||
}
|
||||
|
||||
session()->flash('status', 'registration-success');
|
||||
|
||||
return redirect()->route('verification.notice');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -13,7 +13,7 @@ use Illuminate\Support\Facades\Mail;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
use Illuminate\Validation\Rules\Password;
|
||||
use Inertia\Inertia;
|
||||
use Laravel\Cashier\Cashier;
|
||||
use Illuminate\Support\Str;
|
||||
use Stripe\PaymentIntent;
|
||||
use Stripe\Stripe;
|
||||
|
||||
@@ -51,8 +51,9 @@ class CheckoutController extends Controller
|
||||
}
|
||||
|
||||
$package = Package::findOrFail($request->package_id);
|
||||
|
||||
DB::transaction(function () use ($request, $package) {
|
||||
$validated = $validator->validated();
|
||||
DB::transaction(function () use ($request, $package, $validated) {
|
||||
|
||||
// User erstellen
|
||||
$user = User::create([
|
||||
'email' => $request->email,
|
||||
@@ -62,12 +63,33 @@ class CheckoutController extends Controller
|
||||
|
||||
// Tenant erstellen
|
||||
$tenant = Tenant::create([
|
||||
'name' => 'Neuer Tenant',
|
||||
'domain' => null,
|
||||
'database' => null,
|
||||
'user_id' => $user->id,
|
||||
]);
|
||||
|
||||
'user_id' => $user->id,
|
||||
'name' => $validated['first_name'] . ' ' . $validated['last_name'],
|
||||
'slug' => Str::slug($validated['first_name'] . ' ' . $validated['last_name'] . '-' . now()->timestamp),
|
||||
'email' => $validated['email'],
|
||||
'is_active' => true,
|
||||
'is_suspended' => false,
|
||||
'event_credits_balance' => 0,
|
||||
'subscription_tier' => 'free',
|
||||
'subscription_expires_at' => null,
|
||||
'settings' => json_encode([
|
||||
'branding' => [
|
||||
'logo_url' => null,
|
||||
'primary_color' => '#3B82F6',
|
||||
'secondary_color' => '#1F2937',
|
||||
'font_family' => 'Inter, sans-serif',
|
||||
],
|
||||
'features' => [
|
||||
'photo_likes_enabled' => false,
|
||||
'event_checklist' => false,
|
||||
'custom_domain' => false,
|
||||
'advanced_analytics' => false,
|
||||
],
|
||||
'custom_domain' => null,
|
||||
'contact_email' => $validated['email'],
|
||||
'event_default_type' => 'general',
|
||||
]),
|
||||
]);
|
||||
// Package zuweisen
|
||||
$tenant->packages()->attach($package->id, [
|
||||
'purchased_at' => now(),
|
||||
|
||||
@@ -58,7 +58,7 @@ class MarketingController extends Controller
|
||||
|
||||
public function contactView()
|
||||
{
|
||||
return Inertia::render('legal.kontakt');
|
||||
return Inertia::render('marketing.Kontakt');
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,107 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\PackagePurchase;
|
||||
use App\Models\Tenant;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Stripe\Stripe;
|
||||
use Stripe\PaymentIntent;
|
||||
use Stripe\Subscription;
|
||||
|
||||
class StripeController extends Controller
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
Stripe::setApiKey(config('services.stripe.secret'));
|
||||
}
|
||||
|
||||
public function createPaymentIntent(Request $request)
|
||||
{
|
||||
$request->validate([
|
||||
'tenant_id' => 'required|exists:tenants,id',
|
||||
'package_id' => 'required|exists:packages,id',
|
||||
'amount' => 'required|numeric|min:0',
|
||||
]);
|
||||
|
||||
$tenant = Tenant::findOrFail($request->tenant_id);
|
||||
$package = \App\Models\Package::findOrFail($request->package_id);
|
||||
|
||||
$paymentIntent = PaymentIntent::create([
|
||||
'amount' => $request->amount * 100, // cents
|
||||
'currency' => 'eur',
|
||||
'metadata' => [
|
||||
'tenant_id' => $tenant->id,
|
||||
'package_id' => $package->id,
|
||||
'type' => 'endcustomer_event', // or reseller
|
||||
],
|
||||
]);
|
||||
|
||||
return response()->json([
|
||||
'client_secret' => $paymentIntent->client_secret,
|
||||
]);
|
||||
}
|
||||
|
||||
public function createSubscription(Request $request)
|
||||
{
|
||||
$request->validate([
|
||||
'tenant_id' => 'required|exists:tenants,id',
|
||||
'package_id' => 'required|exists:packages,id',
|
||||
'payment_method_id' => 'required',
|
||||
]);
|
||||
|
||||
$tenant = Tenant::findOrFail($request->tenant_id);
|
||||
$package = \App\Models\Package::findOrFail($request->package_id);
|
||||
|
||||
$subscription = Subscription::create([
|
||||
'customer' => $tenant->stripe_customer_id ?? $this->createCustomer($tenant),
|
||||
'items' => [[
|
||||
'price' => $package->stripe_price_id, // Assume package has stripe_price_id
|
||||
]],
|
||||
'payment_method' => $request->payment_method_id,
|
||||
'default_payment_method' => $request->payment_method_id,
|
||||
'expand' => ['latest_invoice.payment_intent'],
|
||||
'metadata' => [
|
||||
'tenant_id' => $tenant->id,
|
||||
'package_id' => $package->id,
|
||||
'type' => 'reseller_subscription',
|
||||
],
|
||||
]);
|
||||
|
||||
// Create TenantPackage and PackagePurchase
|
||||
\App\Models\TenantPackage::create([
|
||||
'tenant_id' => $tenant->id,
|
||||
'package_id' => $package->id,
|
||||
'purchased_at' => now(),
|
||||
'expires_at' => now()->addYear(),
|
||||
'active' => true,
|
||||
]);
|
||||
|
||||
PackagePurchase::create([
|
||||
'tenant_id' => $tenant->id,
|
||||
'package_id' => $package->id,
|
||||
'provider_id' => $subscription->id,
|
||||
'price' => $package->price,
|
||||
'type' => 'reseller_subscription',
|
||||
'purchased_at' => now(),
|
||||
]);
|
||||
|
||||
return response()->json([
|
||||
'subscription_id' => $subscription->id,
|
||||
'client_secret' => $subscription->latest_invoice->payment_intent->client_secret ?? null,
|
||||
]);
|
||||
}
|
||||
|
||||
private function createCustomer(Tenant $tenant)
|
||||
{
|
||||
$customer = \Stripe\Customer::create([
|
||||
'email' => $tenant->email,
|
||||
'metadata' => ['tenant_id' => $tenant->id],
|
||||
]);
|
||||
|
||||
$tenant->update(['stripe_customer_id' => $customer->id]);
|
||||
|
||||
return $customer->id;
|
||||
}
|
||||
}
|
||||
@@ -1,21 +0,0 @@
|
||||
// Create PackagePurchase for one-off payment
|
||||
$purchase = \App\Models\PackagePurchase::create([
|
||||
'tenant_id' => $tenantId,
|
||||
'package_id' => $packageId,
|
||||
'provider_id' => $paymentIntent['id'],
|
||||
'price' => $paymentIntent['amount_received'] / 100,
|
||||
'type' => $type,
|
||||
'purchased_at' => now(),
|
||||
'refunded' => false,
|
||||
]);
|
||||
|
||||
// Send purchase confirmation email
|
||||
try {
|
||||
$tenant = \App\Models\Tenant::find($tenantId);
|
||||
if ($tenant && $tenant->user) {
|
||||
Mail::to($tenant->user)->queue(new PurchaseConfirmation($purchase));
|
||||
Log::info('Purchase confirmation email sent for payment intent: ' . $paymentIntent['id']);
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
Log::error('Failed to send purchase confirmation email: ' . $e->getMessage());
|
||||
}
|
||||
Reference in New Issue
Block a user