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

# Keplars

> Dodo Payments 이벤트를 기반으로 Keplars를 통해 트랜잭셔널 이메일을 보냅니다.

## 소개

결제 및 구독 이벤트가 발생할 때 전문적인 트랜잭셔널 이메일을 자동으로 보냅니다. 중간 서버가 필요 없이 Keplars를 통해 결제 확인, 구독 업데이트 및 실패 알림을 전달합니다. Dodo Payments는 JavaScript 변환 핸들러를 사용하여 Keplars API를 직접 호출합니다.

<Info>
  이 통합은 인증을 위해 Keplars API 키가 필요합니다. Keplars 대시보드에서 **Settings → API Keys** 아래에서 찾을 수 있으며, **Domains** 아래에서 발신 도메인 또는 주소를 확인하세요.
</Info>

## 시작하기

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

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

    <Frame>
      <img src="https://mintcdn.com/dodopayments/tM0KgwbOo2xwg7zr/images/integrations/keplars/select.png?fit=max&auto=format&n=tM0KgwbOo2xwg7zr&q=85&s=776a4a2228efa0822b15b13d2baaf5bb" alt="Keplars 통합 카드를 선택하세요" style={{ maxHeight: '500px', width: 'auto' }} width="1040" height="731" data-path="images/integrations/keplars/select.png" />
    </Frame>
  </Step>

  <Step title="Enter API Key">
    Keplars API 키를 입력합니다. 이는 모든 요청에 Bearer 토큰으로 전송됩니다.

    <Frame>
      <img src="https://mintcdn.com/dodopayments/tM0KgwbOo2xwg7zr/images/integrations/keplars/api-key.png?fit=max&auto=format&n=tM0KgwbOo2xwg7zr&q=85&s=f3e0917155715d0587a6012c1bfd3f26" alt="Keplars API URL, API 키 입력 및 이벤트 구독" style={{ maxHeight: '500px', width: 'auto' }} width="982" height="854" data-path="images/integrations/keplars/api-key.png" />
    </Frame>
  </Step>

  <Step title="Configure Transformation">
    이메일을 Keplars에 맞게 형식화하기 위해 변환 코드를 편집합니다. 자리 표시자 발신 주소 및 템플릿 ID를 자신의 것으로 교체하세요.
  </Step>

  <Step title="Test & Create">
    샘플 페이로드로 테스트하고 <b>Create</b>를 클릭하여 이메일 보내기를 활성화합니다.
  </Step>

  <Step title="Done!">
    🎉 이제 결제 이벤트가 발생하면 Keplars를 통해 자동으로 트랜잭셔널 이메일이 전송됩니다.
  </Step>
</Steps>

## 변환 코드 예제

각 핸들러는 `webhook.url`을 Keplars 고우선순위 전송 엔드포인트에 설정하고 `webhook.payload`을 Keplars 요청으로 변환합니다 (API 키는 자동으로 Bearer 토큰으로 전송됩니다). `payments@mail.yourdomain.com`를 인증된 발신자로, `your-keplars-*-template-id`를 실제 템플릿 ID로 교체하세요.

<Warning>
  `to`은 **배열**이어야 하며, 수신자가 하나인 경우에도 그렇습니다. `template_id`를 사용할 때 `subject`나 `body`를 보내지 **마십시오**. 템플릿이 이를 제공합니다.
</Warning>

### 결제 확인 이메일

```javascript payment_succeeded.js icon="js" expandable theme={null}
function handler(webhook) {
  if (webhook.eventType !== "payment.succeeded") return webhook;

  const data = webhook.payload.data || {};
  const paymentDate = new Date(webhook.payload.timestamp).toLocaleDateString("en-US", {
    year: "numeric", month: "long", day: "numeric",
  });

  webhook.url = "https://api.keplars.com/api/v1/send-email/high";
  webhook.payload = {
    to: [data.customer?.email],
    from: "payments@mail.yourdomain.com",
    template_id: "your-keplars-payment-success-template-id",
    params: {
      customer_name: data.customer?.name,
      amount: ((data.total_amount || 0) / 100).toFixed(2),
      currency: data.currency || "USD",
      payment_id: data.payment_id,
      payment_method: data.payment_method,
      payment_date: paymentDate,
    },
  };
  return webhook;
}
```

### 결제 실패 알림

