'use client'; import React, { useEffect, useState } from "react"; import { useRouter, useSearchParams } from "next/navigation"; import axios from "axios"; import IconXCircle from "@/components/icon/icon-x-circle"; interface PaymentDetails { email: string; amount: number; planId: string; stripeSessionId: string; status: string; created_at: string; } const PaymentFailure: React.FC = () => { const [payment, setPayment] = useState(null); const [loading, setLoading] = useState(true); const [error, setError] = useState(null); const router = useRouter(); const searchParams = useSearchParams(); const sessionId = searchParams.get("session_id"); // Stripe sends session_id in query useEffect(() => { if (!sessionId) { setError("No session_id provided"); setLoading(false); return; } const fetchPaymentDetails = async () => { try { const res:any = await axios.get( `https://ebay.backend.data4autos.com/api/payment/details`, { params: { session_id: sessionId } } ); setPayment(res.data.payment); } catch (err: any) { console.error(err); setError(err.response?.data?.error || "Failed to fetch payment details"); } finally { setLoading(false); } }; fetchPaymentDetails(); }, [sessionId]); if (loading) { return (
Loading payment details...
); } if (error) { return (
{error}
); } return (
{/* ❌ Error Icon */}
{/* ❌ Title */}

Payment Failed ❌

{/* ❌ Subtitle */}

Unfortunately, your payment could not be processed. Please try again or contact support if the issue persists.

{/* ❌ Card with Payment Details */}
Transaction ID: {payment?.stripeSessionId}
Email: {payment?.email}
Plan: {payment?.planId}
Amount: ${payment?.amount / 100}
Payment Status: {payment?.status}
Date: {new Date(payment?.created_at || "").toLocaleString()}
{/* ❌ Buttons */}
{/* ❌ Footer Text */}

Don’t worry — no amount has been deducted from your account.

); }; export default PaymentFailure;