This commit is contained in:
Iliyan Angelov
2025-11-21 01:20:51 +02:00
parent a38ab4fa82
commit 6f85b8cf17
242 changed files with 7154 additions and 14492 deletions

View File

@@ -40,7 +40,7 @@ const FullPaymentPage: React.FC = () => {
setLoading(true);
setError(null);
// Fetch booking details
const bookingResponse = await getBookingById(id);
if (!bookingResponse.success || !bookingResponse.data?.booking) {
throw new Error('Booking not found');
@@ -49,21 +49,21 @@ const FullPaymentPage: React.FC = () => {
const bookingData = bookingResponse.data.booking;
setBooking(bookingData);
// Check if booking is already confirmed - redirect to booking details
if (bookingData.status === 'confirmed' || bookingData.status === 'checked_in') {
toast.success('Booking is already confirmed!');
navigate(`/bookings/${id}`);
return;
}
// Check if booking uses Stripe payment method
if (bookingData.payment_method !== 'stripe') {
toast.info('This booking does not use Stripe payment');
navigate(`/bookings/${id}`);
return;
}
// Fetch payments
const paymentsResponse = await getPaymentsByBookingId(id);
console.log('Payments response:', paymentsResponse);
@@ -71,7 +71,7 @@ const FullPaymentPage: React.FC = () => {
const payments = paymentsResponse.data.payments;
console.log('Payments found:', payments);
// Find pending Stripe payment (full payment)
const stripePaymentFound = payments.find(
(p: Payment) =>
(p.payment_method === 'stripe' || p.payment_method === 'credit_card') &&
@@ -82,7 +82,7 @@ const FullPaymentPage: React.FC = () => {
console.log('Found pending Stripe payment:', stripePaymentFound);
setStripePayment(stripePaymentFound);
} else {
// Check if payment is already completed
const completedPayment = payments.find(
(p: Payment) =>
(p.payment_method === 'stripe' || p.payment_method === 'credit_card') &&
@@ -93,8 +93,8 @@ const FullPaymentPage: React.FC = () => {
console.log('Found completed Stripe payment:', completedPayment);
setStripePayment(completedPayment);
setPaymentSuccess(true);
// If payment is completed and booking is confirmed, redirect
if (bookingData.status === 'confirmed' || bookingData.status === 'checked_in') {
if ((bookingData.status as string) === 'confirmed' || (bookingData.status as string) === 'checked_in') {
toast.info('Payment already completed. Booking is confirmed.');
setTimeout(() => {
navigate(`/bookings/${id}`);
@@ -102,16 +102,16 @@ const FullPaymentPage: React.FC = () => {
return;
}
} else {
// If no Stripe payment found, check if we can use booking data to create payment info
console.warn('No Stripe payment found in payments array:', payments);
console.warn('Booking payment method:', bookingData.payment_method);
// If booking uses Stripe but no payment record exists, this is an error
throw new Error('No Stripe payment record found for this booking. The payment may not have been created properly.');
}
}
} else {
// If payments endpoint fails or returns no payments, check booking payments array
console.warn('Payments response not successful or no payments data:', paymentsResponse);
if (bookingData.payments && bookingData.payments.length > 0) {
@@ -123,12 +123,12 @@ const FullPaymentPage: React.FC = () => {
);
if (stripePaymentFromBooking) {
setStripePayment(stripePaymentFromBooking as Payment);
setStripePayment(stripePaymentFromBooking as unknown as Payment);
} else {
throw new Error('No pending Stripe payment found for this booking');
}
} else {
// If no payments found at all, this might be a timing issue - wait a moment and retry
console.error('No payments found for booking. This might be a timing issue.');
throw new Error('Payment information not found. Please wait a moment and refresh, or contact support if the issue persists.');
}
@@ -181,15 +181,15 @@ const FullPaymentPage: React.FC = () => {
);
}
// Get payment amount, but validate it's reasonable
let paymentAmount = parseFloat(stripePayment.amount.toString());
const isPaymentCompleted = stripePayment.payment_status === 'completed';
// Log payment amount for debugging
console.log('Payment amount from payment record:', paymentAmount);
console.log('Booking total price:', booking?.total_price);
// If payment amount seems incorrect (too large or doesn't match booking), use booking total
if (paymentAmount > 999999.99 || (booking && Math.abs(paymentAmount - booking.total_price) > 0.01)) {
console.warn('Payment amount seems incorrect, using booking total price instead');
if (booking) {
@@ -198,7 +198,7 @@ const FullPaymentPage: React.FC = () => {
}
}
// Final validation - ensure amount is reasonable for Stripe
if (paymentAmount > 999999.99) {
const errorMsg = `Payment amount $${paymentAmount.toLocaleString()} exceeds Stripe's maximum. Please contact support.`;
console.error(errorMsg);
@@ -209,7 +209,7 @@ const FullPaymentPage: React.FC = () => {
return (
<div className="min-h-screen bg-gradient-to-b from-[#0f0f0f] via-[#1a1a1a] to-[#0f0f0f] py-8">
<div className="max-w-4xl mx-auto px-4">
{/* Back Button */}
{}
<Link
to={`/bookings/${bookingId}`}
className="inline-flex items-center gap-2
@@ -221,7 +221,7 @@ const FullPaymentPage: React.FC = () => {
<span>Back to booking details</span>
</Link>
{/* Success Header (if paid) */}
{}
{isPaymentCompleted && (
<div
className="bg-gradient-to-br from-green-900/20 to-green-800/10
@@ -247,7 +247,7 @@ const FullPaymentPage: React.FC = () => {
</div>
)}
{/* Pending Header */}
{}
{!isPaymentCompleted && (
<div
className="bg-gradient-to-br from-[#d4af37]/10 to-[#c9a227]/5
@@ -274,9 +274,9 @@ const FullPaymentPage: React.FC = () => {
)}
<div className="grid grid-cols-1 lg:grid-cols-3 gap-6">
{/* Payment Info */}
{}
<div className="lg:col-span-2 space-y-6">
{/* Payment Summary */}
{}
<div
className="bg-gradient-to-br from-[#1a1a1a] to-[#0a0a0a]
rounded-xl border border-[#d4af37]/20
@@ -325,7 +325,7 @@ const FullPaymentPage: React.FC = () => {
)}
</div>
{/* Stripe Payment Panel */}
{}
{!isPaymentCompleted && booking && stripePayment && (
<div
className="bg-gradient-to-br from-[#1a1a1a] to-[#0a0a0a]
@@ -365,7 +365,7 @@ const FullPaymentPage: React.FC = () => {
onSuccess={() => {
setPaymentSuccess(true);
toast.success('✅ Payment successful! Your booking has been confirmed.');
// Navigate to booking details after successful payment
setTimeout(() => {
navigate(`/bookings/${booking.id}`);
}, 2000);
@@ -379,7 +379,7 @@ const FullPaymentPage: React.FC = () => {
)}
</div>
{/* Booking Summary Sidebar */}
{}
<div className="lg:col-span-1">
<div
className="bg-gradient-to-br from-[#1a1a1a] to-[#0a0a0a]