訂閱
AM 代管帳戶的 Stripe 訂閱生命週期,讓你專注在定價與存取控制,而不是 webhook 處理細節。
你可以建立 checkout session、讓客戶自行管理方案,並將帳戶權限狀態與 Stripe 保持同步。
訂閱流程
端點
| Endpoint | 用途 |
|---|---|
POST /api/accounts/:account_id/subscriptions/stripe/checkout-session | 啟動訂閱 checkout |
POST /api/accounts/:account_id/subscriptions/stripe/portal-session | 開啟客戶 portal |
POST /api/accounts/:account_id/subscriptions/stripe/checkout-session-sync | 將 checkout session 同步為訂閱資料 |
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 customer。此資料用於解析 Stripe webhook 並同步計費狀態。
Webhook 事件
AM 會處理 Stripe webhook,失敗時自動重試:
| Event | 動作 |
|---|---|
checkout.session.completed | 連結 customer 並建立訂閱 |
customer.subscription.* | 同步訂閱資料 |
invoice.paid | 同步發票並更新存取狀態 |
invoice.payment_failed | 更新可用存取期間 |