/** * PendingPaymentView - Full-page view for new users with pending payment * * This is shown to users who: * - Just signed up with a paid plan * - Have account.status === 'pending_payment' * - Have NOT made any successful payments yet * * Payment methods are shown based on user's country: * - Global: Stripe (Credit/Debit Card) + PayPal * - Pakistan (PK): Stripe (Credit/Debit Card) + Bank Transfer */ import { useState, useEffect } from 'react'; import { CreditCardIcon, Building2Icon, CheckCircleIcon, AlertCircleIcon, Loader2Icon, ArrowLeftIcon, LockIcon, } from '../../icons'; import { Card } from '../ui/card'; import Badge from '../ui/badge/Badge'; import Button from '../ui/button/Button'; import { useToast } from '../ui/toast/ToastContainer'; import BankTransferForm from './BankTransferForm'; import { Invoice, getAvailablePaymentGateways, subscribeToPlan, type PaymentGateway, } from '../../services/billing.api'; // PayPal icon component const PayPalIcon = ({ className }: { className?: string }) => ( ); interface PaymentOption { id: string; type: PaymentGateway; name: string; description: string; icon: React.ReactNode; } interface PendingPaymentViewProps { invoice: Invoice | null; userCountry: string; planName: string; planPrice: string; onPaymentSuccess: () => void; } export default function PendingPaymentView({ invoice, userCountry, planName, planPrice, onPaymentSuccess, }: PendingPaymentViewProps) { const toast = useToast(); const [selectedGateway, setSelectedGateway] = useState('stripe'); const [loading, setLoading] = useState(false); const [gatewaysLoading, setGatewaysLoading] = useState(true); const [paymentOptions, setPaymentOptions] = useState([]); const [showBankTransfer, setShowBankTransfer] = useState(false); const isPakistan = userCountry === 'PK'; // Load available payment gateways useEffect(() => { const loadGateways = async () => { setGatewaysLoading(true); try { const gateways = await getAvailablePaymentGateways(); const options: PaymentOption[] = []; // Always show Stripe (Credit Card) if available if (gateways.stripe) { options.push({ id: 'stripe', type: 'stripe', name: 'Credit/Debit Card', description: 'Pay securely with Visa, Mastercard, or other cards', icon: , }); } // For Pakistan: show Bank Transfer // For Global: show PayPal if (isPakistan) { if (gateways.manual) { options.push({ id: 'bank_transfer', type: 'manual', name: 'Bank Transfer', description: 'Pay via local bank transfer (PKR)', icon: , }); } } else { if (gateways.paypal) { options.push({ id: 'paypal', type: 'paypal', name: 'PayPal', description: 'Pay with your PayPal account', icon: , }); } } setPaymentOptions(options); if (options.length > 0) { setSelectedGateway(options[0].type); } } catch (error) { console.error('Failed to load payment gateways:', error); // Fallback to Stripe setPaymentOptions([{ id: 'stripe', type: 'stripe', name: 'Credit/Debit Card', description: 'Pay securely with Visa, Mastercard, or other cards', icon: , }]); } finally { setGatewaysLoading(false); } }; loadGateways(); }, [isPakistan]); const handlePayNow = async () => { if (!invoice) { toast?.error?.('No invoice found'); return; } // For bank transfer, show the bank transfer form if (selectedGateway === 'manual') { setShowBankTransfer(true); return; } setLoading(true); try { // Get plan ID from invoice subscription const planId = invoice.subscription?.plan?.id; if (!planId) { throw new Error('Plan information not found'); } // Create checkout session const { redirect_url } = await subscribeToPlan(planId.toString(), selectedGateway); // Redirect to payment gateway window.location.href = redirect_url; } catch (error: any) { console.error('Payment initiation failed:', error); toast?.error?.(error.message || 'Failed to start payment process'); } finally { setLoading(false); } }; // If showing bank transfer form if (showBankTransfer && invoice) { return (
{ setShowBankTransfer(false); onPaymentSuccess(); }} onCancel={() => setShowBankTransfer(false)} />
); } return (
{/* Header */}

Account Created!

Complete your payment to activate your {planName} plan

{/* Plan Summary Card */}

Order Summary

{planName}
{planName} Plan (Monthly) ${planPrice}
Total ${planPrice}
{/* Payment Method Selection */}

Select Payment Method

{gatewaysLoading ? (
Loading payment options...
) : paymentOptions.length === 0 ? (
No payment methods available
) : (
{paymentOptions.map((option) => ( ))}
)} {/* Security Badge */}
Your payment information is secure and encrypted
{/* Pay Now Button */} {/* Info text */}

{selectedGateway === 'manual' ? 'You will receive bank details to complete your transfer' : 'You will be redirected to complete payment securely' }

); }