From 03dabde97943412faedacef10bfeded2edde555f Mon Sep 17 00:00:00 2001 From: Hemant Vishwakarma Date: Wed, 22 Apr 2026 18:00:33 +0530 Subject: [PATCH] New changes in paymentsuccesspage --- src/pages/PaymentSuccessPage.tsx | 81 +++++++------------------------- 1 file changed, 16 insertions(+), 65 deletions(-) diff --git a/src/pages/PaymentSuccessPage.tsx b/src/pages/PaymentSuccessPage.tsx index 97acade..0f6fb1e 100644 --- a/src/pages/PaymentSuccessPage.tsx +++ b/src/pages/PaymentSuccessPage.tsx @@ -1,6 +1,6 @@ import React, { useEffect, useState } from 'react'; import { useNavigate, useSearchParams } from 'react-router-dom'; -import { CheckCircle, XCircle, Loader2, AlertCircle } from 'lucide-react'; +import { CheckCircle, XCircle, Loader2 } from 'lucide-react'; import { useConfirmCardPaymentMutation } from '../Redux/services/cards.service'; import { toast } from 'sonner'; import Navbar from '../components/Navbar'; @@ -33,13 +33,12 @@ export function PaymentSuccessPage({ }: PaymentSuccessPageProps) { const [searchParams] = useSearchParams(); const [confirmPayment, { isLoading }] = useConfirmCardPaymentMutation(); - const [status, setStatus] = useState<'loading' | 'success' | 'error' | 'manual'>('loading'); + const [status, setStatus] = useState<'loading' | 'success' | 'error'>('loading'); const [errorMsg, setErrorMsg] = useState(''); - const [manualBookingId, setManualBookingId] = useState(''); const navigate = useNavigate(); useEffect(() => { - const retrieveBookingId = async () => { + const confirm = async () => { // Try all possible sources let bookingId = getCookie('pendingBookingId'); if (!bookingId) bookingId = localStorage.getItem('pendingBookingId'); @@ -55,7 +54,11 @@ export function PaymentSuccessPage({ }); if (!bookingId) { - setStatus('manual'); // show manual entry form + setStatus('error'); + setErrorMsg( + 'Booking ID not found. Please contact support with your order details. ' + + 'If you just completed payment, your order may still be processing.' + ); return; } @@ -63,7 +66,7 @@ export function PaymentSuccessPage({ await confirmPayment(bookingId).unwrap(); setStatus('success'); toast.success('Payment confirmed! Your order is complete.'); - // Clean up + // Clean up all storage document.cookie = 'pendingBookingId=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;'; localStorage.removeItem('pendingBookingId'); sessionStorage.removeItem('pendingBookingId'); @@ -72,34 +75,16 @@ export function PaymentSuccessPage({ setStatus('error'); setErrorMsg(err?.data?.message || 'Failed to confirm payment. Please contact support.'); toast.error('Confirmation failed'); + // Clean up to avoid retry loops + document.cookie = 'pendingBookingId=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;'; + localStorage.removeItem('pendingBookingId'); + sessionStorage.removeItem('pendingBookingId'); } }; - retrieveBookingId(); + confirm(); }, [confirmPayment, searchParams]); - const handleManualConfirm = async () => { - if (!manualBookingId.trim()) { - toast.error('Please enter your Booking ID'); - return; - } - setStatus('loading'); - try { - await confirmPayment(manualBookingId).unwrap(); - setStatus('success'); - toast.success('Payment confirmed! Your order is complete.'); - // Clean up - document.cookie = 'pendingBookingId=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;'; - localStorage.removeItem('pendingBookingId'); - sessionStorage.removeItem('pendingBookingId'); - } catch (err: any) { - console.error('Manual confirmation error:', err); - setStatus('error'); - setErrorMsg(err?.data?.message || 'Failed to confirm payment. Please contact support.'); - toast.error('Confirmation failed'); - } - }; - return (
Payment Successful!

Thank you for your purchase. Your order is now confirmed.

)} @@ -166,40 +151,6 @@ export function PaymentSuccessPage({ )} - - {status === 'manual' && ( - <> - -

Booking ID Not Found

-

- We couldn't automatically retrieve your booking ID. Please enter it below to confirm your payment. -
- (Check your email or order history for the Booking ID) -

-
- setManualBookingId(e.target.value)} - placeholder="Enter Booking ID" - className="w-full border rounded-xl px-4 py-3 font-poppins text-base outline-none focus:border-[#F95F62]" - /> - -
- - - )}