> ## 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.

# 구독

> 구독이 생성, 업데이트되거나 상태가 변경될 때 웹훅 엔드포인트로 전송되는 페이로드입니다.

## 구독 웹훅 이벤트

다음 웹훅 이벤트는 구독 생애 주기 변경 사항을 추적하는 데 사용할 수 있습니다:

| 이벤트                         | 설명                                       |
| --------------------------- | ---------------------------------------- |
| `subscription.active`       | 구독이 성공적으로 활성화되었습니다                       |
| `subscription.updated`      | 구독 개체가 업데이트되었습니다(필드가 변경되면 이 이벤트가 트리거됩니다) |
| `subscription.on_hold`      | 갱신 실패로 인해 구독이 일시 중지되었습니다                 |
| `subscription.renewed`      | 다음 청구 기간을 위해 구독이 갱신되었습니다                 |
| `subscription.plan_changed` | 구독 플랜이 업그레이드, 다운그레이드 또는 수정되었습니다          |
| `subscription.cancelled`    | 구독이 취소되었습니다                              |
| `subscription.failed`       | 위임(mandate) 생성 중 구독 생성에 실패했습니다           |
| `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>

## 웹훅 페이로드 스키마
