訂閱
AM 管理帳戶的 Stripe 訂閱生命週期,讓你專注於定價與權限控管,而不是處理 webhook。
建立 checkout session、讓客戶自助管理方案,並保持帳戶存取與 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 Session
建立 Stripe Checkout session 用於新訂閱:
// 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 | 更新存取視窗 |