'use client'; import { useState, useEffect, useMemo } from 'react'; import { useRouter } from 'next/navigation'; import { Check, ArrowLeft } from 'lucide-react'; import { Button } from '@/components/ui/button'; import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card'; import { fetchSubscriptionPlans, SubscriptionPlan } from '@/lib/stripe'; export default function PricingPage() { return (
{/* Main Content */}
); } /**价格方案 */ function HomeModule5() { const [billingType, setBillingType] = useState<'month' | 'year'>( "month" ); const [plans, setPlans] = useState([]); // 从后端获取订阅计划数据 useEffect(() => { const loadPlans = async () => { try { const plansData = await fetchSubscriptionPlans(); setPlans(plansData); } catch (err) { console.error('加载订阅计划失败:', err); } }; loadPlans(); }, []); const pricingPlans = useMemo<{ title: string; price: number; credits: string; buttonText: string; features: string[]; }[]>(() => { return plans.map((plan) => { return { title: plan.display_name || plan.name, price: billingType === "month" ? plan.price_month/100 : plan.price_year/100, credits: plan.description, buttonText: plan.is_free ? "Try For Free" : "Subscribe Now", features: plan.features || [], }; }); }, [plans, billingType]); const handleSubscribe = async (planName: string) => { if (planName === 'hobby') { return; } try { // 使用新的Checkout Session方案(更简单!) const { createCheckoutSession, redirectToCheckout } = await import('@/lib/stripe'); // 从localStorage获取当前用户信息 const User = JSON.parse(localStorage.getItem("currentUser") || "{}"); if (!User.id) { throw new Error("无法获取用户ID,请重新登录"); } // 1. 创建Checkout Session const result = await createCheckoutSession({ user_id: String(User.id), plan_name: planName, billing_cycle: billingType }); if (!result.successful || !result.data) { throw new Error("create checkout session failed"); } // 2. 直接跳转到Stripe托管页面(就这么简单!) redirectToCheckout(result.data.checkout_url); } catch (error) { throw new Error("create checkout session failed, please try again later"); } }; return (

Start Creating

{/* 计费切换 */}
{/* 主要价格卡片 */}
{pricingPlans.map((plan, index) => (

{plan.title}

${plan.price} /month

{plan.credits}

* Billed monthly until cancelled

    {plan.features.map((feature, featureIndex) => (
  • {feature}
  • ))}
))}
{/* 额外价格卡片 */}

Free

$0

10 Video mins and 1 AI credit per week, 1 Express avatar, 4 Exports per week with invideo watermark.

No access to generative features.

Enterprise

Custom

Custom solutions for large organizations. Advanced security and flexible pricing based on your needs.

on your needs.

); }