"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
We have received your payment. You will receive an email with the order details shortly.
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:
Please check your payment information and try again.
If the issue persists, consider using a different payment method.
For further assistance, please contact our support team at support@example.com.
> )}