变现与迭代
Stripe 接入指南
海外支付首选方案,支持信用卡和多种支付方式
什么是 Stripe
Stripe 是全球最流行的支付平台,支持信用卡、Apple Pay、Google Pay 等多种支付方式。
适用场景
- 面向海外用户的 SaaS 产品
- 订阅制产品(自动续费)
- 一次性付费产品
优势
- 开发者友好:API 设计优秀,文档完善
- 功能强大:支持订阅、发票、退款、争议处理
- 全球支持:支持 135+ 种货币
- 安全合规:PCI DSS 认证,无需担心安全问题
劣势
- 手续费较高:2.9% + $0.30 每笔交易
- 需要企业资质:个人开发者需要注册公司
- 提现周期:7 天(新账户可能更长)
接入步骤
1. 注册 Stripe 账户
访问 stripe.com 注册账户。
需要准备:
- 公司信息(个人可以注册 Sole Proprietorship)
- 银行账户信息
- 身份证明文件
2. 获取 API 密钥
在 Stripe Dashboard 中获取:
- Publishable Key(公开密钥):前端使用
- Secret Key(私密密钥):后端使用
3. 安装 SDK
# Node.js
npm install stripe
# Python
pip install stripe
# Ruby
gem install stripe4. 创建支付会话
前端代码(React 示例):
import { loadStripe } from '@stripe/stripe-js';
const stripePromise = loadStripe('pk_test_...');
async function handleCheckout() {
const response = await fetch('/api/create-checkout-session', {
method: 'POST',
});
const session = await response.json();
const stripe = await stripePromise;
await stripe.redirectToCheckout({
sessionId: session.id,
});
}后端代码(Node.js 示例):
const stripe = require('stripe')('sk_test_...');
app.post('/api/create-checkout-session', async (req, res) => {
const session = await stripe.checkout.sessions.create({
payment_method_types: ['card'],
line_items: [{
price_data: {
currency: 'usd',
product_data: {
name: '专业版订阅',
},
unit_amount: 2900, // $29.00
recurring: {
interval: 'month',
},
},
quantity: 1,
}],
mode: 'subscription',
success_url: 'https://yourdomain.com/success',
cancel_url: 'https://yourdomain.com/cancel',
});
res.json({ id: session.id });
});5. 处理 Webhook
Stripe 会通过 Webhook 通知支付状态变化。
app.post('/webhook', express.raw({type: 'application/json'}), (req, res) => {
const sig = req.headers['stripe-signature'];
let event;
try {
event = stripe.webhooks.constructEvent(req.body, sig, endpointSecret);
} catch (err) {
return res.status(400).send(`Webhook Error: ${err.message}`);
}
// 处理不同事件
switch (event.type) {
case 'checkout.session.completed':
// 支付成功,激活用户订阅
break;
case 'customer.subscription.deleted':
// 订阅取消,停用用户权限
break;
}
res.json({received: true});
});常见场景
订阅制产品
使用 Stripe Billing 管理订阅:
- 自动续费
- 订阅升级/降级
- 取消订阅
- 试用期管理
一次性付费
使用 Stripe Checkout:
- 快速接入,无需自建支付页面
- 支持多种支付方式
- 自动处理税费
按使用量计费
使用 Stripe Metered Billing:
- 按 API 调用次数计费
- 按存储空间计费
- 按用户数计费
测试
Stripe 提供测试模式,使用测试卡号:
- 成功支付:4242 4242 4242 4242
- 需要验证:4000 0025 0000 3155
- 支付失败:4000 0000 0000 9995
常见问题
个人开发者可以用 Stripe 吗?
可以,注册为 Sole Proprietorship(个体经营者)。
如何降低手续费?
- 年交易量 >$80,000 可以申请降低费率
- 使用 ACH 转账(美国)手续费更低
如何处理退款?
在 Stripe Dashboard 中手动退款,或通过 API:
await stripe.refunds.create({
payment_intent: 'pi_...',
});下一步
- 定价心理学 - 如何科学定价
- 订阅制变现 - 订阅制的实施细节
- Lemon Squeezy 接入 - Stripe 的替代方案