Premium Membership
- 月度计划:$29.99
- 年度计划:$99.99
- 终身计划:$199.99
Premium Membership
Cloud Storage
API Access
按照以下步骤从零开始设置项目:
# 克隆仓库git clone https://github.com/obiscr/nextjs-stripe-supabase-starter.gitcd nextjs-stripe-supabase-starter
# 安装依赖npm install
在根目录下创建一个 .env.local
文件。
前往 Supabase 并创建一个免费账户
创建一个组织和一个新项目
前往 项目概览
前往 项目概览
将 Project URL
/ API Key
复制到 .env.local 文件中
# Supabase 密钥 (从 Supabase 项目仪表板 > 项目设置 > API 密钥获取)NEXT_PUBLIC_SUPABASE_URL=https://your-project-id.supabase.coNEXT_PUBLIC_SUPABASE_ANON_KEY=your-anon-key-here
前往 项目设置 > API 密钥
前往 项目设置 > API 密钥
将 service_role
密钥复制到 .env.local 文件中
# Supabase 密钥 (从 Supabase 项目仪表板 > 项目设置 > API 密钥获取)2 collapsed lines
NEXT_PUBLIC_SUPABASE_URL=https://your-project-id.supabase.coNEXT_PUBLIC_SUPABASE_ANON_KEY=your-anon-key-hereSUPABASE_SERVICE_ROLE_KEY=your-service-role-key-here
Note
请保持 SERVICE_ROLE_KEY
私密,不要与任何人分享。
前往 Stripe 并创建一个免费账户
完成账户设置流程
前往 Stripe 仪表板
导航到 开发者 > API 密钥
复制密钥
将你的 发布密钥 和 秘密密钥 (用于开发) 复制到 .env.local
文件中
# Stripe 密钥NEXT_PUBLIC_STRIPE_PUBLISHABLE_KEY=pk_test_your_publishable_key_hereSTRIPE_SECRET_KEY=sk_test_your_secret_key_here
由于本地开发,Stripe 的 Webhook 无法直接访问,因此你需要使用 Stripe CLI 来监听 Webhook。打开终端并运行本地监听器。
> stripe listen --forward-to localhost:3000/api/webhooks/stripeA newer version of the Stripe CLI is available, please update to: v1.28.0> Ready! You are using Stripe API Version [2022-08-01]. Your webhook signing secret is whsec_xxxxx (^C to quit)
你将在终端中看到 Webhook 签名密钥。将其复制到 .env.local 文件中。
# 从 Stripe 仪表板获取: https://dashboard.stripe.com/apikeys2 collapsed lines
NEXT_PUBLIC_STRIPE_PUBLISHABLE_KEY=pk_test_your_publishable_key_hereSTRIPE_SECRET_KEY=sk_test_your_secret_key_hereSTRIPE_WEBHOOK_SECRET=whsec_xxxxx
打开 Stripe 仪表板并导航到 开发者 > Webhook,创建一个新的 Webhook。
API 版本: 2025.06-30.basil
事件: 确保你选择了以下事件。
完成设置步骤。打开 Webhook URL 并复制签名密钥 whsec_xxxxx 到 .env.local 文件中。
# 从 Stripe 仪表板获取: https://dashboard.stripe.com/apikeys2 collapsed lines
NEXT_PUBLIC_STRIPE_PUBLISHABLE_KEY=pk_test_your_publishable_key_hereSTRIPE_SECRET_KEY=sk_test_your_secret_key_hereSTRIPE_WEBHOOK_SECRET=whsec_xxxxx
登录 Supabase
> npx supabase login你好,Supabase!按 Enter 打开浏览器并自动登录。
这是你的登录链接,如果浏览器没有打开 https://supabase.com/dashboard/cli/login?session_id=uuid&token_name=cli_@hostname&public_key=string
Enter your verification code: c4d28d97Token cli_@hostname created successfully.
You are now logged in. Happy coding!
初始化 Supabase
> npx supabase initGenerate VS Code settings for Deno? [y/N] NGenerate IntelliJ Settings for Deno? [y/N] NFinished supabase init.
链接到你的 Supabase 项目
> npx supabase link --project-ref your-project-id输入你的数据库密码 (或留空跳过): // 输入你的数据库密码30 collapsed lines
Connecting to remote database...NOTICE (42P06): schema "supabase_migrations" already exists, skippingFinished supabase link.WARNING: Local config differs from linked project. Try updating supabase/config.tomldiff supabase/config.toml your-project-id--- supabase/config.toml+++ your-project-id@@ -54,8 +54,8 @@
[auth]enabled = true-site_url = "http://127.0.0.1:3000"-additional_redirect_urls = ["https://127.0.0.1:3000"]+site_url = "http://localhost:3000"+additional_redirect_urls = []jwt_expiry = 3600enable_refresh_token_rotation = truerefresh_token_reuse_interval = 10@@ -96,9 +96,9 @@[auth.email]enable_signup = truedouble_confirm_changes = true-enable_confirmations = false+enable_confirmations = truesecure_password_change = false-max_frequency = "1s"+max_frequency = "1m0s"otp_length = 6otp_expiry = 3600[auth.email.template]
应用迁移
> npx supabase db pushConnecting to remote database...你想将这些迁移推送到远程数据库吗?• 20250710080949_init.sql
[Y/n] YNOTICE (42P06): schema "supabase_migrations" already exists, skippingNOTICE (42P07): relation "schema_migrations" already exists, skippingNOTICE (42701): column "statements" of relation "schema_migrations" already exists, skippingNOTICE (42701): column "name" of relation "schema_migrations" already exists, skippingApplying migration 20250710080949_init.sql...NOTICE (42710): extension "uuid-ossp" already exists, skippingFinished supabase db push.
运行自动化脚本来创建产品和服务在你的 Stripe 账户中:
> npm run stripe:init
# 你将看到以下输出。
> [email protected] stripe:init> ts-node scripts/stripe-init.ts
7 collapsed lines
(node:76080) ExperimentalWarning: Type Stripping is an experimental feature and might change at any time(Use `node --trace-warnings ...` to show where the warning was created)(node:76080) [MODULE_TYPELESS_PACKAGE_JSON] Warning: Module type of file:///Users/obiscr/projects/nextjs-stripe-supabase-starter/scripts/stripe-init.ts is not specified and it doesn't parse as CommonJS.Reparsing as ES module because module syntax was detected. This incurs a performance overhead.To eliminate this warning, add "type": "module" to /Users/obiscr/projects/nextjs-stripe-supabase-starter/package.json.[[email protected]] injecting env (7) from .env.local (tip: ⚙️ load multiple .env files with { path: ['.env.local', '.env'] })🚀 Starting Stripe initialization...
📋 Processing product: Premium Membership──────────────────────────────────────────────────9 collapsed lines
📦 Creating product: Premium Membership✅ Product created: ************** - Premium Membership💰 Creating price: Premium Monthly - $29.99✅ Price created: ************** - Premium Monthly💰 Creating price: Premium Yearly - $99.99✅ Price created: ************** - Premium Yearly💰 Creating price: Premium Lifetime - $199.99✅ Price created: ************** - Premium Lifetime✨ Completed Premium Membership with 3 prices
📋 Processing product: Cloud Storage──────────────────────────────────────────────────9 collapsed lines
📦 Creating product: Cloud Storage✅ Product created: ************** - Cloud Storage💰 Creating price: 50GB Storage - $9.99✅ Price created: ************** - 50GB Storage💰 Creating price: 100GB Storage - $19.99✅ Price created: ************** - 100GB Storage💰 Creating price: 500GB Storage - $49.99✅ Price created: ************** - 500GB Storage✨ Completed Cloud Storage with 3 prices
📋 Processing product: API Access──────────────────────────────────────────────────9 collapsed lines
📦 Creating product: API Access✅ Product created: ************** - API Access💰 Creating price: Basic API - $19.99✅ Price created: ************** - Basic API💰 Creating price: Pro API - $49.99✅ Price created: ************** - Pro API💰 Creating price: Enterprise API - $99.99✅ Price created: ************** - Enterprise API✨ Completed API Access with 3 prices
🎉 Stripe initialization completed successfully!
📊 Summary:────────────────────────────────────────────────────────────
🏷️ Premium Membership (**************) 💰 Premium Monthly: ************** - $29.99 💰 Premium Yearly: ************** - $99.99 💰 Premium Lifetime: ************** - $199.99
🏷️ Cloud Storage (**************) 💰 50GB Storage: ************** - $9.99 💰 100GB Storage: ************** - $19.99 💰 500GB Storage: ************** - $49.99
🏷️ API Access (**************) 💰 Basic API: ************** - $19.99 💰 Pro API: ************** - $49.99 💰 Enterprise API: ************** - $99.99
✅ You can now run your application and see the products!🔗 Stripe Dashboard: https://dashboard.stripe.com/products
这将创建配置中定义的所有产品和价格。你可以在 Stripe 仪表板中查看它们。
此时,你可以在 Stripe Webhook 仪表板中看到 Webhook 触发器。
A newer version of the Stripe CLI is available, please update to: v1.28.0> Ready! You are using Stripe API Version [2022-08-01]. Your webhook signing secret is whsec_xxxxx (^C to quit)2025-07-10 21:44:51 --> product.created [evt_******************]2025-07-10 21:44:52 --> plan.created [evt_******************]2025-07-10 21:44:52 <-- [200] POST http://localhost:3000/api/webhooks/stripe [evt_******************]2025-07-10 21:44:52 --> price.created [evt_******************]2025-07-10 21:44:53 <-- [200] POST http://localhost:3000/api/webhooks/stripe [evt_******************]2025-07-10 21:44:53 --> plan.created [evt_******************]2025-07-10 21:44:53 <-- [200] POST http://localhost:3000/api/webhooks/stripe [evt_******************]2025-07-10 21:44:53 --> price.created [evt_******************]2025-07-10 21:44:54 <-- [200] POST http://localhost:3000/api/webhooks/stripe [evt_******************]2025-07-10 21:44:54 --> price.created [evt_******************]2025-07-10 21:44:54 <-- [200] POST http://localhost:3000/api/webhooks/stripe [evt_******************]2025-07-10 21:44:54 --> product.created [evt_******************]2025-07-10 21:44:54 <-- [200] POST http://localhost:3000/api/webhooks/stripe [evt_******************]2025-07-10 21:44:55 <-- [200] POST http://localhost:3000/api/webhooks/stripe [evt_******************]2025-07-10 21:44:55 --> price.created [evt_******************]2025-07-10 21:44:56 <-- [200] POST http://localhost:3000/api/webhooks/stripe [evt_******************]2025-07-10 21:44:56 --> price.created [evt_******************]2025-07-10 21:44:57 --> price.created [evt_******************]2025-07-10 21:44:57 <-- [200] POST http://localhost:3000/api/webhooks/stripe [evt_******************]2025-07-10 21:44:58 --> product.created [evt_******************]2025-07-10 21:44:58 <-- [200] POST http://localhost:3000/api/webhooks/stripe [evt_******************]2025-07-10 21:44:58 <-- [200] POST http://localhost:3000/api/webhooks/stripe [evt_******************]2025-07-10 21:44:58 --> price.created [evt_******************]2025-07-10 21:44:59 --> price.created [evt_******************]2025-07-10 21:44:59 <-- [200] POST http://localhost:3000/api/webhooks/stripe [evt_******************]2025-07-10 21:45:00 --> price.created [evt_******************]2025-07-10 21:45:00 <-- [200] POST http://localhost:3000/api/webhooks/stripe [evt_******************]2025-07-10 21:45:01 <-- [200] POST http://localhost:3000/api/webhooks/stripe [evt_******************]
If everything goes well, you will see the product and product item data in supabase.
> npm run supabase:gen-types
> [email protected] supabase:gen-types> supabase gen types typescript --linked > lib/database.types.ts
npm run dev
在浏览器中打开 http://localhost:3000。
注册新用户
浏览产品
进行测试购买
4242 4242 4242 4242
支付成功
验证购买
这是一个使用 Stripe 和 Supabase 的简单示例。你可以使用它作为你自己的项目的起点。
你可以在以下位置找到源代码: