main #31
@@ -24,7 +24,6 @@ export function PaymentSuccessPage({
|
||||
user,
|
||||
}: PaymentSuccessPageProps) {
|
||||
const [searchParams] = useSearchParams();
|
||||
const sessionId = searchParams.get('session_id');
|
||||
const [confirmPayment, { isLoading }] = useConfirmCardPaymentMutation();
|
||||
const [status, setStatus] = useState<'loading' | 'success' | 'error'>('loading');
|
||||
const [errorMsg, setErrorMsg] = useState<string>('');
|
||||
@@ -32,55 +31,43 @@ export function PaymentSuccessPage({
|
||||
|
||||
useEffect(() => {
|
||||
const confirm = async () => {
|
||||
// Try multiple sources for bookingId
|
||||
// Try multiple sources to get bookingId
|
||||
let bookingId = localStorage.getItem('pendingBookingId');
|
||||
if (!bookingId) {
|
||||
bookingId = sessionStorage.getItem('pendingBookingId');
|
||||
}
|
||||
// Optional: if you have bookingId in URL query param (e.g., ?bookingId=123)
|
||||
const urlBookingId = searchParams.get('bookingId');
|
||||
if (!bookingId && urlBookingId) {
|
||||
bookingId = urlBookingId;
|
||||
}
|
||||
|
||||
if (!bookingId) bookingId = sessionStorage.getItem('pendingBookingId');
|
||||
if (!bookingId) bookingId = searchParams.get('bookingId'); // URL query param
|
||||
|
||||
console.log('Retrieved bookingId:', bookingId);
|
||||
console.log('SessionId from URL:', sessionId);
|
||||
|
||||
if (!bookingId) {
|
||||
setStatus('error');
|
||||
setErrorMsg(
|
||||
'Missing booking information. Please contact support with your order reference. ' +
|
||||
'Booking ID not found. Please contact support with your order details. ' +
|
||||
'If you just completed payment, your order may still be processing.'
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!sessionId) {
|
||||
setStatus('error');
|
||||
setErrorMsg('Missing session ID. Please contact support.');
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
await confirmPayment({ bookingId, sessionId }).unwrap();
|
||||
// ✅ Call confirm API with only bookingId
|
||||
await confirmPayment(bookingId).unwrap();
|
||||
setStatus('success');
|
||||
toast.success('Payment confirmed! Your order is complete.');
|
||||
// Clean up storage
|
||||
localStorage.removeItem('pendingBookingId');
|
||||
sessionStorage.removeItem('pendingBookingId');
|
||||
} catch (err: any) {
|
||||
console.error('Payment confirmation error:', err);
|
||||
console.error('Confirmation error:', err);
|
||||
setStatus('error');
|
||||
setErrorMsg(err?.data?.message || 'Payment could not be confirmed. Please contact support.');
|
||||
toast.error('Payment confirmation failed');
|
||||
// Clean up storage to avoid infinite loops
|
||||
setErrorMsg(err?.data?.message || 'Failed to confirm payment. Please contact support.');
|
||||
toast.error('Confirmation failed');
|
||||
// Clean up to avoid retry loops
|
||||
localStorage.removeItem('pendingBookingId');
|
||||
sessionStorage.removeItem('pendingBookingId');
|
||||
}
|
||||
};
|
||||
|
||||
confirm();
|
||||
}, [sessionId, confirmPayment, searchParams]);
|
||||
}, [confirmPayment, searchParams]);
|
||||
|
||||
return (
|
||||
<div className="min-h-screen bg-[#fafafa] font-poppins">
|
||||
|
||||
Reference in New Issue
Block a user