```javascript payment_failed.js icon="js" expandable theme={null}
function handler(webhook) {
  if (webhook.eventType !== "payment.failed") return webhook;

  const data = webhook.payload.data || {};
  const paymentDate = new Date(webhook.payload.timestamp).toLocaleDateString("en-US", {
    year: "numeric", month: "long", day: "numeric",
  });

  webhook.url = "https://api.keplars.com/api/v1/send-email/high";
  webhook.payload = {
    to: [data.customer?.email],
    from: "payments@mail.yourdomain.com",
    template_id: "your-keplars-payment-failed-template-id",
    params: {
      customer_name: data.customer?.name,
      amount: ((data.total_amount || 0) / 100).toFixed(2),
      currency: data.currency || "USD",
      payment_id: data.payment_id,
      error_message: data.error_message || "Your payment could not be processed.",
      payment_date: paymentDate,
    },
  };
  return webhook;
}
```

### 구독 환영 이메일

```javascript subscription_active.js icon="js" expandable theme={null}
function handler(webhook) {
  if (webhook.eventType !== "subscription.active") return webhook;

  const data = webhook.payload.data || {};
  const nextBilling = data.next_billing_date
    ? new Date(data.next_billing_date).toLocaleDateString("en-US", {
        year: "numeric", month: "long", day: "numeric",
      })
    : "";

  webhook.url = "https://api.keplars.com/api/v1/send-email/high";
  webhook.payload = {
    to: [data.customer?.email],
    from: "payments@mail.yourdomain.com",
    template_id: "your-keplars-subscription-active-template-id",
    params: {
      customer_name: data.customer?.name,
      subscription_id: data.subscription_id,
      product_id: data.product_id,
      amount: ((data.recurring_pre_tax_amount || 0) / 100).toFixed(2),
      currency: data.currency || "USD",
      billing_interval: data.payment_frequency_interval || "month",
      next_billing_date: nextBilling,
    },
  };
  return webhook;
}
```

### 구독 취소 이메일

```javascript subscription_cancelled.js icon="js" expandable theme={null}
function handler(webhook) {
  if (webhook.eventType !== "subscription.cancelled") return webhook;

  const data = webhook.payload.data || {};
  const cancellationDate = new Date(webhook.payload.timestamp).toLocaleDateString("en-US", {
    year: "numeric", month: "long", day: "numeric",
  });

  webhook.url = "https://api.keplars.com/api/v1/send-email/high";
  webhook.payload = {
    to: [data.customer?.email],
    from: "payments@mail.yourdomain.com",
    template_id: "your-keplars-subscription-cancelled-template-id",
    params: {
      customer_name: data.customer?.name,
      subscription_id: data.subscription_id,
      cancellation_date: cancellationDate,
    },
  };
  return webhook;
}
```

## 팁

* 더 나은 전달성을 위해 인증된 발신 도메인 또는 주소를 사용하세요.
* 각 이벤트 유형에 대해 전용 Keplars 템플릿을 생성하여 모든 이메일이 브랜드와 메시지에 부합하도록 하세요.
* 고객 이름, 금액, 결제 ID와 같은 데이터를 전달하여 각 이메일을 개인화하세요.
* 먼저 샌드박스 모드에서 테스트하세요. 샌드박스 전송은 Keplars 테스트 인박스에 캡처되며 전달되지 않습니다.

## 문제 해결

<AccordionGroup>
  <Accordion title="Emails not being sent">
    * Keplars의 **Settings → API Keys**에서 API 키가 올바르고 활성화되어 있는지 확인하세요.
    * 발신 도메인 또는 주소가 인증되었는지 확인하세요.
    * Dodo Payments는 webhook 전달 로그에 Keplars의 원시 오류 응답을 보여줍니다. 세부정보를 확인하세요.
  </Accordion>

  <Accordion title="Template not found">
    * 핸들러의 `template_id`는 Keplars 계정의 활성 템플릿과 일치해야 합니다. 대시보드에서 ID가 활성 상태인지 확인하세요.
  </Accordion>

  <Accordion title="Wrong event triggered">
    * 각 핸들러는 `webhook.eventType`을 검사하고 일치하지 않으면 조기에 반환합니다. Dodo Payments webhook 엔드포인트에서 올바른 이벤트가 구독되었는지 확인하세요.
  </Accordion>
</AccordionGroup>
