> ## Documentation Index
> Fetch the complete documentation index at: https://docs.dodopayments.com/llms.txt
> Use this file to discover all available pages before exploring further.

# サブスクリプション

> サブスクリプションが作成、更新、または状態が変更されたときに、あなたのWebhookエンドポイントに送信されるペイロードです。

## サブスクリプションWebhookイベント

サブスクリプションライフサイクルの変更を追跡するために利用可能なWebhookイベントは以下の通りです：

| Event                       | Description                                          |
| --------------------------- | ---------------------------------------------------- |
| `subscription.active`       | サブスクリプションが正常に有効化されました                                |
| `subscription.updated`      | サブスクリプションオブジェクトが更新されました（フィールドの変更があった場合にこのイベントが発生します） |
| `subscription.on_hold`      | 更新に失敗したためサブスクリプションが保留中になりました                         |
| `subscription.renewed`      | 次の請求期間に向けてサブスクリプションが更新されました                          |
| `subscription.plan_changed` | サブスクリプションプランがアップグレード、ダウングレード、または変更されました              |
| `subscription.cancelled`    | サブスクリプションがキャンセルされました                                 |
| `subscription.failed`       | マンダート作成中にサブスクリプションの作成に失敗しました                         |
| `subscription.expired`      | サブスクリプションが契約期間の終了に達しました                              |

### `subscription.updated` を使用したリアルタイム同期

サブスクリプションのフィールドが変更されるたびに `subscription.updated` ウェブフックが発火し、ポーリングなしでアプリケーションの状態を同期できます:

```javascript theme={null}
app.post('/webhooks/dodo', async (req, res) => {
  const event = req.body;
  
  if (event.type === 'subscription.updated') {
    const subscription = event.data;
    
    // Sync subscription changes to your database
    await syncSubscription(subscription.subscription_id, {
      status: subscription.status,
      next_billing_date: subscription.next_billing_date,
      metadata: subscription.metadata,
      // ... other fields you want to track
    });
    
    console.log(`Subscription ${subscription.subscription_id} updated`);
  }
  
  res.json({ received: true });
});
```

<Tip>
  `subscription.updated` を購読して、サブスクリプションの変更に関するリアルタイム通知を受け取り、API をポーリングする必要をなくします。
</Tip>

## Webhookペイロードスキーマ
