メインコンテンツへスキップ

はじめに

支払いイベントが発生したときに、プロフェッショナルなトランザクションメールを自動的に送信します。Resendの信頼性の高いメールインフラストラクチャと優れた配信率を利用して、支払い確認、サブスクリプションの更新、重要な通知を届けます。
この統合には、認証のためにあなたのResend APIキーが必要です。

始め方

1

Webhookセクションを開く

Dodo Paymentsのダッシュボードで、Webhooks → + エンドポイントを追加に移動し、統合のドロップダウンを展開します。
エンドポイントを追加と統合のドロップダウン
2

Resendを選択

Resend統合カードを選択します。
3

APIキーを入力

設定にあなたのResend APIキーを提供します。
4

変換を設定

ResendのAPI用にメールをフォーマットするために変換コードを編集します。
5

テストと作成

サンプルペイロードでテストし、作成をクリックしてメール送信を有効にします。
6

完了!

🎉 支払いイベントが自動的にResendを通じてトランザクションメールをトリガーします。

変換コードの例

支払い確認メール

payment_confirmation.js
function handler(webhook) {
  if (webhook.eventType === "payment.succeeded") {
    const p = webhook.payload.data;
    webhook.url = "https://api.resend.com/emails";
    webhook.payload = {
      from: "[email protected]",
      to: [p.customer.email],
      subject: "Payment Confirmation - $" + (p.total_amount / 100).toFixed(2),
      html: `
        <h2>Payment Successful!</h2>
        <p>Hi ${p.customer.name},</p>
        <p>Your payment of $${(p.total_amount / 100).toFixed(2)} has been processed successfully.</p>
        <ul>
          <li><strong>Payment ID:</strong> ${p.payment_id}</li>
          <li><strong>Amount:</strong> $${(p.total_amount / 100).toFixed(2)}</li>
          <li><strong>Date:</strong> ${new Date(webhook.payload.timestamp).toLocaleDateString()}</li>
          <li><strong>Method:</strong> ${p.payment_method || "Unknown"}</li>
        </ul>
        <p>Thank you for your business!</p>
      `,
      text: `Payment Successful! Your payment of $${(p.total_amount / 100).toFixed(2)} has been processed. Payment ID: ${p.payment_id}`
    };
  }
  return webhook;
}

サブスクリプションウェルカムメール

subscription_welcome.js
function handler(webhook) {
  if (webhook.eventType === "subscription.active") {
    const s = webhook.payload.data;
    webhook.url = "https://api.resend.com/emails";
    webhook.payload = {
      from: "[email protected]",
      to: [s.customer.email],
      subject: "Welcome to Your Subscription!",
      html: `
        <h2>Welcome to Your Subscription!</h2>
        <p>Hi ${s.customer.name},</p>
        <p>Your subscription has been activated successfully.</p>
        <ul>
          <li><strong>Subscription ID:</strong> ${s.subscription_id}</li>
          <li><strong>Product:</strong> ${s.product_id}</li>
          <li><strong>Amount:</strong> $${(s.recurring_pre_tax_amount / 100).toFixed(2)}/${s.payment_frequency_interval}</li>
          <li><strong>Next Billing:</strong> ${new Date(s.next_billing_date).toLocaleDateString()}</li>
        </ul>
        <p>You can manage your subscription anytime from your account dashboard.</p>
      `,
      text: `Welcome! Your subscription is now active. Amount: $${(s.recurring_pre_tax_amount / 100).toFixed(2)}/${s.payment_frequency_interval}`
    };
  }
  return webhook;
}

支払い失敗通知

payment_failure.js
function handler(webhook) {
  if (webhook.eventType === "payment.failed") {
    const p = webhook.payload.data;
    webhook.url = "https://api.resend.com/emails";
    webhook.payload = {
      from: "[email protected]",
      to: [p.customer.email],
      subject: "Payment Failed - Action Required",
      html: `
        <h2>Payment Failed</h2>
        <p>Hi ${p.customer.name},</p>
        <p>We were unable to process your payment of $${(p.total_amount / 100).toFixed(2)}.</p>
        <ul>
          <li><strong>Payment ID:</strong> ${p.payment_id}</li>
          <li><strong>Amount:</strong> $${(p.total_amount / 100).toFixed(2)}</li>
          <li><strong>Error:</strong> ${p.error_message || "Payment processing failed"}</li>
        </ul>
        <p>Please update your payment method or contact support for assistance.</p>
        <a href="https://yourdomain.com/update-payment">Update Payment Method</a>
      `,
      text: `Payment Failed: We couldn't process your $${(p.total_amount / 100).toFixed(2)} payment. Please update your payment method.`
    };
  }
  return webhook;
}

ヒント

  • より良い配信率のために確認済みの送信者ドメインを使用する
  • メールのHTML版とテキスト版の両方を含める
  • 顧客データでコンテンツをパーソナライズする
  • 明確で行動を促す件名を使用する
  • コンプライアンスのために解除リンクを含める
  • 本番環境に移行する前にメールテンプレートをテストする

トラブルシューティング

  • APIキーが正しくアクティブであることを確認する
  • 送信者ドメインがResendで確認されていることを確認する
  • 受信者のメールアドレスが有効であることを確認する
  • Resendの送信制限とクォータを確認する
  • JSON構造がResend APIフォーマットに一致していることを検証する
  • すべての必須フィールドが存在することを確認する
  • HTMLコンテンツが正しくフォーマットされていることを確認する
  • 送信元のメールアドレスが確認されていることを検証する