cart()->withProducts()->first(); $totalAmount = 0; $lineItems = []; foreach ($cart->products as $product) { $priceInCents = (int) ($product->pivot->price * 100); $totalAmount += ($priceInCents * $product->pivot->quantity); $lineItems[] = new StripeLineItemDTO( currency: StripeCurrency::INR, price: $priceInCents, productName: $product->title, productDescription: $product->description, quantity: $product->pivot->quantity, ); } $currency = StripeCurrency::INR->value; try { $data = new StripeSessionDataDTO( lineItems: $lineItems, mode: StripePaymentMode::Payment, successUrl: config('app.frontend_url').'/checkout/confirmation?order_id='.$order->id.'&session_id={CHECKOUT_SESSION_ID}', cancelUrl: config('app.frontend_url').'/checkout/payment?order_id='.$order->id, ); $session = Session::create($data->toArray()); // add stripe session to order $order->stripeSession()->create( [ 'session_id' => $session->id, ] ); return PaymentResponseDTO::success( transactionId: $session->id, amount: $totalAmount, currency: $currency, method: PaymentModes::StripeCheckout, redirectUrl: $session->url, ); } catch (Exception $e) { Log::error('Stripe Checkout session cannot be created.', ['error' => $e->getMessage()]); return PaymentResponseDTO::failure( amount: $totalAmount, currency: $currency, method: PaymentModes::StripeCheckout, errorMessage: 'Payment gateway unavailable. Please try again.' ); } } }