orders() ->whereId($orderId) ->first(); if (! $order) { throw new AccessDeniedHttpException('Order is not made by you'); } if (! $order->stripeSession()->where('session_id', $stripeSessionId)->exists()) { throw new AccessDeniedHttpException('Stripe session is not made by you'); } try { $session = $this->stripe->checkout->sessions->retrieve($stripeSessionId); } catch (ApiErrorException $e) { Log::error('Stripe api is not available: ', [$e->getMessage()]); throw new ServiceUnavailableHttpException('Stripe api is not available'); } catch (Exception $e) { throw new NotFoundHttpException('Invalid Stripe session id'); } if ($session->payment_status !== 'paid' || $session->status !== 'complete') { return VerifiedCheckoutResponseDTO::failure('Payment Unsuccessful'); } return VerifiedCheckoutResponseDTO::success( message: 'Payment Successful', amount: $session->amount_total, transactionId: $session->payment_intent, mode: $session->payment_method_types[0], ); } }