订阅
AM 为账户管理完整的 Stripe 订阅生命周期,让你专注于定价与访问控制,而不是处理 Webhook 细节。
你可以创建结账会话,让客户自助管理套餐,并保持账户访问状态与 Stripe 同步。
订阅流程
Endpoints
| Endpoint | 用途 |
|---|---|
POST /api/accounts/:account_id/subscriptions/stripe/checkout-session |
发起订阅结账 |
POST /api/accounts/:account_id/subscriptions/stripe/portal-session |
打开客户门户 |
POST /api/accounts/:account_id/subscriptions/stripe/checkout-session-sync |
将结账会话同步为订阅 |
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 Session
为新订阅创建 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 会跳转到你的 success URL。
Customer Portal
允许客户自助管理:
- 更新支付方式
- 查看发票
- 取消订阅
- 变更套餐
// Request
{
return_url: "https://app.example.com/settings";
}
// Response
{
url: "https://billing.stripe.com/...";
}
Subscription Identity
每个账户都有一个订阅身份,用于将账户映射到 Stripe 客户对象。该映射用于解析 Stripe Webhook 并同步计费状态。
Webhook 事件
AM 处理 Stripe Webhook,并在失败时自动重试:
| Event | 动作 |
|---|---|
checkout.session.completed |
关联客户并创建订阅 |
customer.subscription.* |
同步订阅数据 |
invoice.paid |
同步发票并更新访问权限 |
invoice.payment_failed |
更新访问宽限窗口 |