Add PayPal, Stripe, CSV-Export; fix .env.production issue
Deploy to Production (witstore.wende.it) / deploy (push) Successful in 7s
Deploy to Production (witstore.wende.it) / deploy (push) Successful in 7s
- PayPal: Checkout-Integration via srmklive/paypal, Weiterleitung zu PayPal, Bestellung wird nach Capture automatisch auf payment_received gesetzt - Stripe: Payment Elements im Checkout, Intent-API, Zahlung direkt bestätigt - CSV-Export: Admin → Bestellungen → CSV exportieren (UTF-8 BOM für Excel) - PayPal/Stripe nur sichtbar wenn Keys in .env gesetzt - .env.example um PAYPAL_* und STRIPE_* Keys erweitert Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,69 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Shop;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Coupon;
|
||||
use App\Models\Order;
|
||||
use App\Models\ShippingRate;
|
||||
use App\Services\CartService;
|
||||
use App\Services\OrderService;
|
||||
use Illuminate\Http\Request;
|
||||
use Stripe\StripeClient;
|
||||
|
||||
class StripeController extends Controller
|
||||
{
|
||||
public function __construct(private CartService $cart, private OrderService $orderService) {}
|
||||
|
||||
public function createIntent(Request $request)
|
||||
{
|
||||
$subtotal = $this->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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user