'use client' import { useEffect, useState, Suspense } from 'react' import { useSearchParams, useRouter } from 'next/navigation' import { XCircle, RotateCcw, Home, AlertTriangle, HelpCircle, CreditCard } from 'lucide-react' import { Button } from '@/components/ui/button' import { Card, CardContent } from '@/components/ui/card' interface FailureDetails { txn?: string amount?: string type?: string reason?: string error?: string message?: string } interface FailureInfo { title: string description: string suggestions: string[] icon: typeof XCircle color: string } const FAILURE_REASONS: Record = { 'insufficient-funds': { title: 'Insufficient Funds', description: 'Your payment method does not have enough balance to complete this transaction.', suggestions: [ 'Add money to your payment account', 'Try a different payment method', 'Contact your bank if you believe this is an error' ], icon: CreditCard, color: 'text-red-500' }, 'card-declined': { title: 'Card Declined', description: 'Your card was declined by the bank or payment processor.', suggestions: [ 'Check your card details are correct', 'Ensure your card is not expired', 'Try a different card', 'Contact your bank for more information' ], icon: XCircle, color: 'text-red-500' }, 'timeout': { title: 'Payment Timeout', description: 'The payment took too long to process and timed out.', suggestions: [ 'Check your internet connection', 'Try again with a stable connection', 'Clear your browser cache and cookies' ], icon: AlertTriangle, color: 'text-orange-500' }, 'user-cancelled': { title: 'Payment Cancelled', description: 'The payment was cancelled by you during the process.', suggestions: [ 'You can try the payment again', 'Make sure to complete the payment process', 'Contact support if you need assistance' ], icon: XCircle, color: 'text-gray-500' }, 'invalid-details': { title: 'Invalid Payment Details', description: 'The payment details provided were invalid or incorrect.', suggestions: [ 'Double-check your card number and CVV', 'Verify the expiry date is correct', 'Ensure billing address matches your card' ], icon: AlertTriangle, color: 'text-yellow-500' }, 'unknown': { title: 'Payment Failed', description: 'An unexpected error occurred while processing your payment.', suggestions: [ 'Try again in a few minutes', 'Use a different payment method', 'Contact support if the problem persists' ], icon: HelpCircle, color: 'text-gray-500' } } function PaymentFailedContent() { const searchParams = useSearchParams() const router = useRouter() const [details, setDetails] = useState({}) const [failureInfo, setFailureInfo] = useState(FAILURE_REASONS.unknown) const [countdown, setCountdown] = useState(15) useEffect(() => { // Extract failure details from URL parameters const txn = searchParams.get('txn') const amount = searchParams.get('amount') const type = searchParams.get('type') || 'billing' const reason = searchParams.get('reason') || 'unknown' const error = searchParams.get('error') const message = searchParams.get('message') const failureDetails: FailureDetails = { txn: txn || undefined, amount: amount || undefined, type, reason, error: error || undefined, message: message ? decodeURIComponent(message) : undefined } setDetails(failureDetails) setFailureInfo(FAILURE_REASONS[reason] || FAILURE_REASONS.unknown) // Auto-redirect countdown const timer = setInterval(() => { setCountdown((prev) => { if (prev <= 1) { router.push('/profile') return 0 } return prev - 1 }) }, 1000) return () => clearInterval(timer) }, [searchParams, router]) const handleRetryPayment = () => { if (details.type === 'balance') { router.push('/profile?tab=balance') } else { router.push('/services') } } const handleDashboardRedirect = () => { router.push('/profile') } const handleContactSupport = () => { // TODO: Implement support contact functionality router.push('/contact') } const IconComponent = failureInfo.icon return (
{/* Failure Icon */}
{/* Failure Message */}

{failureInfo.title}

{details.message || failureInfo.description}

{/* Payment Details (if available) */} {details.txn && (
Transaction ID {details.txn}
{details.amount && (
Amount ₹{parseFloat(details.amount).toLocaleString('en-IN', { minimumFractionDigits: 2 })}
)}
Type {details.type === 'balance' ? 'Balance Addition' : 'Service Payment'}
Date {new Date().toLocaleDateString('en-IN', { year: 'numeric', month: 'short', day: 'numeric', hour: '2-digit', minute: '2-digit' })}
)} {/* Action Buttons */}
{/* Suggestions */}

What can you do?

    {failureInfo.suggestions.map((suggestion, index) => (
  • {suggestion}
  • ))}
{/* Support Section */}

Need Help?

If you continue to experience issues, our support team is here to help.

{/* Auto-redirect Notice */}

Redirecting to dashboard in {countdown} seconds

{/* Error Details (for debugging, only show in development) */} {details.error && process.env.NODE_ENV === 'development' && (
Debug Information
                {JSON.stringify({ details, failureInfo }, null, 2)}
              
)}
) } export default function PaymentFailedPage() { return (

Loading...

}>
) }