/** * Payment Settings Section Component * Unified payment configuration UI that shows the appropriate setup * based on the business tier (API keys for Free, Connect for Paid) */ import React from 'react'; import { CreditCard, CheckCircle, AlertCircle, Loader2, FlaskConical, Zap, } from 'lucide-react'; import { Business } from '../types'; import { usePaymentConfig } from '../hooks/usePayments'; import StripeApiKeysForm from './StripeApiKeysForm'; import ConnectOnboardingEmbed from './ConnectOnboardingEmbed'; interface PaymentSettingsSectionProps { business: Business; } type PaymentModeType = 'direct_api' | 'connect' | 'none'; const PaymentSettingsSection: React.FC = ({ business }) => { const { data: config, isLoading, error, refetch } = usePaymentConfig(); if (isLoading) { return (
Loading payment configuration...
); } if (error) { return (
Failed to load payment configuration
); } const paymentMode = (config?.payment_mode || 'none') as PaymentModeType; const canAcceptPayments = config?.can_accept_payments || false; const tier = config?.tier || business.plan || 'Free'; const isFreeTier = tier === 'Free'; // Determine Stripe environment (test vs live) from API keys const getStripeEnvironment = (): 'test' | 'live' | null => { const maskedKey = config?.api_keys?.publishable_key_masked; if (!maskedKey) return null; if (maskedKey.startsWith('pk_test_')) return 'test'; if (maskedKey.startsWith('pk_live_')) return 'live'; return null; }; const stripeEnvironment = getStripeEnvironment(); // Status badge component const StatusBadge = () => { if (canAcceptPayments) { return ( Ready ); } return ( Setup Required ); }; // Mode description const getModeDescription = () => { if (isFreeTier) { return 'Free tier businesses use their own Stripe API keys for payment processing. No platform fees apply.'; } return `${tier} tier businesses use Stripe Connect for payment processing with platform-managed payments.`; }; return (
{/* Header */}

Payment Configuration

{getModeDescription()}

{/* Test/Live Mode Banner */} {stripeEnvironment && config?.api_keys?.status === 'active' && (
{stripeEnvironment === 'test' ? ( <>

Test Mode

Payments are simulated. No real money will be charged.

Get Live Keys ) : ( <>

Live Mode

Payments are real. Customers will be charged.

)}
)} {/* Content */}
{/* Tier info banner */}
Current Plan: {tier}
Payment Mode:{' '} {paymentMode === 'direct_api' ? 'Direct API Keys' : paymentMode === 'connect' ? 'Stripe Connect' : 'Not Configured'}
{/* Tier-specific content */} {isFreeTier ? ( refetch()} /> ) : ( refetch()} /> )} {/* Upgrade notice for free tier with deprecated keys */} {isFreeTier && config?.api_keys?.status === 'deprecated' && (

Upgraded to a Paid Plan?

If you've recently upgraded, your API keys have been deprecated. Please contact support to complete your Stripe Connect setup.

)}
); }; export default PaymentSettingsSection;