サブスクリプション
AccountMaker(以下「AM」)は Account 向けの Stripe サブスクリプションライフサイクルを管理し、Webhook 実装よりも価格設計とアクセス制御に集中できるようにします。
Checkout セッションを作成し、顧客にプラン管理を提供し、Stripe と Account のアクセス状態を同期します。
サブスクリプションフロー
エンドポイント
| Endpoint | Purpose |
|---|---|
POST /api/accounts/:account_id/subscriptions/stripe/checkout-session | サブスクリプション Checkout を開始 |
POST /api/accounts/:account_id/subscriptions/stripe/portal-session | Customer Portal を開く |
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 Customer Identity を取得 |
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/...";
}
サブスクリプション Identity
各 Account は Stripe Customer に対応する Subscription Identity を持ちます。Stripe Webhook の解決と課金状態同期で利用します。
Webhook イベント
AM は Stripe Webhook を処理し、失敗時はリトライします。
| Event | Action |
|---|---|
checkout.session.completed | 顧客を紐付けてサブスクリプションを作成 |
customer.subscription.* | サブスクリプションデータを同期 |
invoice.paid | 請求書同期とアクセス更新 |
invoice.payment_failed | アクセス期間を更新 |