Merge pull request 'main' (#8) from main into testing
All checks were successful
CityCards-Website / Build-CityCards-Website (push) Successful in 22s
All checks were successful
CityCards-Website / Build-CityCards-Website (push) Successful in 22s
Reviewed-on: #8
This commit is contained in:
@@ -290,6 +290,7 @@ export function PaymentDetailsPage({
|
|||||||
const { checkoutPageUrl } = payResponse;
|
const { checkoutPageUrl } = payResponse;
|
||||||
|
|
||||||
localStorage.setItem('pendingBookingId', bookingId);
|
localStorage.setItem('pendingBookingId', bookingId);
|
||||||
|
sessionStorage.setItem('pendingBookingId', bookingId);
|
||||||
|
|
||||||
if (!checkoutPageUrl || typeof checkoutPageUrl !== 'string') {
|
if (!checkoutPageUrl || typeof checkoutPageUrl !== 'string') {
|
||||||
throw new Error('Invalid checkout URL received from server');
|
throw new Error('Invalid checkout URL received from server');
|
||||||
|
|||||||
@@ -13,7 +13,6 @@ interface PaymentSuccessPageProps {
|
|||||||
onSignOutClick?: () => void;
|
onSignOutClick?: () => void;
|
||||||
currentPage?: string;
|
currentPage?: string;
|
||||||
user?: { email: string; name: string } | null;
|
user?: { email: string; name: string } | null;
|
||||||
// Add other handlers if needed (optional)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export function PaymentSuccessPage({
|
export function PaymentSuccessPage({
|
||||||
@@ -33,12 +32,26 @@ export function PaymentSuccessPage({
|
|||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const confirm = async () => {
|
const confirm = async () => {
|
||||||
// Retrieve bookingId from localStorage (set before redirect)
|
// Try multiple sources for bookingId
|
||||||
const bookingId = localStorage.getItem('pendingBookingId');
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log('Retrieved bookingId:', bookingId);
|
||||||
|
console.log('SessionId from URL:', sessionId);
|
||||||
|
|
||||||
if (!bookingId) {
|
if (!bookingId) {
|
||||||
setStatus('error');
|
setStatus('error');
|
||||||
setErrorMsg('Missing booking information. Please contact support.');
|
setErrorMsg(
|
||||||
|
'Missing booking information. Please contact support with your order reference. ' +
|
||||||
|
'If you just completed payment, your order may still be processing.'
|
||||||
|
);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -49,24 +62,25 @@ export function PaymentSuccessPage({
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// ✅ Send both bookingId and sessionId to backend
|
|
||||||
await confirmPayment({ bookingId, sessionId }).unwrap();
|
await confirmPayment({ bookingId, sessionId }).unwrap();
|
||||||
setStatus('success');
|
setStatus('success');
|
||||||
toast.success('Payment confirmed! Your order is complete.');
|
toast.success('Payment confirmed! Your order is complete.');
|
||||||
// Clear the stored bookingId
|
// Clean up storage
|
||||||
localStorage.removeItem('pendingBookingId');
|
localStorage.removeItem('pendingBookingId');
|
||||||
|
sessionStorage.removeItem('pendingBookingId');
|
||||||
} catch (err: any) {
|
} catch (err: any) {
|
||||||
console.error('Payment confirmation error:', err);
|
console.error('Payment confirmation error:', err);
|
||||||
setStatus('error');
|
setStatus('error');
|
||||||
setErrorMsg(err?.data?.message || 'Payment could not be confirmed. Please contact support.');
|
setErrorMsg(err?.data?.message || 'Payment could not be confirmed. Please contact support.');
|
||||||
toast.error('Payment confirmation failed');
|
toast.error('Payment confirmation failed');
|
||||||
// Optionally clear pending booking on error to avoid infinite loops
|
// Clean up storage to avoid infinite loops
|
||||||
localStorage.removeItem('pendingBookingId');
|
localStorage.removeItem('pendingBookingId');
|
||||||
|
sessionStorage.removeItem('pendingBookingId');
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
confirm();
|
confirm();
|
||||||
}, [sessionId, confirmPayment]);
|
}, [sessionId, confirmPayment, searchParams]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="min-h-screen bg-[#fafafa] font-poppins">
|
<div className="min-h-screen bg-[#fafafa] font-poppins">
|
||||||
@@ -113,7 +127,7 @@ export function PaymentSuccessPage({
|
|||||||
<h2 className="text-2xl font-semibold text-[#2a2a2a]">Payment Successful!</h2>
|
<h2 className="text-2xl font-semibold text-[#2a2a2a]">Payment Successful!</h2>
|
||||||
<p className="text-[#555] mt-2">Thank you for your purchase. Your order is now confirmed.</p>
|
<p className="text-[#555] mt-2">Thank you for your purchase. Your order is now confirmed.</p>
|
||||||
<button
|
<button
|
||||||
onClick={() => navigate('/my-orders')} // adjust to your orders page route
|
onClick={() => navigate('/my-orders')}
|
||||||
className="mt-6 px-6 py-3 bg-[#F95F62] text-white rounded-xl font-medium hover:bg-[#e8545a] transition"
|
className="mt-6 px-6 py-3 bg-[#F95F62] text-white rounded-xl font-medium hover:bg-[#e8545a] transition"
|
||||||
>
|
>
|
||||||
View My Orders
|
View My Orders
|
||||||
|
|||||||
Reference in New Issue
Block a user