Accountmaker Docs
功能

訂閱

Stripe 訂閱整合,包含 checkout、入口、同步與 webhook。

subscriptions stripe payments

訂閱

AM 管理帳戶的 Stripe 訂閱生命週期,讓你專注於定價與權限控管,而不是處理 webhook。

建立 checkout session、讓客戶自助管理方案,並保持帳戶存取與 Stripe 同步。

訂閱流程

StripeAMUserStripeAMUserStart checkoutCreate checkout sessionRedirect to StripeComplete paymentWebhook: checkout.session.completedSync subscription + features

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/webhookStripe 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更新存取視窗

相關