cart->subtotal(); $country = session('checkout_country', 'DE'); $shippingRate = ShippingRate::forCart($subtotal, $country); $shippingCost = $shippingRate ? $shippingRate->getCostForTotal($subtotal) : 0; $discount = 0; if ($code = session('coupon_code')) { $coupon = Coupon::findValid($code); if ($coupon) $discount = $coupon->calcDiscount($subtotal); } $total = max(0, $subtotal - $discount) + $shippingCost; $stripe = new StripeClient(config('services.stripe.secret')); $intent = $stripe->paymentIntents->create([ 'amount' => (int) round($total * 100), 'currency' => 'eur', 'automatic_payment_methods' => ['enabled' => true], ]); return response()->json(['client_secret' => $intent->client_secret]); } public function success(Request $request) { $checkoutData = session('checkout_data'); $paymentIntent = $request->input('payment_intent'); if (!$checkoutData || !$paymentIntent) { return redirect()->route('checkout.index'); } $stripe = new StripeClient(config('services.stripe.secret')); $intent = $stripe->paymentIntents->retrieve($paymentIntent); if ($intent->status !== 'succeeded') { return redirect()->route('checkout.confirm')->with('error', 'Zahlung nicht abgeschlossen.'); } $checkoutData['payment_method'] = 'stripe'; $order = $this->orderService->createFromSession($checkoutData, 'stripe'); $order->update([ 'payment_id' => $paymentIntent, 'status' => 'payment_received', 'paid_at' => now(), ]); session()->forget(['checkout_data', 'checkout_country']); return redirect()->route('checkout.thankyou', $order->order_number); } }