Skip to main content

支付集成

Codofly Template 集成 Stripe 支付系统,支持订阅管理、一次性付款和积分充值。

Stripe 配置

环境变量

初始化 Stripe

lib/stripe.ts

订阅管理

创建订阅

app/api/stripe/create-subscription/route.ts

订阅组件

components/subscription/subscription-plans.tsx

一次性付款

创建支付意图

app/api/stripe/create-payment-intent/route.ts

支付表单

components/payment/payment-form.tsx

积分系统

积分充值

app/api/credits/purchase/route.ts

积分消费

lib/credits.ts

Webhook 处理

Stripe Webhook

app/api/webhooks/stripe/route.ts

账单管理

获取账单历史

app/api/billing/history/route.ts

账单组件

components/billing/billing-history.tsx

退款处理

创建退款

app/api/stripe/refund/route.ts
确保在生产环境中使用真实的 Stripe 密钥,并正确配置 Webhook 端点。

最佳实践

  1. 安全性 - 永远不要在客户端暴露 Stripe 密钥
  2. Webhook - 使用 Webhook 处理支付状态更新
  3. 错误处理 - 优雅处理支付失败情况
  4. 测试 - 使用 Stripe 测试模式进行开发
查看 Stripe 文档 了解更多支付功能。