订阅
AM 为账户管理 Stripe 订阅生命周期,让你专注于定价与访问控制,而不是处理 webhook。
创建 checkout 会话,让客户自主管理套餐,并保持账户访问与 Stripe 同步。
订阅流程
Endpoints
| Endpoint | 用途 |
|---|---|
POST /api/accounts/:account_id/subscriptions/stripe/checkout-session | 启动订阅 checkout |
POST /api/accounts/:account_id/subscriptions/stripe/portal-session | 打开客户门户 |
POST /api/accounts/:account_id/subscriptions/stripe/checkout-session-sync | 同步 checkout 与订阅 |
POST /api/accounts/:account_id/subscriptions/sync | 从 Stripe 同步订阅 |
POST /api/accounts/:account_id/subscriptions/change | 更改套餐或价格 |
POST /api/accounts/:account_id/subscriptions/cancel | 取消订阅 |
GET /api/accounts/:account_id/subscriptions | 订阅列表 |
GET /api/accounts/:account_id/subscriptions/features | 激活功能列表 |
GET /api/accounts/:account_id/subscriptions/identity | 获取 Stripe 客户身份 |
POST /api/applications/:application_id/subscriptions/stripe/webhook | Stripe Webhook |
Checkout 会话
创建 Stripe Checkout 会话用于新订阅:
// Request
{
price_id: "price_...",
success_url: "https://app.example.com/success",
cancel_url: "https://app.example.com/cancel"
}
// Response
{
url: "https://checkout.stripe.com/..."
}
将用户重定向到返回的 URL。支付完成后,Stripe 会跳转到你的成功 URL。
客户门户
允许客户自助管理:
- 更新支付方式
- 查看发票
- 取消订阅
- 切换套餐
// Request
{
return_url: "https://app.example.com/settings";
}
// Response
{
url: "https://billing.stripe.com/...";
}
订阅身份
每个账户都有订阅身份,将账户映射到 Stripe 客户。用于解析 webhook 并同步计费状态。
Webhook 事件
AM 处理 Stripe webhook,并在失败时重试:
| 事件 | 动作 |
|---|---|
checkout.session.completed | 绑定客户并创建订阅 |
customer.subscription.* | 同步订阅数据 |
invoice.paid | 同步发票并更新访问 |
invoice.payment_failed | 更新访问窗口 |