"use client"; import { React, useState, useEffect } from 'react' import { useSearchParams } from 'next/navigation' import Navbar from "../../../components/navbar"; import Loader from '../../../components/loader'; const ResultPage = () => { const session_id = useSearchParams().get('session_id'); const [loading, setLoading] = useState(true); const [session, setSession] = useState(null); const [error, setError] = useState(null); useEffect(() => { const fetchCheckoutSession = async () => { if (!session_id) return; try { const res = await fetch(`/api/checkout_sessions?session_id=${session_id}`); const sessionData = await res.json(); if (res.ok) { setSession(sessionData); } else { setError(sessionData.error); } } catch (err) { setError('An error occurred while retrieving the session.'); } finally { setLoading(false); } }; fetchCheckoutSession(); }, [session_id]); if (loading) { return ; } if (error) { return (
{error}
); } return (

{session.payment_status === 'paid' ? "Thank you for your purchase!" : "Payment failed :("}

Return Home {session.payment_status === 'paid' ? ( <>
Session ID: {session_id}

We have received your payment. You will receive an email with the order details shortly.

Order Summary:
    {session.line_items.map(item => (
  • {item.quantity} x {item.description} - ${item.amount_total / 100}
  • ))}

Total Amount: ${session.amount_total / 100}

Payment Method: {session.payment_method_types.join(', ')}

) : ( <>

Your payment was not successful. Please try again.

Possible reasons for the failure include:

  • Insufficient funds in your account.
  • Incorrect payment details entered.
  • Payment method not supported.
  • Network issues during the transaction.

Please check your payment information and try again.
If the issue persists, consider using a different payment method.

Retry Payment

For further assistance, please contact our support team at support@example.com.

)}
); } export default ResultPage;