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

# 풍차

> Dodo Payments 이벤트를 기반으로 풍차 워크플로우 및 스크립트를 트리거하여 맞춤형 자동화를 수행합니다.

## 소개

결제 이벤트가 발생할 때 풍차에서 사용자 정의 워크플로우 및 스크립트를 실행합니다. 데이터베이스 작업을 수행하고, 알림을 전송하며, 데이터를 처리하고, 풍차의 강력한 워크플로우 엔진을 사용하여 복잡한 비즈니스 로직을 자동화합니다.

<Info>
  이 통합을 구성하려면 워크플로 구성에서 Windmill 웹훅 URL이 필요합니다.
</Info>

## 시작하기

<Steps>
  <Step title="Open the Webhook Section">
    Dodo Payments 대시보드에서 <b>Webhooks → + Add Endpoint</b>로 이동하고 통합 드롭다운을 확장합니다.

    <Frame>
      <img src="https://mintcdn.com/dodopayments/slbAEdrLLwKHfaRf/images/integrations/windmill.png?fit=max&auto=format&n=slbAEdrLLwKHfaRf&q=85&s=695fe639c086c3d899efae177d646591" alt="Add Endpoint and integrations dropdown" style={{ maxHeight: '500px', width: 'auto' }} width="1678" height="954" data-path="images/integrations/windmill.png" />
    </Frame>
  </Step>

  <Step title="Select Windmill">
    <b>Windmill</b> 통합 카드를 선택합니다.
  </Step>

  <Step title="Create Windmill Workflow">
    Windmill에서 새 워크플로를 만들고 트리거 구성에서 웹훅 URL을 복사합니다.
  </Step>

  <Step title="Paste Webhook URL">
    Windmill 웹훅 URL을 엔드포인트 구성에 붙여넣습니다.
  </Step>

  <Step title="Configure Transformation">
    변환 코드를 편집하여 이벤트를 Windmill 워크플로에 맞게 형식화합니다.
  </Step>

  <Step title="Test & Create">
    샘플 페이로드로 테스트한 다음 <b>Create</b>를 클릭하여 통합을 활성화합니다.
  </Step>

  <Step title="Done!">
    🎉 결제 이벤트가 이제 Windmill 워크플로를 자동으로 트리거합니다.
  </Step>
</Steps>

## 변환 코드 예제

### 기본 워크플로우 페이로드

```javascript basic_workflow.js icon="js" expandable theme={null}
function handler(webhook) {
  if (webhook.eventType === "payment.succeeded") {
    const p = webhook.payload.data;
    webhook.payload = {
      event_type: webhook.eventType,
      payment_id: p.payment_id,
      amount: (p.total_amount / 100).toFixed(2),
      currency: p.currency || "USD",
      customer_email: p.customer.email,
      customer_name: p.customer.name,
      payment_method: p.payment_method || "unknown",
      timestamp: webhook.payload.timestamp,
      metadata: {
        business_id: p.business_id,
        product_id: p.product_id
      }
    };
  }
  return webhook;
}
```

### 구독 워크플로우 핸들러

```javascript subscription_workflow.js icon="js" expandable theme={null}
function handler(webhook) {
  const s = webhook.payload.data;
  switch (webhook.eventType) {
    case "subscription.active":
      webhook.payload = {
        event_type: "subscription_started",
        subscription_id: s.subscription_id,
        customer_email: s.customer.email,
        customer_name: s.customer.name,
        product_id: s.product_id,
        amount: (s.recurring_pre_tax_amount / 100).toFixed(2),
        frequency: s.payment_frequency_interval,
        next_billing: s.next_billing_date,
        customer_id: s.customer.customer_id,
        timestamp: webhook.payload.timestamp
      };
      break;
    case "subscription.cancelled":
      webhook.payload = {
        event_type: "subscription_cancelled",
        subscription_id: s.subscription_id,
        customer_email: s.customer.email,
        cancelled_at: s.cancelled_at,
        cancel_at_next_billing: s.cancel_at_next_billing_date,
        customer_id: s.customer.customer_id,
        timestamp: webhook.payload.timestamp
      };
      break;
  }
  return webhook;
}
```

### 분쟁 워크플로우 핸들러

```javascript dispute_workflow.js icon="js" expandable theme={null}
function handler(webhook) {
  if (webhook.eventType.startsWith("dispute.")) {
    const d = webhook.payload.data;
    webhook.payload = {
      event_type: webhook.eventType,
      dispute_id: d.dispute_id,
      payment_id: d.payment_id,
      amount: (d.amount / 100).toFixed(2),
      status: d.dispute_status,
      stage: d.dispute_stage,
      remarks: d.remarks || "",
      urgent: webhook.eventType === "dispute.opened",
      business_id: d.business_id,
      timestamp: webhook.payload.timestamp
    };
  }
  return webhook;
}
```

## 일반적인 풍차 사용 사례

<AccordionGroup>
  <Accordion title="Database Operations">
    * PostgreSQL/MySQL에서 고객 기록 업데이트
    * 결제 이벤트를 데이터 웨어하우스에 기록
    * 데이터를 외부 시스템과 동기화
    * 재고 수준 업데이트
    * 분석 메트릭 추적
  </Accordion>

  <Accordion title="Business Logic">
    * 수익 메트릭 계산
    * 환불 및 조정 처리
    * 구독 수명 주기 관리
    * 보고서 및 내보내기 생성
    * 결제 데이터 검증
  </Accordion>

  <Accordion title="External Integrations">
    * 분석 플랫폼에 데이터 전송
    * CRM 시스템 업데이트
    * 이메일 캠페인 트리거
    * 캘린더 이벤트 생성
    * SMS 알림 전송
  </Accordion>
</AccordionGroup>

## 팁

* 워크플로우 처리를 쉽게 하기 위해 페이로드 데이터를 구조화합니다.
* 비즈니스 로직을 위해 모든 관련 메타데이터를 포함합니다.
* 이벤트 전반에 걸쳐 일관된 필드 이름을 사용합니다.
* 워크플로우 타이밍을 위해 타임스탬프를 포함합니다.
* 풍차의 내장 오류 처리를 활용합니다.

## 문제 해결

<AccordionGroup>
  <Accordion title="Workflows not triggering">
    * 웹훅 URL이 정확하고 활성 상태인지 확인
    * Windmill 워크플로가 게시되고 활성 상태인지 확인
    * 페이로드 구조가 워크플로 기대치와 일치하는지 확인
    * Windmill 실행 로그에서 오류 확인
  </Accordion>

  <Accordion title="Data processing issues">
    * 워크플로 입력 매개변수 매핑 확인
    * 데이터 형식이 예상 형식과 일치하는지 검증
    * 샘플 데이터로 워크플로 테스트
    * Windmill 스크립트 실행 로그 검토
  </Accordion>
</AccordionGroup>
